static u8 crccheck(u8* p,u8 len) //CRC校验,返回CRC检验值
{
    u8 bit0,cbit,i,j,byte,temp;
    temp = 0;
    for (j = 0; j < len; j++) {
        byte = p[j];
        for(i = 0; i < 8; i++) {
            cbit = temp & 0x01;
            bit0 = byte & 0x01;
            temp = temp >> 1;
            if ((cbit^bit0)) temp ^= 0x8c;
            byte >>= 1;
        }
    }
    return temp;
}

该函数为CRC8校验,多项式(即除数)为g(x)=x8+x5+x4+1,对应的二进制数为100110001。返回的是CRC校验值(即余数)。

CRC校验中有两个关键点:一是要预先确定一个发送端和接收端都用来作为除数的二进制比特串(或多项式);二是把原始帧与上面选定的除进行二进制除法运算,计算出FCS。前者可以随机选择,也可按国际上通行的标准选择,但最高位和最低位必须均为“1”。

 

参考:

http://m.blog.csdn.net/blog/husion01/17440333

http://m.blog.csdn.net/blog/lycb_gz/8201987

http://blog.csdn.net/liyuanbhu/article/details/7882789

 

 

相关文章:

  • 2021-11-22
  • 2021-09-08
  • 2021-05-23
  • 2021-11-01
  • 2022-12-23
猜你喜欢
  • 2022-02-25
  • 2021-05-07
  • 2021-12-30
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案