![CSZ EZT-430i Скачать руководство пользователя страница 14](http://html.mh-extra.com/html/csz/ezt-430i/ezt-430i_users-reference-manual_2693060014.webp)
EZT-430i Communications Manual
Serial
Communication
CSZ
EZT-430i
REV
C
4.5
Example Cyclical Redundancy Checksum (CRC) Algorithm
unsigned int ca_crc(unsigned char *start_of_packet, unsigned char *end_of_packet)
{
unsigned int crc;
unsigned char bit_count;
unsigned char *char_ptr;
/* Start at the beginning of the packet */
char_ptr = start_of_packet;
/* Initialize CRC */
crc = 0xFFFF;
/* Loop through the entire packet */
do{
/* Exclusive-OR the byte with the CRC */
crc ^= (unsigned int)*char_ptr;
/* Loop through all 8 data bits */
bit_count = 0;
do{
/* If the LSB is 1, shift the CRC and XOR the polynomial mask with the CRC */
if(crc & 0x0001){
crc >>= 1;
crc ^= 0xA001;
}
/* If the LSB is 0, shift the CRC only */
else{
crc >>= 1;
}
} while(bi+ < 7);
} while(c+ < end_of_packet);
return(crc);
}