and compares the calculated value to the actual value it received in the CRC eld. If the two
values are not equal, an error results.
The CRC is started by 0xFFFF.Then a process begins of applying successive eight-bit bytes of
the message to the current contents of the register. Only the eight bits of data in each character
are used for generating the CRC. Start and stop bits, and the parity bit, do not apply to the
CRC.
During generation of the CRC, each eight-bit character is exclusive ORed with the register
contents. Then the result is shifted in the direction of the least signicant bit (LSB), with a zero
lled into the most signicant bit (MSB) position.The LSB is extracted and examined.If the LSB
was a 1, the register is then exclusive ORed with a preset, xed 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 ORed with the register's current value,
and the process repeats for eight more shifts as described above. The nal 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 rst, followed by
the high-order byte.
unsigned int crc_chk_value(unsigned char *data_value,unsigned char length
{
unsigned int crc_value=0xFFFF;
int i;
while(length--)
{
crc_value^=*data_value++;
for(i=0;i<8;i++)
{
if(crc_value&0x0001)
{
crc_value=(crc_value>>1)^0xa001;
}
else
{
crc_value=crc_value>>1;
}
}
}