当前位置:文档之家› PIC单片机实现CRC的小程序

PIC单片机实现CRC的小程序

PIC单片机实现CRC的小程序

PIC单片机实现CRC的小程序

PIC 单片机实现CRC 的小程序PIC 单片机实现Dallas 的iButton 通讯时,

编了段产生和校验CRC 的子程序。;PIC 单片机pic16#includeP16CE625.INC;---

----------------------------

cblock0x20datBuff:8;assign8bytedatabufferbit_cnt;bitcountingCRC_COUNT;numbe rofbytesforCRCCRC_RESULT;CRCresulrcrc_temp;temporarydatabufferduringCRC endc;-------------------------------

#defineskp0btfsc#defineskp1btfss;===============================org0x0 00movlw.7movwfCRC_COUNTmovlwdatBuffmovwfFSR;FSRpointtodatabuffercall CRC_CHECKmovwfdatBuff+7goto$;===============================;C HECKTHECRCFOR?BYTESDATA;ForthepolynomialofX +X +X +1;Derived f ro mDallas’siButtonstandard;Beforecalling,FSR=databuffer;CRC_COUNT=numberofb ytesforCRCCRC_CHECK;~~~~~~~~~~~~~~~clrfCRC_RESULT;initializetheCRCb uffer_crc_00movlw.8;numberofbitsforonebytemovwfbit_cnt;setbitcountermovfINDF, w;getonedatabytemovwfcrc_temp;copytotemporarylocation_crc_01rrfcrc_temp,f;get LSBinCskpc;isthisLSB=1?goto_crc_02;goifLSB=0movlw0x01;doifLSB=1xorwfCR

C_RESULT,f_crc_02rrfCRC_RESULT,w;getLSBofCRCskpc;testLSBgoto_crc_03;g oifLSB=0movlw0x18;doifLSB=1xorwfCRC_RESULT,f;polynomialimplementation

_crc_03rrfCRC_RESULT,w;wholebyterightrotaterrfCRC_RESULT,fdecfszbit_cnt,f; bitcountinggoto_crc_01;goonuntilaa8bitsdoneincfFSR,f;pointerupdatetonextbytedecf szCRC_COUNT,f;bytecountinggoto_crc_00;goonuntilallbytedonemovfCRC_RESUL T,w;getCRC,ZsetifCRC=0return;returnwithCRCinWENDtips:感谢大家的阅读,本

文由我司收集整编。仅供参阅!

相关主题
文本预览
相关文档 最新文档