www.pudn.com > c8051f020上实现的CRC.rar > CRC.#1
#include#include #define crc_model 0x1021l #define crc_byte 0x8000l #define last_byte 2 idata unsigned short crc_variable; idata unsigned short crc_store; void crc(int adata) { int k; int crc_temp; char mark; int rchar; rchar=adata; crc_temp=crc_variable; for(k=0;k<8;k++) { if(crc_temp&crc_byte) mark=1; crc_temp<<=1; if(rchar&0x80) crc_temp++; rchar<<=1; if(mark==1) crc_temp^=crc_model; } crc_variable=crc_temp; } void main(void) { int i; int j; int k=0; int a[300]; for(i=0;i<256;i++) { crc_variable=0; a[i]=i; crc(a[i]); for( j=0;j