beautypg.com

Ccitt/crc code calculation – Welch Allyn LC101 CO2 Module - User Manual User Manual

Page 60

background image

LC101 CO

2

Module OEM Implementation Manual

Page 60

Confidential

Welch Allyn OEM Technologies

CRC

The CRC is performed on the byte stream, not on the corresponding values of the ASCII hex
characters. The CRC check should be performed at a very low level within the host's software.
The host calculates a CRC of the actual transmitted bytes excluding the check byte (which is sent
as two ASCII HEX characters).

For the byte string:

057h represents a single character, in this case the ASCII letter "W". 0x25 represents the
resulting value of the ASCII HEX representation of the parameter value. Thus, 0x25 is actually
transmitted as 32h (ASCII letter "2") followed by 35h (ASCII letter "5").”

CCITT/CRC Code Calculation

The 8-bit CCITT/CRC code is based on the CCITT/CCITT/CRC polynomial which uses the
conventional right shifting (high to low) method. The polynomial is:

G(x) = x^8 + x^7 + x^2 + 1

The feedback constant is 0xA1 (hex). CCITT/CRC values are initialized to 0xFF (hex).

The CCITT/CRC update value is implemented by a table look up scheme. The following is an
implementation example in ‘C’ language. Usage:

#define updateCCITT/CRC_8(value,CCITT/CRC) (CCITT/CRC_table_8[value^CCITT/CRC])
#define MAX_SIZE 23

/*choose any size*/

unsigned char CCITT/CRC_table_8[256];
unsigned char data[MAX_SIZE];

/*data to be CCITT/CRC checked*/

unsigned char calc_CCITT/CRC(char data,int n)
{

unsigned char CCITT/CRC;
/*make_table_8( );*/

/*do this at least once*/

CCITT/CRC=0xFF;
for(i=0;i

CCITT/CRC=updateCCITT/CRC_8(data[i],CCITT/CRC);

}
return(CCITT/CRC);

}

{STX}

“W”

xx

yy

CCITT/CRC

{ETX}

waveform byte string

0x25

0x80

0x79

{STX}W258079{ETX}

02h

57h

32h35h

38h30h

37h39h

03h