// CRC.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "math.h" void main() // int check_sum(unsigned char *buff, char start, char bytes) { char byte_cnt,bit_cnt; /* loop counters */ unsigned int crc_reg; /* Result register */ unsigned int CRCHi, CRCLo;/*Low and high order bytes of the crc*/ crc_reg = 0xFFFF; /* Set the CRC register to all 1’s */ /* Repeat for each byte of sub string */ for(byte_cnt=start; byte_cnt<(bytes+start); byte_cnt++) { crc_reg = crc_reg ^ (unsigned int)buff[byte_cnt]; /*EXOR CRC & Next Byte*/ /* Test each bit of the CRC */ for(bit_cnt=0; bit_cnt<8; bit_cnt++) { if(crc_reg & 0x0001) { crc_reg = crc_reg >>1; /* IF LSB=1 EXOR CRC with A001H*/ crc_reg = crc_reg ^ 0Xa001; /* Then shift CRC toward LSB */ } else crc_reg = crc_reg>>1; /* ELSE Shift CRC towards LSB */ } } CRCLo=crc_reg>>8; /*Swap the low and high order bytes of the crc result*/ CRCHi=crc_reg<<8; crc_reg = CRCLo+CRCHi; // return crc_reg; /*Final CRC register Result */ }