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; // Initialize crc
while (number_byte>0)
{
crc ^= data_pointer // crc XOR with data
bit_counter=0; // reset counter
while (bit_counter < 8)
{
if (crc & 0x0001)
{
crc >>= 1; // shift to the right 1 position
crc ^= POLY; // crc XOR with POLY
}
else
{
crc >>=1; // shift to the right 1 position
}
bit_counter++; // increase counter
}
number_byte--; // adjust byte counter
}
return (crc); // final result of crc
}
53