Scott Dattalo wrote: > Since you're religiously opposed to assembly, this C source will save > your soul: > > http://www.dattalo.com/technical/software/pic/crc_8bit.c > > A good C-compiler should turn the crc_bits() function into about 19 > instructions. > Scott I've tried four CRC8 routines in Keil C51 for a 8051 core: 1.- Atmel (i-button): machine cycles = 152 prog. mem. = 0B 2.- Scott, Table routine: machine cycles = 20 prog. mem. = 256B 3.- Scott, nibble routine: machine cycles = 65 prog. mem. = 32B 4.- Scott, bits routine: machine cycles = 51 prog. mem. = 0B (*)asm instrucctions= 30 For more speed, the use of table can make a difference, but the bit routine... is the winner for little program memory spaces! Thanks, Scott. Dennis Crawley Argentina www.geocities.com/proyectosenpic (spanish) ----------------- (*) 78: unsigned char crc_bits(int dato) 79: { 80: int i = (dato ^ crc) & 0xff; 81: C:0x05C8 E50F MOV A,crc(0x0F) C:0x05CA 6F XRL A,R7 C:0x05CB FF MOV R7,A 82: crc = 0; C:0x05CC E4 CLR A C:0x05CD F50F MOV crc(0x0F),A 84: if(i & 1) C:0x05CF EF MOV A,R7 C:0x05D0 30E003 JNB 0xE0.0,C:05D6 85: crc ^= 0x5e; C:0x05D3 630F5E XRL crc(0x0F),#0x5E 86: if(i & 2) C:0x05D6 EF MOV A,R7 C:0x05D7 30E103 JNB 0xE0.1,C:05DD 87: crc ^= 0xbc; C:0x05DA 630FBC XRL crc(0x0F),#0xBC 88: if(i & 4) C:0x05DD EF MOV A,R7 C:0x05DE 30E203 JNB 0xE0.2,C:05E4 89: crc ^= 0x61; C:0x05E1 630F61 XRL crc(0x0F),#0x61 90: if(i & 8) C:0x05E4 EF MOV A,R7 C:0x05E5 30E303 JNB 0xE0.3,C:05EB 91: crc ^= 0xc2; C:0x05E8 630FC2 XRL crc(0x0F),#0xC2 92: if(i & 0x10) C:0x05EB EF MOV A,R7 C:0x05EC 30E403 JNB 0xE0.4,C:05F2 93: crc ^= 0x9d; C:0x05EF 630F9D XRL crc(0x0F),#0x9D 94: if(i & 0x20) C:0x05F2 EF MOV A,R7 C:0x05F3 30E503 JNB 0xE0.5,C:05F9 95: crc ^= 0x23; C:0x05F6 630F23 XRL crc(0x0F),#0x23 96: if(i & 0x40) C:0x05F9 EF MOV A,R7 C:0x05FA 30E603 JNB 0xE0.6,C:0600 97: crc ^= 0x46; C:0x05FD 630F46 XRL crc(0x0F),#0x46 98: if(i & 0x80) C:0x0600 EF MOV A,R7 C:0x0601 30E703 JNB 0xE0.7,C:0607 99: crc ^= 0x8c; 100: C:0x0604 630F8C XRL crc(0x0F),#TH0(0x8C) 101: return crc; C:0x0607 AF0F MOV R7,crc(0x0F) } -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist