Give this a whirl.
Code:rtcAMPM var bit ' Storage flag to indicate AM or PM ; 0=AM, 1=PM hourmode var bit ' Storage flag for RTC 12/24 hour mode ; 0=24Hr, 1=12Hr BCDResult var byte ' Storage for temporary result for BCD Conversions If(PortC.5 = 1) & (PortC.6 = 1) then Pause 1500 If (PortC.5 = 1) & (PortC.6 = 1) then I2CRead SDApin,SCLpin,$D0,$02,[RTCHour] hourmode = RTCHour.6 if hourmode = 1 then ' Is the RTC set for 12-hour mode rtcAMPM = RTCHour.5 ' Assign AM/PM RTCHour = RTCHour & %00011111 ' Bits 4-0 = Hours 0-12 endif BCDResult = RTCHour gosub Bcd2Dec if hourmode = 1 then '12Hr if rtcAMPM = 1 then 'PM BCDResult = BCDResult + 12 'PM endif else if BCDResult > 12 then BCDResult = BCDResult - 12 rtcAMPM = 1 else rtcAMPM = 0 endif endif gosub Dec2Bcd RTCHour = BCDResult hourmode = ! hourmode I2cwrite SDApin,SCLpin,$D0,$02,[RTCHour] pause 10 I2cwrite SDApin,SCLpin,$D0,$02,[RTCHour] ' Need to write twice because you changed the mode bit Bcd2Dec: ' Subroutine to convert BCD (2 hex digits) to Decimal ' Make sure to set BCDResult with parameter value before calling this sub ' Result is stored in BCDResult BCDResult = (((BCDResult >> 4) * 10) + (BCDResult & $0f)) return Dec2Bcd: ' Subroutine to convert Decimal to BCD (2 hex digits) ' Make sure to set BCDResult with parameter value before calling this sub ' Result is stored in BCDResult BCDResult = (((BCDResult / 10) << 4) | (BCDResult // 10)) return




Bookmarks