might come in handy, to solve communication problems, with such devices.
#Define setBCD(v) converts from: base 16 to: base 10 (v = Decimal/Hex)
#Define getBCD(v) converts from: base 10 to: base 16 (v = BCD)
BCD_Mac.bas (including some test code):
Code: Select all
' toBCD_Mac.bas -- (c) 2020-07-03, MrSwiss
'
' compile: -s console
'
#Define setBCD(v) ( CUByte((v) \ 10 Shl 4 + (v) Mod 10) ) ' base 16 to base 10
#Define getBCD(v) ( CUByte(((v) Shr 4) * 10 + ((v) And 15)) ) ' base 10 to base 16
Dim As Ubyte buffer(0 To 6) ' size as required (by device)
Print "DEC"; Tab(9); "BCD-format"; Tab(25); "BIN/HEX"
Print
For i As UInteger = 0 To 99 ' min/max BCD range
buffer(0) = setBCD(i) ' set to BCD format (Base 10)
buffer(1) = getBCD(buffer(0)) ' reset to BIN/HEX (Base 16)
Print i; Tab(9); Bin(buffer(0), 8); _
Tab(25); Bin(buffer(1), 8) ' show them both
Next
Print : Print : Print "... done ... ";
Sleep