dim temp1 as byte
dim ascbfr0 as byte
dim ascbfr1 as byte
dim units as byte
dim tens as byte
'*******
'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 binary byte
bcd2bin:
units = temp1 And 0x0f
tens = temp1 And 0xf0
tens = ShiftRight(tens, 4)
tens = tens * 10
temp1 = tens + units
Return
'*******
'convert the bin number to packed bcd for RTC write
'enter with temp1 holding the binary byte
'exit with temp1 holding the packed BCD byte
'also ascbfr1,ascbfr0 hold the ASCII value
bin2bcd:
tens = temp1 / 10
units = temp1 Mod 10
ascbfr1 = tens Or 0x30
ascbfr0 = units Or 0x30
tens = ShiftLeft(tens, 4)
temp1 = tens Or units
Return
'*******
'convert packed bcd i/o to ascii for lcd
'enter with the packed BCD byte in temp1
'on exit ascbfr1 and ascbfr0 hold the ASCII numbers
bcd2asc:
ASM: movf temp1,w
ASM: andlw 0x0f
ASM: iorlw 0x30
ASM: movwf ascbfr0
ASM: movf temp1,w
ASM: swapf temp1,w
ASM: andlw 0x0f
ASM: iorlw 0x30
ASM: movwf ascbfr1
Return