User Manual

User Guide
©2008-2020 Seeed Technology Co., Ltd. All rights reserved. solution.seeedstudio.com
21 / 23
5.5 CRC16 Check Algorithm
//-----------------------------------------------------------------------------
// CRC calculation of C51 language function is as follows
// Enter the parameter 1:snd, to be the name of the byte Check array
// Input parameters 2:num, the total number of Check to be byte
// Function return value: Check and
//-----------------------------------------------------------------------------
unsigned int calc_crc16 (unsigned char *snd, unsigned char num)
{
unsigned char i, j;
unsigned int c,crc=0xFFFF;
for(i = 0; i < num; i ++)
{
c = snd[i] & 0x00FF;
crc ^= c;
for(j = 0;j < 8; j ++)
{
if (crc & 0x0001)
{
crc>>=1;
crc^=0xA001;
}
else
{
crc>>=1;
}
}
}
return(crc);