> > The following is an example program that creates a string and appends = > an ANSI standard CRC-16 to it. This will work on any PIC16cXX processor. = > I have ported it to the 12c5xx, but it is messy because of the limited = > jump space in the 'c5x architecture. Feel free to use/modify this as you = > wish. The code was adapted from a C routine I found on the net a while = > back. This code has been tested and decoded by a PC that the PIC sent = > data to. > =20 > Follow up to: rfarmer@mindspring.com > [several hundred lines of code snipped] Here is a slightly smaller version: ; ; ; Calculate CRC-16. ; ; ; ; In: W - Byte to add to CRC ; CRC_High,CRC_Low - Previous CRC (set to 0 on startup) ; Act: Update ; Out: CRC_High,CRC_Low - Updated CRC value ; Regs: tmp, Counter CalcCRC movwf tmp movlw 8 movwf Counter CRC_Loop movf CRC_Low,w xorwf tmp,w clrc rrf CRC_High rrf CRC_Low andlw 1 jz CRC_Skip movlw 0xa0 xorwf CRC_High movlw 0x01 xorwf CRC_Low CRC_Skip rrf tmp loop Counter,CRC_Loop return This may or may not generate the same CRC (it's the same algorithm as used in zoo and arc and many other old archives). By changing the two hex values that are XORed, you can change this code to calculate any CRC-16. I've also got one that interleaves the CRC calculations with the serial receive, so it takes zero time to execute. This code runs on 12 and 14 bit PICs with minimal changes. Frank