CRC problem

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View


I found a C routine that calculates the CRC correctly
OnCrctst() is a button to run it.
I need a 8051 ASM routine to do the same thing or similar
I can only find a few PIC routines which I cannot seen to follow.
Please, someone help me.....
Ed
============================================================================

#define                 P_KERMIT    0x8408
unsigned short          update_crc_kermit(unsigned short crc, char c);
static int              crc_tabkermit_init = FALSE;
static unsigned short   crc_tabkermit[256];
static void             init_crckermit_tab( void );

void CEfloppyDlg::OnCrctst()
{
  int i, j;
  char ed[10];
  unsigned char dstr[20];

  dstr[0]=0x30;    //known data string 02 30 30 30 33 46 4F 21 20 20 03 68
D5
  dstr[1]=0x30;    //02 is not processed for CRC
  dstr[2]=0x30;    //03 is string end and is included
  dstr[3]=0x33;    //68 D5 is CRC Kermit and does calculate correctly
  dstr[4]=0x46;    //with this routine
  dstr[5]=0x4f;
  dstr[6]=0x21;
  dstr[7]=0x20;
  dstr[8]=0x20;
  dstr[9]=0x03;
  crc = 0x0000;
  for (i=0; i<10; i++){
    j=update_crc_kermit(crc, dstr[i]);
    crc=j;
  }
  _itoa(crc, ed, 16);  //convert answer to ascii string
  AfxMessageBox(ed);   //display results with correct CRC value
}

unsigned short update_crc_kermit( unsigned short crc, char c )
{
  unsigned short tmp, short_c;

  short_c = 0x00ff & (unsigned short) c;
  if ( ! crc_tabkermit_init )
    init_crckermit_tab();
  tmp =  crc ^ short_c;
  crc = (crc >> 8) ^ crc_tabkermit[ tmp & 0xff ];

  return crc;
}

static void init_crckermit_tab( void )
{
  int i, j;
  unsigned short crc, c;

  for (i=0; i<256; i++) {
    crc = 0;
    c   = (unsigned short) i;
    for (j=0; j<8; j++) {
      if ( (crc ^ c) & 0x0001 )
        crc = ( crc >> 1 ) ^ P_KERMIT;
      else
        crc =   crc >> 1;
      c = c >> 1;
    }
    crc_tabkermit[i] = crc;
  }
  crc_tabkermit_init = TRUE;
}



Re: CRC problem



Quoted text here. Click to load it

C++ routine, actually

Quoted text here. Click to load it

Read the paper at http://www.ross.net/crc/crcpaper.html and code up a
few routines. Table-driven runs much faster but eats storage that you
may or may not have in an 8051-family chip. If you're in a hurry, skip
to sections 18 and 19 where cookbook routines are provided in C. Once
it's working in C, it should be easy to convert the shifts, masks, xors,
etc. to assembler.

--
Rich Webb     Norfolk, VA

Re: CRC problem



Quoted text here. Click to load it

You can probably adapt one of several routines here:

http://www.8052.com/codelib

--
Dan Henry

Site Timeline