with a preset, fixed value. If the LSB was a 0, no exclusive OR takes place. This
process is repeated until eight shifts have been performed. After the last (eighth)
shift, the next eight-bit byte is exclusive O Red with the register's current value, and
the process repeats for eight more shifts as described above. The final contents of the
register, after all the bytes of the message have been applied, is the CRC value.
When the CRC is appended to the message, the low-order byte is appended first,
followed by the high-order byte.
Unsigned int Crc_Cal_Value (Unsigned int *data, Unsigned int length)
{
Unsigned int crcValue = 0xffff;
int i;
while (length--)
{
crcValue ^= *data++;
for (i = 8 – 1; i >= 0; i--)
{
if (crcValue & 0x0001)
{
crcValue = (crcValue >> 1) ^ 0Xa001;
}
else
{
crcValue = crcValue >> 1;
}
}
}
return (crcValue);
}