I try to do a real time clock with PCF8563, the clock works fine but a strange thing produit.a every 20 seconds the LCD add me numbers, like this:
LCD
time: 6:30:00
Date: 01/01/2014 (no problem)
LCD
time: 6:30:20
Date: 01/21/2014 (oups. ..!).
LCD
time: 6:30:40 -> time: 46:30:41 (oups ...)
Date: 41/41/2014 (oups ..)
strange and I can not find the problem
my code or the clock
Please try in your code for conversion from bcd to dec the code like written below:
'convert RTC packed bcd to a bin number for inc/dec usage
'enter with temp1 holding the packed BCD byte
'exit with temp1 holding the decimal byte
bcd2dec:
units = temp1 Mod 16
tens = (temp1 / 16) * 10
temp1 = tens + units
Return
When this is working you have to modify the bin2bcd code too.
'convert the bin number to packed bcd for RTC write
'enter with temp1 holding the decimal byte
'exit with temp1 holding the packed BCD byte
dec2bcd:
tens = (temp1 / 10) * 16
units = temp1 Mod 10
temp1 = tens + units
Return
Note 1: maybe it's needed to mask the 7th bit, because it is unused or reserved for other functionality.
Note 2: Remember that the high nibble is used for the tens and the low nibble is used for the units.