#include <stdio.h>
typedef unsigned char uint8_t ;
typedef unsigned int uint32_t ;
typedef unsigned short uint16_t ;
static uint8_t CRC8(uint8_t *data, uint8_t datalen)
{
uint8_t crc = 0xff;
uint8_t i = 0;
if(datalen <= 0)
{
return crc;
}
while(datalen--)
{
for(i = 0x80; i != 0; i /=2)
{
if((crc & 0x80) != 0)
{
crc *= 2;
crc ^= 0x07;
}
else
{
crc *=2;
}
if((*data & i) != 0)
{
crc ^= 0x07;
}
}
data++;
}
return crc;
}
int main(void) {
uint8_t example_1[] = {0xd4, 0x00, 0xd5, 0x06, 0xbf, 0xff, 0x1e, 0x01, 0x3c, 0x08};
uint8_t example4[] = {0xf0,0x00,0xf1,0x06,0xe7,0x00,0xe1,0x5c,0x5e,0xf7};
uint8_t crc;
uint8_t len = 0xa;
crc = CRC8(example4, len);
printf("Hello World crc:%x\n",crc);
return 0;
}