unsigned char crc8(unsigned char *data, unsigned char len)
{
unsigned char crc = 0x00;
unsigned char i, j;
for (i = 0; i < len; i++)
{
crc ^= data[i];
for (j = 0; j < 8; j++)
{
if (crc & 0x80)
{
crc = (crc << 1) ^ 0x07; // 根据生成多项式进行异或操作
}
else
{
crc <<= 1;
}
}
}
return crc;
} |