+ Post New Thread
Results 1 to 15 of 15
  1. #1
    Member level 2
    Points: 438, Level: 4

    Join Date
    Apr 2018
    Posts
    45
    Helped
    0 / 0
    Points
    438
    Level
    4

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

    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..

    Click image for larger version. 

Name:	proteus.png 
Views:	6 
Size:	63.1 KB 
ID:	153256

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

  2. #2
    Advanced Member level 2
    Points: 2,803, Level: 12
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    557
    Helped
    49 / 49
    Points
    2,803
    Level
    12

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

    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.



    •   AltAdvertisement

        
       

  3. #3
    Super Moderator
    Points: 79,216, Level: 68
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,976
    Helped
    4332 / 4332
    Points
    79,216
    Level
    68

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

    I only gave it a quick look but you should have "#include < 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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



  4. #4
    Member level 2
    Points: 438, Level: 4

    Join Date
    Apr 2018
    Posts
    45
    Helped
    0 / 0
    Points
    438
    Level
    4

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

    @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 Code:
    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.Click image for larger version. 

Name:	proteus-smulate.png 
Views:	4 
Size:	86.7 KB 
ID:	153262



    •   AltAdvertisement

        
       

  5. #5
    Super Moderator
    Points: 79,216, Level: 68
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,976
    Helped
    4332 / 4332
    Points
    79,216
    Level
    68

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

    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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



  6. #6
    Member level 2
    Points: 438, Level: 4

    Join Date
    Apr 2018
    Posts
    45
    Helped
    0 / 0
    Points
    438
    Level
    4

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

    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.



  7. #7
    Advanced Member level 2
    Points: 2,803, Level: 12
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    557
    Helped
    49 / 49
    Points
    2,803
    Level
    12

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

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



    •   AltAdvertisement

        
       

  8. #8
    Member level 2
    Points: 438, Level: 4

    Join Date
    Apr 2018
    Posts
    45
    Helped
    0 / 0
    Points
    438
    Level
    4

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

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

    tnx



  9. #9
    Super Moderator
    Points: 79,216, Level: 68
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,976
    Helped
    4332 / 4332
    Points
    79,216
    Level
    68

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

    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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



  10. #10
    Member level 2
    Points: 438, Level: 4

    Join Date
    Apr 2018
    Posts
    45
    Helped
    0 / 0
    Points
    438
    Level
    4

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

    HTML Code:
    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



  11. #11
    Advanced Member level 2
    Points: 2,803, Level: 12
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    557
    Helped
    49 / 49
    Points
    2,803
    Level
    12

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

    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.



  12. #12
    Member level 2
    Points: 438, Level: 4

    Join Date
    Apr 2018
    Posts
    45
    Helped
    0 / 0
    Points
    438
    Level
    4

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

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



  13. #13
    Advanced Member level 2
    Points: 2,803, Level: 12
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    557
    Helped
    49 / 49
    Points
    2,803
    Level
    12

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

    I didn't check why it is stucking.

    Here is the link for libstock.com's mikroC code. You can use the DS3231 driver in your code. Change the I2C function names to yours.

    https://libstock.mikroe.com/projects...emperature-i2c



    •   AltAdvertisement

        
       

  14. #14
    Member level 2
    Points: 438, Level: 4

    Join Date
    Apr 2018
    Posts
    45
    Helped
    0 / 0
    Points
    438
    Level
    4

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

    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..



  15. #15
    Advanced Member level 2
    Points: 2,803, Level: 12
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    557
    Helped
    49 / 49
    Points
    2,803
    Level
    12

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

    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.



--[[ ]]--