![crc16計算算法完整_第1頁](http://file4.renrendoc.com/view/a33d8e3e0531f7f163973b36b454740b/a33d8e3e0531f7f163973b36b454740b1.gif)
![crc16計算算法完整_第2頁](http://file4.renrendoc.com/view/a33d8e3e0531f7f163973b36b454740b/a33d8e3e0531f7f163973b36b454740b2.gif)
![crc16計算算法完整_第3頁](http://file4.renrendoc.com/view/a33d8e3e0531f7f163973b36b454740b/a33d8e3e0531f7f163973b36b454740b3.gif)
![crc16計算算法完整_第4頁](http://file4.renrendoc.com/view/a33d8e3e0531f7f163973b36b454740b/a33d8e3e0531f7f163973b36b454740b4.gif)
![crc16計算算法完整_第5頁](http://file4.renrendoc.com/view/a33d8e3e0531f7f163973b36b454740b/a33d8e3e0531f7f163973b36b454740b5.gif)
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
PAGECRC16計算算法XOR=異或N=字節(jié)的信息位POLY=CRC16多項式計算=1010000000000001(生成多項式=1+x+x+x)在CRC16中,發(fā)送的第一個字節(jié)為低字節(jié).
CRC計算示例(幀0207)CRC寄存器初始化1111111111111111XOR第一個字符00000000000000001111111111111101移位10111111111111110SYMBOL124\f"Symbol"11010000000000001標志1,XOR多項式1101111111111111移位20110111111111111SYMBOL124\f"Symbol"1標志1,XOR多項式10100000000000011100111111111110移位30110011111111110SYMBOL189\f"Symbol"0移位40011001111111111SYMBOL189\f"Symbol"110100000000000011001001111111110移位50100100111111111SYMBOL189\f"Symbol"0移位60010010011111111SYMBOL189\f"Symbol"110100000000000011000010011111110移位70100001001111111SYMBOL189\f"Symbol"0移位80010000100111111SYMBOL189\f"Symbol"0101000000000000110000001001111100000000000000111XOR第二個字符1000000100111001移位10100000010011100SYMBOL189\f"Symbol"110100000000000011110000010011101移位20111000001001110SYMBOL189\f"Symbol"110100000000000011101000001001111移位30110100000100111SYMBOL189\f"Symbol"110100000000000011100100000100110移位40110010000010011SYMBOL189\f"Symbol"0移位50011001000001001SYMBOL189\f"Symbol"110100000000000011001001000001000移位60100100100000100SYMBOL189\f"Symbol"0移位70010010010000010SYMBOL189\f"Symbol"0移位80001001001000001SYMBOL189\f"Symbol"0 最高有效 最低有效幀的CRC16則為:4112例執(zhí)行CRC生成的C語言的函數(shù)在下面示出。所有的可能的CRC值都被預裝在兩個數(shù)組中,當計算報文內容時可以簡單的索引即可。一個數(shù)組含有16位CRC域的所有256個可能的高位字節(jié),另一個數(shù)組含有地位字節(jié)的值。這種索引訪問CRC的方式提供了比對報文緩沖區(qū)的每個新字符都計算新的CRC更快的方法。注意:此函數(shù)內部執(zhí)行高/低CRC字節(jié)的交換。此函數(shù)返回的是已經(jīng)經(jīng)過交換的CRC值。也就是說,從該函數(shù)返回的CRC值可以直接放置于報文用于發(fā)送。函數(shù)使用兩個參數(shù):unsignedchar*puchMsg; 指向含有用于生成CRC的二進制數(shù)據(jù)報文緩沖區(qū)的指針unsignedshortusDataLen; 報文緩沖區(qū)的字節(jié)數(shù).CRC生成函數(shù)unsignedshortCRC16(puchMsg,usDataLen) /*函數(shù)以unsignedshort類型返回CRC*/unsignedchar*puchMsg; /*用于計算CRC的報文*/unsignedshortusDataLen; /*報文中的字節(jié)數(shù)*/{unsignedcharuchCRCHi=0xFF; /*CRC的高字節(jié)初始化*/unsignedcharuchCRCLo=0xFF; /*CRC的低字節(jié)初始化*/unsigneduIndex; /*CRC查詢表索引*/while(usDataLen--) /*完成整個報文緩沖區(qū)*/{uIndex=uchCRCLo^*puchMsgg++; /*計算CRC*/uchCRCLo=uchCRCHi^auchCRCHi[uIndex};uchCRCHi=auchCRCLo[uIndex];}return(uchCRCHi<<8|uchCRCLo);}
高字節(jié)表/*高位字節(jié)的CRC值*/staticunsignedcharauchCRCHi[]={0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40};低字節(jié)表/*低位字節(jié)的CRC值*/staticcharauchCRCLo[]={0x00,0xC0,0xC1,0x01,0xC3,0x03,0x02,0xC2,0xC6,0x06,0x07,0xC7,0x05,0xC5,0xC4,0x04,0xCC,0x0C,0x0D,0xCD,0x0F,0xCF,0xCE,0x0E,0x0A,0xCA,0xCB,0x0B,0xC9,0x09,0x08,0xC8,0xD8,0x18,0x19,0xD9,0x1B,0xDB,0xDA,0x1A,0x1E,0xDE,0xDF,0x1F,0xDD,0x1D,0x1C,0xDC,0x14,0xD4,0xD5,0x15,0xD7,0x17,0x16,0xD6,0xD2,0x12,0x13,0xD3,0x11,0xD1,0xD0,0x10,0xF0,0x30,0x31,0xF1,0x33,0xF3,0xF2,0x32,0x36,0xF6,0xF7,0x37,0xF5,0x35,0x34,0xF4,0x3C,0xFC,0xFD,0x3D,0xFF,0x3F,0x3E,0xFE,0xFA,0x3A,0x3B,0xFB,0x39,0xF9,0xF8,0x38,0x28,0xE8,0xE9,0x29,0xEB,0x2B,0x2A,0xEA,0xEE,0x2E,0x2F,0xEF,0x2D,0xED,0xEC,0x2C,0xE4,0x24,0x25,0xE5,0x27,0xE7,0xE6,0x26,0x22,0xE2,0xE3,0x23,0xE1,0x21,0x20,0xE0,0xA0,0x60,0x61,0xA1,0x63,0xA3,0xA2,0x62,0x66,0xA6,0xA7,0x67,0xA5,0x65,0x64,0xA4,0x6C,0xAC,0xAD,0x6D,0xAF,0x6F,0x6E,0xAE,0xAA,0x6A,0x6B,0xAB,0x69,0xA9,0xA8,0x68,0x78,0xB8,0xB9,0x79,0xBB,0x7B,0x7A,0xBA,0xBE,0x7E,0x7F,0xBF,0x7D,0xBD,0xBC,0x7C,0xB4,0x74,0x75,0xB5,0x77,0xB7,0xB6,0x76,0x72,0xB2,0xB3,0x73,0xB1,0x71,0x70,0xB0,0x50,0x90,0x91,0x51,0x93,0x53,0x52,0x92,0x96,0x56,0x57,0x97,0x55,0x95,0x94,0x54,0x9C,0x5C,0x5D,
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 施工現(xiàn)場施工防化學災害制度
- 應急物資裝備應急預案
- 醫(yī)療護理醫(yī)學培訓 吸痰護理技術課件
- DB6103T 87-2025企業(yè)簡易注銷登記服務規(guī)程
- XX村電排建設及維護合同書2025
- 個人股權抵押融資合同樣本
- 臨時促銷服務合同
- 中小企業(yè)融資合作合同協(xié)議
- 京東商城代運營合同模板
- 個人質押貸款合同模板
- 2025年礦山開采承包合同實施細則4篇
- 某縣城區(qū)地下綜合管廊建設工程項目可行性實施報告
- 《架空輸電線路導線舞動風偏故障告警系統(tǒng)技術導則》
- 2024年計算機二級WPS考試題庫
- 廣東省廣州黃埔區(qū)2023-2024學年八年級上學期期末數(shù)學試卷(含答案)
- 法理學課件馬工程
- 《無菌檢查培訓》課件
- 2024-2030年中國香菇行業(yè)銷售狀況及供需前景預測報告
- 高中英語必背3500單詞表(完整版)
- GB/T 44570-2024塑料制品聚碳酸酯板材
- 禁止送禮的協(xié)議書
評論
0/150
提交評論