Real Time Clock

Discussion in 'General Electronics Chat' started by RG23, Jan 7, 2011.

  1. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    How to implement a RTC without using any timer in PIC 16F887 ?

    How to use DS1307 to achieve RTC for PIC? ​
     
  2. nigelwright7557

    Senior Member

    May 10, 2008
    487
    71
    Look up the datasheet.
     
  3. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    I want to implement RTC without using any timer in PIC 16F887.

    I just want to read the time from RTC and display it on LCD in Hours: MIn: Sec format.

    http://www.maxim-ic.com/app-notes/index.mvp/id/3921

    I tried the above link but it did not solve the problem.

    If anyone has an idea, please let me know.

    Thank you.
     
  4. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,346
    Hello,

    I merged the thread as the subject is still the same.

    Bertus
     
  5. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Did you get that data sheet? - http://www.maxim-ic.com/datasheet/index.mvp/id/2688

    The data sheet give the details about the RTC chip:
     
  6. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    i tried with that datasheet.


    But somehow could not display Hours, min , Sec on LCD display

    Please help me out.
     
  7. tom66

    Senior Member

    May 9, 2009
    2,613
    214
    What have you done so far? Have you got an LCD display? What type of LCD display, dot-matrix, or individual segments? Is it a fully graphical LCD or is it segmented? Does it have an integrated controller? What is the interface of the controller, if any?
     
  8. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    You have not as yet described your problem. However, I believe I can tell you why your DS1307 is not working. Assuming that you have implemented the SPI data read and write functions correctly in software then most likely you have not enabled the 32,768Hz oscillator. Until you set the CH bit in register 00 high, the 32,768Hz oscillator will not oscillate and you will not be able to read the time. The chip comes from the manufacturer with this bit set to 0. YOu will get nothing from teh RTC until you write a "1" to the CH bit. This suggestion comes from personal experience.

    hgmjr
     
  9. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    I just want to read the time from RTC and display it on LCD in Hours: MIn: Sec format.

    I tried the following code bt it did not work. Please help me out.

    Code ( (Unknown Language)):
    1.  
    2. RTC_rd:
    3. call I2C_STRT
    4. movlw 0XD0 ; slave address + write
    5. movwf I2C_Value
    6. call I2C_SEND
    7. movlw 0X00 ; set word address to seconds register
    8. movwf I2C_Value
    9. call I2C_SEND
    10. call I2C_STRT
    11. movlw 0XD1 ; slave address + read
    12. movwf I2C_Value
    13. call I2C_SEND
    14. call read_RTC ; read the seconds data
    15. movwf SECS ; save it
    16. call ack
    17.  
    18. movlw 0X01 ; set word address to seconds register
    19. movwf I2C_Value
    20. call I2C_SEND
    21. call I2C_STRT
    22. movlw 0XD1 ; slave address + read
    23. movwf I2C_Value
    24. call I2C_SEND
    25. call read_RTC ; read the seconds data
    26. movwf MINS
    27. call ack
    28.  
    29. movlw 0X02 ; set word address to seconds register
    30. movwf I2C_Value
    31. call I2C_SEND
    32. call I2C_STRT
    33. movlw 0XD1 ; slave address + read
    34. movwf I2C_Value
    35. call I2C_SEND
    36. call read_RTC ; read the seconds data
    37. movwf SECS
    38. call nack
    39. call I2C_STP
    40. return
    41.  
    42. read_RTC:
    43.  
    44. bsf I2C_DTA ; set SDA for input
    45. movlw 0x08 ; send 8 bits
    46. movwf COUNTER5
    47.  
    48. bcf I2C_CLOCK ; SCL low (output)
    49. clrf I2C_Value ; clear var
    50. ;rlf I2C_Value, 1 ; rotate carry in
    51. ;clrf I2C_Value ; clear var again
    52.  
    53. I2C_read_loop:
    54. rlf I2C_Value, 1
    55.  
    56. bsf I2C_CLOCK ; SCL high (input)
    57. btfsc PORTC,4
    58. bsf I2C_Value, 0 ; if data out = 1, set bit
    59.  
    60. ;bcf I2C_CLOCK
    61.  
    62. bcf I2C_CLOCK ; SCL low (output)
    63.  
    64. decfsz COUNTER5, 1
    65. goto I2C_read_loop
    66.  
    67. movf I2C_Value, 0
    68.  
    69. return
    70.  
    71.  
     
    Last edited by a moderator: Jan 12, 2011
  10. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Try writing the hex value 0x80 to the seconds register. The MSB in this data value is the CH bit that I was referring to. By writing a "1" to that bit location in the seconds register you enable the 32,768Hz oscillator.

    hgmjr
     
  11. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    I tried putting 1 there but it did not work
     
  12. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    Have you tested you LCD to check if it is operational?
    Is it broken?

    You should try to send a few characters to the LCD to see if it works first.
     
  13. tom66

    Senior Member

    May 9, 2009
    2,613
    214
    Do you have an oscilloscope or a logic analyser to test the circuit?
     
  14. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,346
    Hello,

    At the moment you only talked about the hardware and the pic program.
    A schematic how everything is connected would help a lot to get the overview.
    Can you make the schematic and post it?

    Bertus
     
  15. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    The LCD is working fine

    The clock frequency is the same as the crystal frequency

    By setting the CH bit in register 00 the oscillator should have been enabled but it doesn't
     
  16. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    i have posted the code for RTC earlier

    Are there any flaws in it?
     
  17. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Can you post a schematic? I am particularly interested in what you have done regarding the backup battery input.

    hgmjr
     
  18. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    i dont have the schematic

    But I just want to read the sec,min , hrs from RTC and display it on LCD

    I still haven't solved that problem

    I appreciate your help

    Thank you
     
  19. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    I had one more question

    Do I need to call the RTC subroutine in the main or in the ISR

    I have posted my code earlier

    Please have a look and let me know any flaws

    Thank you
     
  20. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Are you providing a backup battery connected to the RTC?

    hgmjr
     
Loading...