[Gmecm] J1850 CRC

Bill Shaw b.shaw
Mon Jan 8 18:16:06 UTC 2007


Nice!  Thanks Paul!

Bill


Paul Smith wrote:
> Hi Bill,
>
> Here's one implementation of the J1850 CRC routine.
>
> unsigned char crcbitbybit(unsigned char* p, unsigned char len) {
>
> unsigned char crchighbit=0x80;
> unsigned char crc=0x7E;
> unsigned char polynom=0x1D;
> unsigned char order=8;
>
> 	// bit by bit algorithm with augmented zero bytes.
> 	// does not use lookup table, suited for polynom orders between 1...32.
>
> 	unsigned char i, j, c, bit;
>
>
> 	for (i=0; i<len; i++) {
>
> 		c = (unsigned long)*p++;
>
> 		for (j=0x80; j; j>>=1) {
>
> 			bit = crc & crchighbit;
> 			crc<<= 1;
> 			if (c & j) crc|= 1;
> 			if (bit) crc^= polynom;
> 		}
> 	}
>
> 	for (i=0; i<order; i++) {
>
> 		bit = crc & crchighbit;
> 		crc<<= 1;
> 		if (bit) crc^= polynom;
> 	}
>
> 	crc^= 0xFF;;
>
> 	return(crc);
> }
>
>
>   
>> Does anyone have a J1850 CRC routine in C that they'd be willing to
>> share with the rest of the class?
>>
>> Thanks,
>>
>> BIll
>> _______________________________________________
>> Gmecm mailing list
>> Gmecm at diy-efi.org
>> Subscribe: http://lists.diy-efi.org/mailman/listinfo/gmecm
>> Main WWW page: http://www.diy-efi.org/gmecm
>>
>>     
>
>
>   





More information about the Gmecm mailing list