Code:
'////////////////////////////////////////////////////
'////////////////// PROGRAM /////////////////////////
'////////////////////////////////////////////////////
I2CWRITE SDApin,SCLpin,$D0,$00,[$56,$59,$20,$00,$00,$00,$00,$00] ' Write to DS1337 to initialize RTC
pause 10
I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour] ' bit 5 of hour is 1 for PM , 0 for AM
pause 10
'RTCHour.5 = 1 'bit 5 is the AM/PM bit with logic high being PM AND NOT USED
' RTCHour.6 = 0 '24h selected ' for 12 or 24 h mode , when high 12h mode is selected
'in 24 hour mode (=0) bit 5 is used for hours 20 to 23
I2CwRITE SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour]
pause 10
Mainloop:
I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour]
gosub bcd_to_bin
If (PortC.5 = 1) & (PortC.6 = 1) then Pause 1500
If (PortC.5 = 1) & (PortC.6 = 1) then
'IF hourly mode = AM
I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour]
Pause 10
if RTCHour.6 = 1 then 'turn into 24h mode therefore 1 to 11 converts to 13 to 23
point =2
RTCHour.6 = 0
endif
if RTCHour.6 = 0 then 'turn into 12h mode therefore 13 to 23 converts to 1 to 11
point =3
RTCHour.6 = 1
endif
I2cwrite SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour]
Pause 100
endif
temp1_min = RTCMin_temp1
m = temp1_min
'PortA.0 =1
'gosub display
' PortA.0 =0
temp2_min = RTCMin_temp2
n = temp2_min
' PortA.1 =1
' gosub display
' PortA.1 =0
temp1_sec = RTCSec_temp1
o = temp1_sec
' PortA.2 =1
' gosub display
' PortA.2 =0
temp2_sec = RTCSec_temp2
p = temp2_sec
' PortA.4 =1
'gosub display
'PortA.4 =0
lcdout $FE,1, "Time: ", HEX2 RTCHour, ":", hex2 RTCmin ,":", HEX2 RTCsec 'in decimals... wow
lcdout $FE,$C0, dec TempVal , " :" ,dec RTCHour_temp1,":", dec RTCHour_temp2,":", dec point
Pause 150
goto Mainloop
end
bcd_to_bin:
if (RTCHour.6 = 1 ) then 'bit 5 is used if RTCHour.6 = 0 ; 24h selected
RTCHour.6 = 0
RTCHour.5 = 0
RTCHour_temp2 = $0F & RTCHour
RTCHour_temp1= RTCHour >> 4
endif
if (RTCHour.6 = 0 ) then
RTCHour_temp2 = %00001111 & RTCHour
RTCHour_temp1= RTCHour >> 4 ' Shift down four to read 2 BCD value
TempVal = RTCHour_temp1 * 10 + RTCHour_temp2 ' this calculate the hours in decima
if ( TempVal > 19 ) then
return
else
RTCHour.5 = 0
RTCHour_temp2 = $0F & RTCHour
RTCHour_temp1= RTCHour >> 4
endif
endif
RTCMin_temp2 = $0F & RTCMin ' Clear off the top four bits
RTCMin_temp1= RTCMin >> 4 ' Shift down four to read 2 BCD value
RTCSec_temp2 = $0F & RTCSec ' Clear off the top four bits
RTCSec_temp1= RTCSec >> 4 ' Shift down four to read 2 BCD value
return
Bookmarks