7 Appendix
7.1 8-Bit CRC Software C Algorithm
// 8 bits crc calculation. Initial crc entry value must be 0.
// polynomial = X8 + X5 + X4 + 1
// data is an 8 bit number; crc is an unsigned 8 bit number
// repeat this function for each data block byte, folding the result
//
back into the call parameter crc
unsigned char eight_bit_crc(unsigned char crc, unsigned char data)
{
unsigned charindex; // shift counter
unsigned charfb;
// intermediate test bit
index = 8;
do
// initialize the shift counter
// loop 8 times
{
fb = (crc ^ data) & 0x01;
data >>= 1;
crc >>= 1;
if(fb)
{
}
crc ^= 0x8c;
} while(--index);
return crc;
}
7.2 16-Bit CRC Software C Algorithm
// 16 bits crc calculation. Initial crc entry value must be 0.
// The message is not augmented with 'zero' bits.
// polynomial = X16 + X12 + X5 + 1
// data is an 8 bit number, unsigned
// crc is a 16 bit number, unsigned
// repeat this function for each data block byte, folding the result
//
back into the call parameter crc
unsigned long sixteen_bit_crc(unsigned long crc, unsigned char data)
{
unsigned char index; // shift counter
crc ^= (unsigned long)(data) << 8;
index = 8;
do
{
// loop 8 times
if(crc & 0x8000)
{
}
else
crc= (crc << 1) ^ 0x1021;
{
}
crc= crc << 1;
} while(--index);
return crc;
}
A CRC calculator for Windows is available free of charge from Quantum Research.
lQ
29
QT60486-AS R8.01/0105