发表于:2003-11-03 14:25:00
2楼
void CRC_check(unsigned char *buff, int len, unsigned char *chk)
{
unsigned short crc;
unsigned char *cptr;
int i;
crc=0xFFFF;
for(i=0; i <len; i++)
{
CRC_calc(buff[i] , &crc);
}
cptr=(unsigned char *)&crc;
chk[0]=*(cptr); // Low Byte first
chk[1]=*(cptr+1); // High byte
return;
}
/*...........................................................................*/
/* CRC one byte calculation */
/*...........................................................................*/
void CRC_calc(unsigned char c, unsigned short *crc)
{
unsigned char bn;
unsigned short i;
for(i = 8 ; i > 0 ; i--)
{
bn = c;
c /=(unsigned char) 2;
if((*crc & 0x0001)){
bn++;
}
*crc /=(unsigned short) 2;
if((bn & 0x0001)){
*crc ^= 0xa001;
}
}
return;
}