I'm looking for a utility that takes a given data packet with a CRC16, and decodes the poly used. ie. TheCRCis 16 ... where 16 is for CRC16 or CRC32, 16 being CRC16 and byte... is a packet ending in the CRC. Eventually, I need this in PIC code too. It's for a protocol decoder. Craig > -----Original Message----- > From: pic microcontroller discussion list > [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of root > Sent: June 18, 1999 12:21 AM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: CRC16 > > > Hallo, > > here is the source for your convenience. I use this routine extensively. > Imre > -------------[ Source code follows ]--------------------- > ; 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 = 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 using > ; > ; > 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 > > ------------------[End of Code Fragment]------------------- > > On Thu, 17 Jun 1999, Martin Huber wrote: > > > Hallo, > > > > has anyone an idea for implementing a CRC16 into a PIC16C6X f|r checking > > a serial datastream. > > Or does anyone know, where to get an example for a code. > > > > Thanks > > > > Martin Huber > > > > >