Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

RTC with 7-Segments to display seconds in 2 seven segments

Status
Not open for further replies.

saramah

Member level 3
Joined
Apr 25, 2018
Messages
64
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
689
I am trying to disp time ( only seconds) after extraxting from rtc-ds3231, code and header attached written in xc8 for 16f877a and also proteus ckt attached.

With the all header files(as attaced), this was working well in 16/2 lcd,
but problems is - not able to display in 7-segments.>> not getting any output at mcu pins for control and data pin for segments.>>why behaving like this??

Is my .c is in line to disp at segmnets or problems in conversion of BCD-DECimal and viceversa..

proteus.png

pl suggest what is the issues.....
tnx
 

Attachments

  • main.c.txt
    2.3 KB · Views: 79
  • PIC16977a_I2C.h.txt
    1.2 KB · Views: 75
  • PIC16F877a_DS3231.h.txt
    1.4 KB · Views: 80

Do you see all pins of PIC have gray boxes or do some have red or blue boxes next to pins? If all have gray boxes then PIC is excluded from Simulation.

To fix it, double click PIC model and uncheck "Exclude from Simulation" checkbox.

I2C pull-ups need to be Digital resistors type.

The code looks okay.
 

I only gave it a quick look but you should have "#include <xc.h>< xc.h >" (without the spaces) at the beginning of your program before you assign pins and values.

You are also returning 'pattern' as an unsigned int then sending it to an 8-bit port. It would be better to make SEGMENT_MAP an unsigned char and follow it with "return SEGMENT_MAP[digit];" to save a variable and use the correct data types.

Brian.</xc.h>
 

@baileychic::
All Data pins are blue and control pins one blue and other red boxes while simulation. A simulation snap is attched. And digital resitor also attached but no improvement found here also.

@betwixt:: yah sorry for not "#include < xc.h >" (without the spaces) at the beginning.
HTML:
You are also returning 'pattern' as an unsigned int then sending it to an 8-bit port. It would be better to make SEGMENT_MAP an unsigned char and follow it with "return SEGMENT_MAP[digit];" to save a variable and use the correct data types.
its corrected as advice but there also not any improvement. the updated (.C) file is also attahed.

Is there any coding problems??

- - - Updated - - -

sorry please consider this proteus-simulation snap. earlier was not simulated snap. so consider this one.proteus-smulate.png
 

Attachments

  • proteus1.png
    proteus1.png
    57.4 KB · Views: 158
  • main1.c.txt
    2.4 KB · Views: 74

The "xc.h" has to be right at the top of the program. It tells the compiler to use the selected microcontroller (in project settings) and associates all it's register names with their addresses. At the moment, all the #pragma statements refer to settings that are undefined because they are used before the compiler knows what type of PIC is being used.

I would use different variable types for some other storage but I think it should work with the present code. As there are references in each .c file to functions in other .c files, I assume there are also .h files with 'extern' declarations in them so the linker can recognize them as the same variable.

Brian.
 

When i had tested with the same .h files with 16x2 lcd code, the system working correctly.
but why after adding 7-seg code in liew of lcd code in only .c file, this not working...
if the matter is of "xc.h" and "extern" then it also should not work in lcd too.
i think you once cleary look into the problems for not being working in 7-seg...
with the snap of proteus as attached last session, rtc working, whether content of 'sec' to rtc and extract of data from rtc are working here or not confirm, is the conversion from bcd to dec and dec to bcd is correct.
 

Zip and attach the complete MPLAB X XC8 and Proteus project files for testing or analysis.
 

Here is the complete file in zip>xc v2.00/mplabv5.00

tnx
 

Attachments

  • 7seg_rtc.zip
    172.2 KB · Views: 111

Normal practice is to place shared definitions and declarations in header files and to place the working code in '.c' files. You have much of the code inside the headers, hence the confusion over 'extern' I mentioned in post #5.

To comply with normal coding, rename the existing .h files as .c then include them in the project as source files.

Personally, I would change SEGMENT_MAP to a 'const unsigned char' and place it outside any function and near the beginning of the program. That eliminates the whole 'Display()' function and also saves memory by placing the segment map in ROM instead of RAM.

Brian.
 

HTML:
To comply with normal coding, rename the existing .h files as .c then include them in the project as source files.

Personally, I would change SEGMENT_MAP to a 'const unsigned char' and place it outside any function and near the beginning of the program. That eliminates the whole 'Display()' function and also saves memory by placing the segment map in ROM instead of RAM.

I have done but no improvement found in proteus as posted earlier.

pl suggest what is gets wrong for not working the 7-seg.
tnx
 

Attachments

  • clkcd7s11.zip
    1.8 KB · Views: 107

I checked your code and code execution is stucking at

Code:
Set_Time_Date(); //set time and date on the RTC module

Your 7 Segment Display code is good and working. I tested it.

I can provide you a libstock.com DS3231 library link here but it is written in mikroC but you can use that code for your DS3231 part. It will work.
Mods will not allow me to post mikroC code for your XC8 related issue.

If you are interested in the link then request it here and I will post it.
 

YAP..
Why it is stucking.Will you let the cause to known me once.
I request to Please send the link/code.
tnx
 

where is the defination of functionS placed under "DS3231.c"
like,
Code:
I2C1_start();
I2C1_Wr();
I2C1_Rd();
I2C1_Stop();
I2C1_start()
I2C1_Init();

There are 3 files,
(1) DS3231.H >>PROTOTYPING..
(2) DS3231.C>> FUNC DEFINATION..
(3) DS3231 RTC.C >> SOURCE FILE..
 

Those ar emikroC I2Cx functions from mikroC compiled library. You cannot see its source code.

You have to use mikroC example DS3231 project's DS3231 related files and replace the mikroC I2Cx functions with youe equivalent XC8 I2C functions.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top