Hello,
I am trying to convert from 12h mode to 25H mode and vice versa with a Ds1337 chip. Not getting great results for now.
What I understand Bit 5 and 6 or the hours plays a role in converting. Her is a clip from the datasheet:
The DS1337 can be run in either 12-hour or 24-hour mode. Bit 6 of the hours register is defined as the 12- or 24-
hour mode-select bit. When high, the 12-hour mode is selected. In the 12-hour mode, bit 5 is the AM/PM bit with
logic high being PM. In the 24-hour mode, bit 5 is the second 10-hour bit (20–23 hours).
I am configuring it so that when two buttons are pressed down for over 1.5 seconds, the conversion between 12h mode to 24h mode is done. From what I understan, I also need to convert the time myself example: from 20H to 8H. The code for me should work but keeps giving me random values, any ideas ?
thanks
Code:
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
gosub bcd_to_bin
RTCHour = TempVal + 12
RTCHour.6 = 0
endif
if RTCHour.6 = 0 then 'turn into 12h mode therefore 13 to 23 converts to 1 to 11
point =3
gosub bcd_to_bin
RTCHour = TempVal - 12
RTCHour.6 = 1
endif
I2cwrite SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour]
Pause 100
endif
Bookmarks