list p=p16f84 #include p16f84.inc ;=============================================================== ; ; CRC-8 for Dallas iButton products ; ; ; From Maxim/Dallas AP Note 27 ; ; "Understanding and Using Cyclic Redundancy Checks with ; Dallas Semiconductor iButton Products" ; ; The Ap note describes the CRC-8 algorithm used in the ; iButton products. Their implementation involves a 256 byte ; CRC table. This algorithm is implemented here. In addition ; two other algorithms are shown. One uses nibble arrays and ; the other uses boolean arithmetic. ; ; ; 18JAN03 - T. Scott Dattalo cblock 0x20 crc endc org 0 goto start ;=============================================================== crc_8: xorwf crc,f clrw btfsc crc,0 xorlw 0x5e btfsc crc,1 xorlw 0xbc btfsc crc,2 xorlw 0x61 btfsc crc,3 xorlw 0xc2 btfsc crc,4 xorlw 0x9d btfsc crc,5 xorlw 0x23 btfsc crc,6 xorlw 0x46 btfsc crc,7 xorlw 0x8c movwf crc return ;=============================================================== start: clrf crc movlw 1 call crc_8 ; crc = 0x5e clrf crc movlw 2 call crc_8 ; crc = 0xbc clrf crc movlw 4 call crc_8 ; crc = 0x61 clrf crc movlw 8 call crc_8 ; crc = 0xc2 clrf crc movlw 0x10 call crc_8 ; crc = 0x9d clrf crc movlw 0x20 call crc_8 ; crc = 0x23 clrf crc movlw 0x40 call crc_8 ; crc = 0x46 clrf crc movlw 0x80 call crc_8 ; crc = 0x8c ; dallas example: clrf crc movlw 0x02 call crc_8 ; crc = 0xbc movlw 0x1c call crc_8 ; crc = 0xaf movlw 0xb8 call crc_8 ; crc = 0x1e movlw 0x01 call crc_8 ; crc = 0xdc movlw 0x00 call crc_8 ; crc = 0xf4 movlw 0x00 call crc_8 ; crc = 0x15 movlw 0x00 call crc_8 ; crc = 0xa2 movlw 0xa2 call crc_8 ; crc = 0x00 goto start end