CRC problem

Apr 04, 2009 2 Replies

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> 8) ^ crc_tabkermit[ tmp & 0xff ];



return crc; }



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



for (i=0; i 1 ) ^ P_KERMIT; else crc = crc >> 1; c = c >> 1; } crc_tabkermit[i] = crc; } crc_tabkermit_init = TRUE; }


C++ routine, actually

Read the paper at

formatting link
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

You can probably adapt one of several routines here:

formatting link

Dan Henry

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required