Forgive me if this has been done before - I am new to the PICAXE.
I wanted to display values in HEX and did not find a solution so I wrote this code to convert and display using sertxd.
If anyone has an alternative, please share.
Thanks
I wanted to display values in HEX and did not find a solution so I wrote this code to convert and display using sertxd.
If anyone has an alternative, please share.
Thanks
Code:
#picaxe 20m2
#no_data
#com 4
#terminal 4800
Symbol bval =b2
Symbol wval =w13
Symbol wremain =w11
Symbol divisor =w12
Symbol subx =b3
Symbol idx =b4
Symbol aval =b5
main:
sertxd ("Enter number", cr, lf)
serrxd #wval
if wval < 256 then
bval = wval
sertxd ("Byte Value: ",#bval, cr,lf)
gosub HexByte
else
sertxd ("Word Value: ",#wval, cr,lf)
gosub HexWord
end if
sertxd(cr,lf)
if wval > 0 then
goto main
end if
reconnect
sertxd ("end pgm", cr, lf)
end
HexWord:
sertxd("$")
wremain=wval
divisor=4096
for subx = 0 to 2
idx=wremain/divisor
gosub PrtHex
wremain=wremain//divisor
divisor=divisor/16
next
idx=wremain
gosub PrtHex
return
HexByte:
sertxd("$")
idx = bval/16
gosub PrtHex
idx = bval//16
gosub PrtHex
return
PrtHex:
lookup idx,("0123456789ABCDEF"),aval
sertxd(aval)
return