User manual

110
Cyclic Redundancy Checking (CRC)
The CRC is a 2-byte checksum code attached to the end of the message
by the sender to check if the communication frame is transmitted
without error.
The sender calculates the CRC when it sends one-byte message, and
the receiver should also calculate the CRC from the data of the
message. Since this CRC calculation takes a long time when writing a
communication program, you should find any ways to increase the
speed of this part to avoid errors and improve the communication
speed.
CRC-16 calculation subroutine written in BASIC
CRC_Sum: CRC-16 reserve code after the calculation (CRC content to be sent at the
end of message)
Data: CRC-16 data input to be calculated (byte data from message)
1000 CRC_Sum = CRC_Sum XOR Data
1010 FOR I=1 to 8
1020 CARRY=CRC_Sum AND 1
1030 RC_Sum=CRC_Sum SHR 1
1040 IF CARRY=1 THEN CRC_Sum XOR 0A001H
1050 NEXT I
1060 RETURN
CRC-16 calculation subroutine written in PASCAL
Procedure CRC16 (Data: Byte)
Var i : Byte;
Begin
CRC_Sum := CRC_Sum xor Data;
for i : 1 to 8 do
Begin
if((CRC_Sum and 1)=1) then CRC_Sum := (CRC_Sum shr 1) xor $A001;
Else CRC_Sum: = CRC_Sum shr 1;
End;
End;
CRC-16 calculation subroutine written in C
Void Crc16 (unsigned int Data) {
Unsigned int i;
Crc=Crc^(Data & 0x00FF);
for(i=0;i<=7;I++) {
if((Crc & 0x0001) == 0x0001) Crc=(Crc>>1)^0xA001;
else Crc=Crc>>1;
}
}
CRC calculation range
DA SA Function Length Information CRC L CRC H
CRC calculation range
2 bytes