
56
D. Error check Generation
(1) LRC Generation
Add all bytes in the message, excluding the starting colon and ending CRLF. Add them
into an eight-bit field, so that carries will be discarded.
Subtract the final field value from FF hex (all 1's), to produce the ones complement.
Add 1 to produce the two's-complement. Ex. The query data is F0H + 06H + 00H + 80H +
17H + 70H = FDH, the two’s complement is 03H. The ‘0’ & ‘3’ will be the LRC.
(2)
CRC Generation
Generating a CRC
Step 1
Load a 16-bit register with FFFF hex (all 1's). Call this the CRC register.
Step 2
Exclusive OR the first eight-bit byte of the message with the low order byte
of the 16-bit CRC register, putting the result in the CRC register.
Step 3
Shift the CRC register one bit to the right (toward the LSB), zero filling the
MSB. Extract and examine the LSB.
Step 4
If the LSB is 0, repeat Step 3 (another shift). If the LSB is 1, Exclusive OR
the CRC register with the polynomial value A001 hex (1010 0000 0000
0001).
Step 5
Repeat Steps 3 and 4 until eight shifts have been performed. When this is
done, a complete eight-bit byte will have been processed.
Step 6
Repeat Steps 2 ... 5 for the next eight-bit byte of the message. Continue
doing this until all bytes have been processed.
The final contents of the CRC register is the CRC value.
Step 7
When the CRC is placed into the message, its upper and lower bytes must
be swapped as described below.
Pseudo code for generating a CRC-16
:
CONST ARRAY BUFFER /* data, ex: F0h, 06h, 00h, 80h, 17h, 70h */
CONST WORD POLYNOMIAL = 0A001h /* X16 = X15 + X2 + X1 */
/* SUBROTINUE OF CRC CACULATE START */
CRC_CAL(LENGTH)
VAR INTEGER LENGTH;
{ VAR WORD CRC16 = 0FFFFH; /* CRC16 initial */
VAR INTEGER = i,j; /* LOOP COUNTER */
VAR BYTE DATA; /* DATA BUFFER */
FOR (i=1;i=LENGTH;i++) /* BYTE LOOP */
{ DATA == BUFFER[i];
CRC16 == CRC16 XOR DATA
FOR (j=1;j=8;J++) /* BIT LOOP */
{ IF (CRC16 AND 0001H) = 1 THEN
CRC16 == (CRC16 SHR 1) XOR POLYNOMIAL;
ELSE
CRC16 == CRC16 SHR 1;
DATA == DATA SHR 1;
};
};
RETURN(CRC16);
};
Summary of Contents for CT-2000ES
Page 7: ...7 G Control circuit...