|
#include
E-mail:
info@telesys.ru
typedef unsigned char byte;
typedef unsigned int word;
unsigned char crc8(unsigned char *buf, unsigned int i, unsigned char crc);
unsigned char cc[]={0x1f,0xc8,0xc2,0x00,0x00,0x00,0x00,0x26};
void main (void)
{
unsigned char crc;
int i;
crc=crc8(cc,7,0);
printf("crc8 %02x\n",(word)crc);
}
byte crc8 (byte *buf, word len, byte crc)
{
word i,j,k;
byte ret=crc,m,l;
for (i=0;i
m=1;
for (j=0;j<8;j++)
{
l=((buf[i]&m)?0x8c:0)^((ret&0x1)?0x8c:0);
ret>>=1;
ret^=l;
m<<=1;
}
}
return ret;
}
Ответы