PIC单片机实现CRC的小程序
时间:03-08
来源:互联网
点击:
PIC单片机实现CRC的小程序
PIC单片机实现Dallas的iButton通讯时,编了段产生和校验CRC的子程序。
;PIC单片机 www.pic16.com
#includeP16CE625.INC>
;-------------------------------
cblock0x20
datBuff:8;assign8bytedatabuffer
bit_cnt;bitcounting
CRC_COUNT;numberofbytesforCRC
CRC_RESULT;CRCresulr
crc_temp;temporarydatabufferduringCRC
endc
;-------------------------------
#defineskp0btfsc
#defineskp1btfss
;===============================
org0x000
movlw.7
movwfCRC_COUNT
movlwdatBuff
movwfFSR;FSRpointtodatabuffer
callCRC_CHECK
movwfdatBuff+7
goto$
;===============================
;CHECKTHECRCFOR?BYTESDATA
;ForthepolynomialofX^8+X^5+X^4+1
;DerivedfromDallas'siButtonstandard
;Beforecalling,FSR=databuffer
;CRC_COUNT=numberofbytesforCRC
CRC_CHECK;~~~~~~~~~~~~~~~
clrfCRC_RESULT;initializetheCRCbuffer
_crc_00
movlw.8;numberofbitsforonebyte
movwfbit_cnt;setbitcounter
movfINDF,w;getonedatabyte
movwfcrc_temp;copytotemporarylocation
_crc_01
rrfcrc_temp,f;getLSBinC
skpc;isthisLSB=1?
goto_crc_02;goifLSB=0
movlw0x01;doifLSB=1
xorwfCRC_RESULT,f
_crc_02
rrfCRC_RESULT,w;getLSBofCRC
skpc;testLSB
goto_crc_03;goifLSB=0
movlw0x18;doifLSB=1
xorwfCRC_RESULT,f;polynomialimplementation
_crc_03
rrfCRC_RESULT,w;wholebyterightrotate
rrfCRC_RESULT,f
decfszbit_cnt,f;bitcounting
goto_crc_01;goonuntilaa8bitsdone
incfFSR,f;pointerupdatetonextbyte
decfszCRC_COUNT,f;bytecounting
goto_crc_00;goonuntilallbytedone
movfCRC_RESULT,w;getCRC,ZsetifCRC=0
return;returnwithCRCinW
END
PIC单片机实现Dallas的iButton通讯时,编了段产生和校验CRC的子程序。
;PIC单片机 www.pic16.com
#includeP16CE625.INC>
;-------------------------------
cblock0x20
datBuff:8;assign8bytedatabuffer
bit_cnt;bitcounting
CRC_COUNT;numberofbytesforCRC
CRC_RESULT;CRCresulr
crc_temp;temporarydatabufferduringCRC
endc
;-------------------------------
#defineskp0btfsc
#defineskp1btfss
;===============================
org0x000
movlw.7
movwfCRC_COUNT
movlwdatBuff
movwfFSR;FSRpointtodatabuffer
callCRC_CHECK
movwfdatBuff+7
goto$
;===============================
;CHECKTHECRCFOR?BYTESDATA
;ForthepolynomialofX^8+X^5+X^4+1
;DerivedfromDallas'siButtonstandard
;Beforecalling,FSR=databuffer
;CRC_COUNT=numberofbytesforCRC
CRC_CHECK;~~~~~~~~~~~~~~~
clrfCRC_RESULT;initializetheCRCbuffer
_crc_00
movlw.8;numberofbitsforonebyte
movwfbit_cnt;setbitcounter
movfINDF,w;getonedatabyte
movwfcrc_temp;copytotemporarylocation
_crc_01
rrfcrc_temp,f;getLSBinC
skpc;isthisLSB=1?
goto_crc_02;goifLSB=0
movlw0x01;doifLSB=1
xorwfCRC_RESULT,f
_crc_02
rrfCRC_RESULT,w;getLSBofCRC
skpc;testLSB
goto_crc_03;goifLSB=0
movlw0x18;doifLSB=1
xorwfCRC_RESULT,f;polynomialimplementation
_crc_03
rrfCRC_RESULT,w;wholebyterightrotate
rrfCRC_RESULT,f
decfszbit_cnt,f;bitcounting
goto_crc_01;goonuntilaa8bitsdone
incfFSR,f;pointerupdatetonextbyte
decfszCRC_COUNT,f;bytecounting
goto_crc_00;goonuntilallbytedone
movfCRC_RESULT,w;getCRC,ZsetifCRC=0
return;returnwithCRCinW
END
单片机 51单片机 MCU 单片机视频教程 单片机开发 ARM单片机 AVR单片机 PIC单片机 Atmel stm32 单片机学习 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)