At 09:03 PM 2/10/00 -0800, you wrote: >I was searching through the PICLIST archive for a CRC-16 >routine for a project but found nothing useful. The only >thing I found was a Dallas app note (#27) that uses a >linear method, no table lookup and no loops. > Here is how I did it. It is a bit of a brute force method and not all that efficient on the PIC's, but it works. I use locals because my compiler doesn't like to dereference pointers in complex statements. If I used a global buffer array I think it would be a bit more efficient, but since I am currently using only 10% of my CPU flash, I just don't care. :) typedef struct { uns8 low_byte; uns8 high_byte; } byte_word; typedef union { uns16 word; byte_word bytes; } word_apart; word_apart crc; void crc16_lsb(unsigned char *pData, unsigned char length) { unsigned char i, data; crc.word = 0xFFFF; do { data = *pData; pData++; crc.bytes.low_byte = crc.bytes.low_byte ^ data; for (i = 8; i > 0; i--) { if (crc.bytes.low_byte & 0x01) { crc.word = (crc.word >> 1); crc.bytes.low_byte = crc.bytes.low_byte ^ 0x08; crc.bytes.high_byte = crc.bytes.high_byte ^ 0x84; } else crc.word >>= 1; } } while (--length); crc.word = ~crc.word; } Erik Reikes Software Engineer Xsilogy, Inc. ereikes@xsilogy.com ph : (858) 535-5113 fax : (858) 535-5163 cell : (858) 663-1206