Cyclical redundancy checksum (crc) algorithm – Watlow Series 97 User Manual
Page 71

Cyclical Redundancy Checksum (CRC) Algorithm
This C routine, calc_crc(), calculates the cyclical redundancy checksum, CRC, for
a string of characters. The CRC is the result of dividing the string by 0xA001.
Modbus applications calculate the packet’s CRC then append it to the packet.
#define POLYNOMIAL 0xA001;
unsigned int calc_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 ^= POLYNOMIAL;
}
/* If the LSB is 0, shift the CRC only */
else{
crc >>= 1;
}
} while(bit_count++ < 7);
} while(char_ptr++ < end_of_packet);
return(crc);
}
Wa t l o w S e r i e s 9 7
A p p e n d i x
■
A . 9
- 12LS Controller (111 pages)
- 8LS Controller (140 pages)
- 8PID Controller (55 pages)
- Addendum to EZwarePlus (50 pages)
- ANASCAN (62 pages)
- ANASOFT (95 pages)
- ANAWIN 2 (154 pages)
- ANAWIN 3 (23 pages)
- Calibrating Watlow Series 988 Family Process Controls (19 pages)
- CAS (98 pages)
- CAS200 (124 pages)
- CLS (180 pages)
- CLS200 (251 pages)
- CLS200, MLS300 and CAS200 (92 pages)
- Control Console (12 pages)
- CPC400 (230 pages)
- DIN-A-MITE Style A (9 pages)
- DIN-A-MITE Style B (14 pages)
- DIN-A-MITE Style C (22 pages)
- DIN-A-MITE Style D (9 pages)
- DIN-Mount Adapter Instruction Sheet, Rev A (1 page)
- Dual DAC (4 pages)
- EM Gateway (28 pages)
- E-Safe Hybrid Relay Rev B (4 pages)
- E-SAFE II Hybrid Power Switch (4 pages)
- EZwarePlus Programming (264 pages)
- EZ-ZONE PM (111 pages)
- EZ-ZONE PM PID (125 pages)
- EZ-ZONE PM Express Limit (34 pages)
- EZ-ZONE PM Express (35 pages)
- EZ-ZONE PM Integrated Controller (181 pages)
- EZ-ZONE RM Limit Module Rev C (127 pages)
- EZ-ZONE RMA Modul (79 pages)
- EZ-ZONE RMC (236 pages)
- EZ-ZONE RME (124 pages)
- EZ-ZONE RMH (161 pages)
- EZ-ZONE RUI/Gateway (62 pages)
- EZ-ZONE RM-Scanner-Modul (140 pages)
- EZ-ZONE ST (97 pages)
- F4 External Event Board - Rev.B (2 pages)
- HG Series Mercury Displacement Relay (6 pages)
- LogicPro (296 pages)
- Mercury Relay or MDR Retrofit (13 pages)
- MICRODIN (24 pages)
- MICRODIN (106 pages)