<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Thu, 26 Jan 2012 14:35:03 +0100
From   : nicolagiacobbe@... (nicola giacobbe)
Subject: CRC-8 algorithm

I have a C version around:

typedef unsigned char uchar;

uchar crc_update(uchar crc, uchar data)
{
       uchar i,j;

       crc = crc ^ data;
       for (i = 0; i < 8; i++)
       {
               j = crc & 0x01;
               crc >>= 1;
               if (j) crc ^= 0x8C;
       }

       return crc;
}

and here is the 6502 listing (converted on-the-fly, so no warranty here):

    10DIM A 256

    20FOR I%=0 TO 3 STEP 3

    30P%=A

    40 REM USING (&74) FOR STARTING ADDRESS

    50 REM (&76) FOR THE BYTE COUNT

    60 REM &78 FOR THE CRC VALUE

    70[OPT I%

    80.crc

    90LDY#0

   100.crc_update

   110LDA &76

   120ORA &77

   130BEQ endcrc

   140LDA(&74),Y

   150EOR &78

   160LSR A

   170BCC skipSeeding

   180EOR #&8C

   190.skipSeeding

   200STA &78

   210CLC

   220LDA &74

   230ADC#1

   240STA &74

   250LDA &75

   260ADC#0

   270STA &75

   280CLC

   290LDA &76

   300ADC #&FF

   310STA &76

   320LDA &77

   330ADC #&FF

   340STA &77

   350JMP crc_update

   360.endcrc

   370RTS

   380]

   390NEXT I%

   400REM TESTING THE CODE

   410REM BY LOADING AN ARRAY AND THEN CHANGING A BIT

   420DIM B 800

   430?&74=B MOD 256

   440?&75=B DIV 256

   450?&76=800 MOD 256

   460?&77=800 DIV 256

   470FOR I%=0 TO 799

   480B?I%=I%

   490NEXT

   500?&78=0

   510CALL crc

   520PRINT "CRC BEFORE CHANGE=";?&78

   530J%=1

   540FOR I%=0 TO 7

   550B?37=(B?37) EOR J%

   560?&74=B MOD 256

   570?&75=B DIV 256

   580?&76=800 MOD 256

   590?&77=800 DIV 256

   600?&78=0

   610CALL crc

   620 PRINT "CRC AFTER FLIPPING BIT ";I%;" = ";?&78

   630B?37=(B?37) EOR J%

   640J%=J%+J%

   650NEXT I%

   660END



On Thu, 26 Jan 2012 11:06:02 +0100, J.G.Harston <jgh@...> wrote:

> I have a need for an 8-bit CRC algorithm (transmitting up to about
> 20 bytes, CRC-16 would be overkill, and I'd prefer a CRC rather
> than a checksum).
>
> There are various CRC-8 polynomials in use, what would people
> recommend? When I need a CRC-16 I use XMODEM &1021, when I
> need a CRC-32 I use PKZip &EDB88320.
>
> Ta.
>


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>