Example of CRC calculation in "C" language
This subroutine used to do CRC calculation
#define POLY 0xA001;
unsigned int crc_calculation (unsigned char *start_string, unsigned char number_byte)
{
unsigned int crc;
unsigned char bit_counter;
unsigned char *data_pointer;
data_pointer= start_string;
crc = 0xffff;
while (number_byte>0)
{
crc ^= data_pointer
bit_counter=0;
while (bit_counter < 8)
{
bit_counter++;
}
number_byte--;
}
return (crc);
}
// Initialize crc
// crc XOR with data
// reset counter
if (crc & 0x0001)
{
crc >>= 1;
crc ^= POLY;
}
else
{
crc >>=1;
}
// shift to the right 1 position
// crc XOR with POLY
// shift to the right 1 position
// increase counter
// adjust byte counter
// final result of crc
53