fastgrandad
New Member
I have a project that uses the 1307 chip to provide reasonably accurate time. I want to be able to alter the time setting from the main program and have a routine that reads the individual clock parameters, any of which, after being converted from BCD to decimal, can be incremented/decremented and then written back to the clock. However, to be written back they need to be converted back from decimal to BCD.
I've written a few lines of code that seem to do the trick but wondered whether there is a more elegant way of doing the conversion to BCD.
b2=b1/10 'isolate MSD
b3=b1//10 'isolate LSD
b4=b2*16+b3 'shift MSD bits left 4 places (X16), add to LSD = BCD
where b1 is the decimal number and b4 has been converted to BCD.
Paul
I've written a few lines of code that seem to do the trick but wondered whether there is a more elegant way of doing the conversion to BCD.
b2=b1/10 'isolate MSD
b3=b1//10 'isolate LSD
b4=b2*16+b3 'shift MSD bits left 4 places (X16), add to LSD = BCD
where b1 is the decimal number and b4 has been converted to BCD.
Paul