Real Time Clock problem

Thread Starter

Santosh_16k

Joined Aug 19, 2011
19
Here is my circuit diagram: http://www.flickr.com/photos/73123684@N08/6592133625/in/photostream
And here is my code for a simple clock
Rich (BB code):
ACALL DELAY
;----TURNING ON THE RTC
MOV R0,#10
MOV A,#20H
MOVX @R0,A
;----SETTING THE TIME MODE
MOV R0,#11
MOV A,#83H
MOVX @R0,A
;----SETTING THE TIME
MOV R0,#0
MOV A,#55H
MOV @R0,A
MOV R0,#02
MOV A,#58H
MOV @R0,A
MOV R0,#04
MOV A,#16H
MOV @R0,A
MOV R0,#11
MOV A,#03H
MOV @R0,A
DELAY:
	MOV R3,#50
HERE2:	MOV R4,#255
HERE:	DJNZ R4,HERE
	DJNZ R3,HERE2
	RET
END
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
 

SgtWookie

Joined Jul 17, 2007
22,210
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.
 

SgtWookie

Joined Jul 17, 2007
22,210
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:

Thread Starter

Santosh_16k

Joined Aug 19, 2011
19
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:
Rich (BB code):
ORG 0000H

;LCD initialization
MOV A,#38H
ACALL CMDWRITE
ACALL DELAY1
MOV A,#0EH
ACALL CMDWRITE
ACALL DELAY1
MOV A,#01H
ACALL CMDWRITE
ACALL DELAY1

;RTC on
MOV R0,#10
MOV A,#20H
MOVX @R0,A

;Selecting Time Mode
MOV R0,#11
MOV A,#83H
MOVX @R0,A

MOV R0,#11
MOV A,#03
MOVX @R0,A

;Reading the time values from RTC
TIMEX:
MOV A,#80H
ACALL CMDWRITE
MOV R0,#04
MOVX A,@R0
ACALL DISPLAY
MOV A,#':'
MOV R0,#02
MOVX A,@R0
ACALL DISPLAY
MOV A,#':'
ACALL DATAWRITE
MOV R0,#00
MOVX A,@R0
ACALL DISPLAY
SJMP TIMEX
;Converting BCD to ASCII and sending it to screen
DISPLAY:
MOV B,A
SWAP A
ANL A,#0FH
ORL A,#30H
ACALL DATAWRITE
ACALL DELAY1
MOV A,B
ANL A,#0FH
ORL A,#30H
ACALL DATAWRITE
ACALL DELAY1
RET
;Writing command to LCD
CMDWRITE:
MOV P1,A
CLR P2.0
CLR P2.1
SETB P2.2
ACALL DELAY1
CLR P2.2
RET
;Writing data to LCD
DATAWRITE:
MOV P1,A
SETB P2.0
CLR P2.1
SETB P2.2
ACALL DELAY1
CLR P2.2
RET


DELAY1:
HERE2: MOV R3,#99
HERE:  DJNZ R3,HERE
       DJNZ R4,HERE2
RET
END
And here is the modified circuit:http://www.flickr.com/photos/73123684@N08/6600458735/in/photostream/lightbox/
 
Last edited:

SgtWookie

Joined Jul 17, 2007
22,210
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:
Top