CONTREX CX-1200 User Manual
Page 297

7 - 58
Control Byte Definitions:
Bit 7
=
(1) Negative Numbers Allowed (0) Positive Numbers only
Bit 6
=
(1) Leading Zero's (0) No Leading Zero's
Bit 5
=
(1) Restricted Parameter (0) Unrestricted Parameter
Bit 4
=
(1) Parameter Defined (0) Undefined Parameter
Bit 3
=
Not Used (always 0)
Bit 2
=
(1) Floating Decimal Point (0) Fixed Decimal Point
Bit 1
=
(1) Binary Number (0) Decimal Number
Bit 0
=
(1) Integer (0) Non-Integer
Note: Applies to Parameters & Parameter Values
Example of CRC-16 Calculation (in C):
#define CRC16 0x8005
/* CRC-16 Generating Poly */
/* function returns the accumulated CRC value calculated for the Buffer */
/* this value can be transmitted or compared to a CRC value received */
/* “*data” is a pointer to the Buffer of data bytes to calculate the CRC for */
/* “len” is the number of data bytes to use for the calculation */
unsigned int do_crc(unsigned char *data, int len)
{
int i, j;
/* byte & bit counters */
unsigned int accum = 0xFFFF;
/* CRC value accumulator */
unsigned int dat;
/* holds data byte */
for(i = 0; i < len; ++i){
/* for each byte of data */
dat = *data++;
/* get data byte & goto next */
accum ^= (dat << 8);
/* put data into high byte */
j = 0;
/* clear bit counter */
while(j++ < 8){
/* for each bit */
if(accum & 0x8000)
/* if MSB set */
accum ^= CRC16;
/* Modulus-2 math w/CRC 16 */
accum <<= 1;
/* shift left 1 bit */
}
/* end for each bit */
}
/* end for each byte */
return(accum);
/* return the CRC value */
}
/* End do_crc function */