15 lines
471 B
C++
15 lines
471 B
C++
|
#include "CRC16.h"
|
|||
|
|
|||
|
unsigned short CRC16(unsigned char *puchMsg, unsigned short usDataLen)
|
|||
|
{
|
|||
|
unsigned char uchCRCHi = 0xFF; /* <20><>CRC <20>ֽڳ<D6BD>ʼ<EFBFBD><CABC>*/
|
|||
|
unsigned char uchCRCLo = 0xFF; /* <20><>CRC <20>ֽڳ<D6BD>ʼ<EFBFBD><CABC>*/
|
|||
|
unsigned int uIndex; /* CRC ѭ<><D1AD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
while (usDataLen--) /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
{
|
|||
|
uIndex = uchCRCHi ^ *puchMsg++; /* <20><><EFBFBD><EFBFBD>CRC */
|
|||
|
uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex];
|
|||
|
uchCRCLo = auchCRCLo[uIndex];
|
|||
|
}
|
|||
|
return (((unsigned short)uchCRCHi << 8u) | uchCRCLo);
|
|||
|
}
|