Hello,
I'm trying to use a bit of code which generates a CRC and it is working correctly provided I input the data in ASCII format, i.e. "A","B","C","1", "2" etc or use the number equivalents, i.e. decimal 1 = 49, 2 = 50 etc.
The main part of the program generates a data string in the scratchpad of type:
$$Daed,100,12:46:20,53.25,-3.25,XXX where XXX is the CRC value.
How do I get the CRC calculation to recognise the text and decimal values and treat them correctly please? I've searched the forums, but I think I've been staring at the problem so long, I'm just going round in circles.
Code:
SYMBOL crc = w0 ' b0/b1
SYMBOL k = w1 ' b2/b3
SYMBOL byte_ = b4
SYMBOL bit_ = b5
symbol word2 = w12
SYMBOL POLYNOMIAL = $1021
crc = $FFFF
put 1,49 'decimal 1 in ASCII
put 2,50
put 3,51
for b14 = 1 to 3
get b14,b15
byte_ = b15 : GOSUB Crc16Add2:
next
crc = crc ^ $0000
END
Crc16Add2:
word2 = byte_ << 8
crc = crc ^ word2
for byte_ = 0 to 7
word2 = crc & 0x8000
if word2 > 0 then
crc = crc << 1
crc = crc ^ 0x1021
else
crc = crc << 1
endif
next
return
I am comparing the result with http://www.lammertbies.nl/comm/info/crc-calculation.html for the 0xFFFF option.
Thanks for any help.
I'm trying to use a bit of code which generates a CRC and it is working correctly provided I input the data in ASCII format, i.e. "A","B","C","1", "2" etc or use the number equivalents, i.e. decimal 1 = 49, 2 = 50 etc.
The main part of the program generates a data string in the scratchpad of type:
$$Daed,100,12:46:20,53.25,-3.25,XXX where XXX is the CRC value.
How do I get the CRC calculation to recognise the text and decimal values and treat them correctly please? I've searched the forums, but I think I've been staring at the problem so long, I'm just going round in circles.
Code:
SYMBOL crc = w0 ' b0/b1
SYMBOL k = w1 ' b2/b3
SYMBOL byte_ = b4
SYMBOL bit_ = b5
symbol word2 = w12
SYMBOL POLYNOMIAL = $1021
crc = $FFFF
put 1,49 'decimal 1 in ASCII
put 2,50
put 3,51
for b14 = 1 to 3
get b14,b15
byte_ = b15 : GOSUB Crc16Add2:
next
crc = crc ^ $0000
END
Crc16Add2:
word2 = byte_ << 8
crc = crc ^ word2
for byte_ = 0 to 7
word2 = crc & 0x8000
if word2 > 0 then
crc = crc << 1
crc = crc ^ 0x1021
else
crc = crc << 1
endif
next
return
I am comparing the result with http://www.lammertbies.nl/comm/info/crc-calculation.html for the 0xFFFF option.
Thanks for any help.