bintoascii

Reverendj1

New Member
bcdtoascii

Does anyone have some code that would do a reverse asciitobcd, i.e. a bcdtoascii? I need to send some data back to a clock to set it, but it is in two digit decimal format.
 
Last edited:

BeanieBots

Moderator
The PICAXE supports bintoascii and bcdtoascii so I assume you want to convert ASCII characters to BCD ready to put into a DS1307 type real time clock chip.
I'm also assuming that these characters really are ASCII and come from something like a terminal emulator. If I've got it wrong, then sorry but here's how to do it anyway.
Let's say you want to convert "2" & "3" in to the BCD value 23.
b0="2"
b1="3"
'first convert to decimal
b0=b0-"0" 'b0 now holds the number 2 rather than the character "2"
b1=b1-"0" 'same for the "3".
'make the 2 the high nibble
b2=b0*16
b2=b2+b1 'add the 3

b2 now hold "23" in BCD format ready to be sent to the clock.
 
Top