APPENDIX D
4618 - 021
143
C Program
/*
Straightforward, non-optimized CRC-CCITT routine.
Assumes 16-bit integer variables.
MSB of integer is MSB of CRC result.
*/
#define POLY
0x8408
/* Polynomial */
void main(void)
{
unsigned int crc;
crc = 0xffff;
printf("crc of 'T' is 0x%x\n", bytecrc("T",&crc) );
crc = 0xffff;
printf("crc of 'THE' is 0x%x\n", blkcrc("THE",&crc,3) );
crc = 0xffff;
printf("crc of 'THE,QUICK,BROWN,FOX,0123456789' is
0x%x\n",blkcrc("THE,QUICK,BROWN,FOX,0123456789",&crc,30));
} /* end main */
unsigned int blkcrc(unsigned char *bufptr, unsigned int *crcres, unsigned int count)
{
int i;
for (i = 1; i <= count; i++ , + )
/* do for whole block */
bytecrc(bufptr, crcres);
/* do CRC for 1 byte */
return *crcres;
} /* end blkcrc */
unsigned int bytecrc(unsigned char *bufptr, unsigned int *crcres)
{
unsigned int j, ch, Q;
ch = (unsigned int) *bufptr;
/* get char to int format */
for (j = 1; j <= 8; j ++ )
{
/* do each bit LSB first */
Q = (*crcres & 0x0001) ^ (ch & 0x0001);
/*
Q = 1 if either crcres or data least significant bits are 1, but
not
both.
*/
if ( Q == 0x0001 )
{
/*- Q is one */
*crcres = *crcres >> 1;
/* shift right one */
*crcres = *crcres ^ POLY;
/* XOR with POLYnomial */
}
else
/*- Q is zero */
*crcres = *crcres >> 1; /* just shift no XOR */
ch = ch >> 1; /* move next data into position */
}
return *crcres;
} /* end bytecrc */
Содержание Signature
Страница 16: ......
Страница 26: ...INSTALLATION 10 4618 021 Fig 5 Typical Metal Detector Conveyor ...
Страница 31: ...INSTALLATION 4618 021 15 Fig 10 Cable Gland Assemblies for Power Supply Unit ...
Страница 52: ...OPERATING INSTRUCTIONS 36 4618 021 Fig 14 Supervisor Mode Flow Chart ...
Страница 55: ...OPERATING INSTRUCTIONS 4618 021 39 Fig 15 Engineer Mode Flow Chart ...
Страница 71: ...OPERATING INSTRUCTIONS 4618 021 55 Fig 16 Pack Sensor Mode Flow Chart ...
Страница 82: ...OPERATING INSTRUCTIONS 66 4618 021 Fig 18 QA Inspector And Operator Flow Chart ...
Страница 92: ...OPERATING INSTRUCTIONS 76 4618 021 Fig 19 Viewing Mode Flow Chart ...