Real Time Clock problem

Discussion in 'The Projects Forum' started by Santosh_16k, Dec 28, 2011.

  1. Santosh_16k

    Thread Starter New Member

    Aug 19, 2011
    19
    0
    Here is my circuit diagram: http://www.flickr.com/photos/73123684@N08/6592133625/in/photostream
    And here is my code for a simple clock
    Code ( (Unknown Language)):
    1.  
    2. ACALL DELAY
    3. ;----TURNING ON THE RTC
    4. MOV R0,#10
    5. MOV A,#20H
    6. MOVX @R0,A
    7. ;----SETTING THE TIME MODE
    8. MOV R0,#11
    9. MOV A,#83H
    10. MOVX @R0,A
    11. ;----SETTING THE TIME
    12. MOV R0,#0
    13. MOV A,#55H
    14. MOV @R0,A
    15. MOV R0,#02
    16. MOV A,#58H
    17. MOV @R0,A
    18. MOV R0,#04
    19. MOV A,#16H
    20. MOV @R0,A
    21. MOV R0,#11
    22. MOV A,#03H
    23. MOV @R0,A
    24. DELAY:
    25.     MOV R3,#50
    26. HERE2:  MOV R4,#255
    27. HERE:   DJNZ R4,HERE
    28.     DJNZ R3,HERE2
    29.     RET
    30. END
    31.  
    This code sets the time in RTC but when I simulated the circuit in Proteus, RTC was unable to set time as 16:58:55...
    I cann't find out what is the error...Plz help
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I don't see you checking to see if the RTC is ready for data, or ready for more data.

    You're probably stuffing so much data down the RTC's throat so quickly that it doesn't know what to do.
     
  3. Santosh_16k

    Thread Starter New Member

    Aug 19, 2011
    19
    0
    What do u recommend then?
    Should I add more delay's between commands of RTC?
     
  4. Santosh_16k

    Thread Starter New Member

    Aug 19, 2011
    19
    0
    Please help me! :(
     
  5. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Did you look at the timing specifications?
    http://pdfserv.maxim-ic.com/en/ds/DS12885-DS12C887A.pdf
    See pages 4 and 5.

    If you are not following those specifications, the device won't know what you are trying to tell it.

    Also, in your code - you ACALL DELAY at the beginning, and then you execute the rest of the code - however, there is nothing to stop the uC from falling back into that subroutine. It will go through the delay loop again, and then crash into that RET statement. What happens after that is anyone's guess - I'm not certain what will happen. It may return to the beginning and start the program all over again - but that's a poor way of doing it.
     
    Last edited: Dec 29, 2011
  6. Santosh_16k

    Thread Starter New Member

    Aug 19, 2011
    19
    0
    I tried reading the specification...but still I was unable to find what am I supposed to do in that...
    I removed the initial delays...(I had added them to give some time to the RTC after start up!)...
    I interfaced and LCD to check the output but the problem I got was that seconds are getting over written on the hours and minutes part...
    Then, I tried doing it displaying the minutes part separately but again minutes were getting over written by seconds, even though I wasn't calling it...
    Here's the modified code:
    Code ( (Unknown Language)):
    1.  
    2. ORG 0000H
    3.  
    4. ;LCD initialization
    5. MOV A,#38H
    6. ACALL CMDWRITE
    7. ACALL DELAY1
    8. MOV A,#0EH
    9. ACALL CMDWRITE
    10. ACALL DELAY1
    11. MOV A,#01H
    12. ACALL CMDWRITE
    13. ACALL DELAY1
    14.  
    15. ;RTC on
    16. MOV R0,#10
    17. MOV A,#20H
    18. MOVX @R0,A
    19.  
    20. ;Selecting Time Mode
    21. MOV R0,#11
    22. MOV A,#83H
    23. MOVX @R0,A
    24.  
    25. MOV R0,#11
    26. MOV A,#03
    27. MOVX @R0,A
    28.  
    29. ;Reading the time values from RTC
    30. TIMEX:
    31. MOV A,#80H
    32. ACALL CMDWRITE
    33. MOV R0,#04
    34. MOVX A,@R0
    35. ACALL DISPLAY
    36. MOV A,#':'
    37. MOV R0,#02
    38. MOVX A,@R0
    39. ACALL DISPLAY
    40. MOV A,#':'
    41. ACALL DATAWRITE
    42. MOV R0,#00
    43. MOVX A,@R0
    44. ACALL DISPLAY
    45. SJMP TIMEX
    46. ;Converting BCD to ASCII and sending it to screen
    47. DISPLAY:
    48. MOV B,A
    49. SWAP A
    50. ANL A,#0FH
    51. ORL A,#30H
    52. ACALL DATAWRITE
    53. ACALL DELAY1
    54. MOV A,B
    55. ANL A,#0FH
    56. ORL A,#30H
    57. ACALL DATAWRITE
    58. ACALL DELAY1
    59. RET
    60. ;Writing command to LCD
    61. CMDWRITE:
    62. MOV P1,A
    63. CLR P2.0
    64. CLR P2.1
    65. SETB P2.2
    66. ACALL DELAY1
    67. CLR P2.2
    68. RET
    69. ;Writing data to LCD
    70. DATAWRITE:
    71. MOV P1,A
    72. SETB P2.0
    73. CLR P2.1
    74. SETB P2.2
    75. ACALL DELAY1
    76. CLR P2.2
    77. RET
    78.  
    79.  
    80. DELAY1:
    81. HERE2: MOV R3,#99
    82. HERE:  DJNZ R3,HERE
    83.        DJNZ R4,HERE2
    84. RET
    85. END
    86.  
    And here is the modified circuit:http://www.flickr.com/photos/73123684@N08/6600458735/in/photostream/lightbox/
     
    Last edited: Dec 30, 2011
  7. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I'm reading in the datasheet for the 12887 that you need to wait for 200mS after applying power before attempting to read from or write to the IC. 200mS is a pretty long time. I don't know what crystal you are using.

    I'm not sure what you're doing with the time set code. You need to be writing the address and data to port P0, and reading back from it. You don't seem to be doing that.

    Before writing to the 12887 internal time, calendar, alarm registers, the SET bit in register B (address 0BH) needs to be set to a logic 1. You need to clear this bit after the data mode bit has been written.

    The data mode bit (binary or BCD), DM of register B must be set to the appropriate logic level; 1 for binary; 0=BCD.

    The 24-12 bit needs to be set to logic 0 (24 hour) before initializing the hours.

    Write data to the IC:
    Lower R/W.
    Raise AS.
    Place the address on the bus.
    Lower AS to latch the address.

    Raise DS
    Place the data on the bus.
    Lower DS to latch the data.

    Read data from the IC:
    Raise R/W.
    Raise AS
    Place the address on the bus.
    Lower AS to latch the address

    Raise DS
    Read data from bus.

    Addresses (from table 2B)
    Seconds are at address 00H.
    Minutes are at address 02H.
    Hours are at address 004h.
     
    Last edited: Dec 30, 2011
    Santosh_16k likes this.
Loading...