CRC-16/MODBUS x16+x15+x2+1校验计算
#include <stdio.h>
int main(void)
{
unsigned short tmp = 0xffff;
unsigned short ret1 = 0;
unsigned char buff[8] = {0};
buff[0] = 0xa5;
buff[1] = 0x5a;
buff[2] = 0x02;
buff[3] = 0x03;
buff[4] = 0x84;
buff[5] = 0x00;
buff[6] = 0x01;
buff[7] = 0x00;
for(int n = 0; n < 8; n++)
{
tmp = buff[n] ^ tmp;
for(int i = 0;i < 8;i++)
{
if(tmp & 0x01){
tmp = tmp >> 1;
tmp = tmp ^ 0xa001;
}
else
{
tmp = tmp >> 1;
}
}
}
/*CRC校验后的值*/
printf("%X\n",tmp);
return 0;
}