Code:
Mainloop:
if PORTC.6 =0 then
GOSUB READ_RTC
I2CWRITE DPIN,CPIN,$A0,Write_Address,[sec,mins,hr]
PAUSE 10
Write_Address = Write_Address +3
Endif
if PORTC.7 =0 then
if Write_Address = 0 then goto Mainloop
j = 0
For i=0 to (Write_Address / 3) -1
I2CREAD DPIN,CPIN,$A0,j,[sec,mins,hr]
PAUSE 10
LCDOUT $FE,1," Time ",DEC2 i
LCDOUT $FE,$C0,"WA ",DEC j," T:", dec2 hr, ":", dec2 mins, ":", dec2 sec
PAUSE 1000
j =j + 3
next i
Endif
GOTO Mainloop
End
READ_RTC:
I2CREAD DPIN, CPIN, $D0, SecReg, [sec,mins,hr,day,date,mon,yr]
pause 10
TempVal=hr
GoSub BCD_TO_BIN
hr=TempVal
TempVal=sec
GoSub BCD_TO_BIN
sec=TempVal
TempVal=mins
GoSub BCD_TO_BIN
mins=TempVal
RETURN
SET_RTC: ' Do once at startup
yr = $3
mon = $5
date = $05
sec = $09
mins = $04
hr = $02
I2CWRITE DPIN, CPIN, $D0, SecReg, [sec,mins,hr,day,date,mon,yr]
RETURN
BCD_TO_BIN: ' Convert the BCD values into BIN
Temp1 = $0F & TempVal ' Clear off the top four bits
Temp1 = Temp1 Dig 0
Temp2 = TempVal >> 4 ' Shift down four to read 2 BCD value
Temp2 = Temp2 Dig 0
TempVal = Temp2 * 10 + Temp1
Return
Bookmarks