#1, BYTE CRC
参考:
https://blog.csdn.net/m0_37697335/article/details/113267780?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522F1451286-1B97-44AA-A5FC-386045B4939B%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=F1451286-1B97-44AA-A5FC-386045B4939B&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduend~default-1-113267780-null-null.142v100pc_search_result_base9&utm_term=crc16%20modbus%E6%9F%A5%E8%A1%A8%E6%B3%95%20c%E8%AF%AD%E8%A8%80&spm=1018.2226.3001.4187
注意表格不对,会有错误。
/MODBUS******************
-
Name: CRC-16/MODBUS x16+x15+x2+1
-
Width: 16
-
Poly: 0x8005
-
Init: 0xFFFF
-
Refin: True
-
Refout: True
-
Xorout: 0x0000
-
Note:
*****************************************************************************/
WORD CRC_GetModbus16(BYTE * pData, WORD nLength)
{
WORD cRc_16 = 0xFFFF, i;
BYTE temp;for (i = 0; i < nLength; ++i)
{
temp = (BYTE)(cRc_16 & 0xFF);
cRc_16 = (WORD)((cRc_16 >> 8) ^ crc16tab[(temp ^ pData[i]) & 0xFF]);}
return cRc_16;
}
#2, WORD CRC