By Dr. Imre Bartfai
; What you need is to define the polynomial. E. g. for the CCITT one:
poly0 equ 0x21
poly1 equ 0x10
; Do not forget to initialize <crcval> = <crch:crcl> before the 1st call
; e. g. with 0xFF or with zeroes, as the particular CRC algorithm
; requires.
;This subroutine calculates a 16-bit CRC
;--------
; CrcUpd: update <crcval> using <W>
;
;
CBLOCK crcblk
crch
crcl
saved
oldcch
i
ENDC
CrcUpd movwf saved ; j = W
movlw d'8' ; W = 8
movwf i ; i = W
_loop movfw crch
movwf oldcch ; temporary save
clrc ; clear carry for rlf
rlf crcl ; crc << 1
rlf crch
movfw saved ; the char read
xorwf oldcch,F ; test with old high
btfss oldcch,7 ; if bit set, apply mask
b _notset ; otherwise skip
movlw poly0
xorwf crcl,F
movlw poly1
xorwf crch,F
_notset clrc ; for rlf
rlf saved,F ; next bit of saved
decfsz i,F
b _loop
return
;
; End CrcUpd
| file: /techref/microchip/crc.htm, 1KB, , updated: 2003/7/17 14:15, local time: 2008/10/11 09:13,
38.103.63.61:LOG IN
|
| ©2008 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? Please DO link to this page! Digg it! <A HREF="http://www.piclist.com/techref/microchip/crc.htm"> PIC Microcontroller Bit Math Method - CRC</A> |
| Did you find what you needed? |
|
o List host: MIT, Site host massmind.org, Top posters @20081011 Apptech, Jinx, Xiaofan Chen, olin piclist, Vitaliy, Alan B. Pearce, William \Chops\ Westfield, JonnyMac, Tamas Rudnai, Gerhard Fiedler, * Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Shultz Electronics, Timothy Weber, on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
|
.