User's Manual

December 6, 2006 Proprietary Information 69
Revision 1.0
// the command to be checked.
unsigned char placeholder; // A place to put the byte while we
// work on it.
for (byteindex = 1; byteindex <= (arraylength - 3); byteindex++) // begin checking after SOH and
// before CRC bytes
{
placeholder = bytearray[byteindex];
for(bitindex = 0; bitindex <= 7; bitindex++)
{
tempresults = (crc >> 15) ^ (placeholder >> 7); // Shift CRC right 15 bits then do a
// bitwise XOR
crc <<= 1; // Shift CRC left one bit and store it
// in CRC
if(tempresults)
{
crc ^= 0x1021;
// Standard CCITT Polynomial
// X16+X12+X5+1
}
placeholder <<= 1;
}
}
return crc; // Returns the CRC calculated in
// the variable crc
}