The programmable controllers produced by SIEMENS in Germany are also widely used in China, and are used in metallurgy, chemical and printing production lines. Siemens (SIEMENS) PLC products include LOGO, S7-200, S7-1200, S7-300, S7-400 and so on. Siemens S7 series PLC is small in size, fast in speed and standardized, with network communication capability, stronger function and high reliability. S7 series PLC products can be divided into micro PLC (such as S7-200), PLC with small-scale performance requirements (such as S7-300) and PLC with medium and high performance requirements (such as S7-400).
CRC checkRC is the Cyclic Redundancy Check (Cyclic Redundancy Check): It is the most commonly used error checking code in the field of data communication. The feature is that the length of the information field and the check field can be arbitrarily selected. Cyclic Redundancy Check (CRC) is a data transmission error detection function that performs polynomial calculation on data and attaches the result to the back of the frame. The receiving device also performs a similar algorithm to ensure the correctness and completeness of the data transmission. Sex.
working principle
The basic principle of the Cyclic Redundancy Check (CRC) is to splicing the parity code of the R bit after the K-bit information code. The entire code length is N bits. Therefore, this code is also called the (N, K) code. For a given (N, K) code, it can be proved that there is a polynomial G(x) with the highest power NK=R. A check code of K bit information can be generated according to G(x), and G(x) is called a generator polynomial of this CRC code.
The specific generation process of the check code is as follows: suppose the information to be transmitted is represented by a polynomial C(X), and C(x) is shifted to the left by R bits (which can be expressed as C(x)*2R), so that the right side of C(x) The R bit will be vacated, which is the position of the check code. The remainder obtained by dividing C(x)*2R by the generator polynomial G(x) is the check code. Any code consisting of a binary bit string can be in one-to-one correspondence with a polynomial whose coefficients are only '0' and '1'. For example, the polynomial corresponding to the code 1010111 is x6+x4+x2+x+1, and the polynomial is the code 101111 corresponding to x5+x3+x2+x+1.
  
PLC's crc check programMethod 1: Calculation
Main program: OB1
Network 1
LD M0.0
EU
CALL SBR0, AC0 /
INCB VB0
INCB VB0
XMT send and receive buffer, 0
Network 2
LD M0.1
EU
CALL SBR0, AC0
AW" AC0, +0
MOVB 1, AC0
SBR_0: SBR0
VAR_OUTPUT
Crc:INT;
END_VAR
VAR
Count:INT;
Ptr:DWORD;
END_VAR
BEGIN
Network 1
// MOVW AC0, *#ptr is used for sending, directly writes the CRC to the send buffer, then mmodbusBufr adds 2.
//
LD SM0.0
MOVW 16#FFFF, AC0
BTI VB0, LW2
MOVD &VB0, LD4
INCD LD4
FOR AC2, +1, LW2
XORB *LD4, AC0
FOR AC1, +1, +8
SRW AC0, 1
LD SM1.1
XORW 16#A001, AC0
NEXT
LD SM0.0
INCD LD4
NEXT
Network 2
// MOVW AC0, #crc for receiving
// If the program does not need to receive, you can delete this line and delete the OUT parameter of crc.
//
//
//
// MOVW AC0, *#ptr for sending
// Write the CRC directly to the send buffer, then add mmodbusBufr to 2.
// If the program does not need to send, you can delete this line.
LD SM0.0
SWAP AC0
MOVW AC0, LW0
MOVW AC0, *LD4
Network 3 // Network title
// network annotation
END_SUBROUTINE_BLOCK
INTERRUPT_BLOCK INT_0: INT0
TITLE=interrupt program comment
BEGIN
Network 1 // Network title
// network annotation
END_INTERRUPT_BLOCK
Method 2: Lookup method
ORGANIZATION_BLOCK main program: OB1
TITLE= differs from method 1 in that it has an additional initialization, which simplifies the CRC calculation process and shortens the time.
// call method is the same as method 1
BEGIN
Network 1 // Network title
// Initialize the CRC table, which takes 512 bytes. VB2256---------VB2767
LD SM0.1
CALL SBR0
Network 2 // Network title
// send
LD M0.0
EU
CALL SBR1, AC0 //AC0 is useless here
INCB VB2000
INCB VB2000
XMT send and receive buffer, 0
Network 3
// Check the received data right or wrong after the completion of the reception. If the calculation result is 0, the transmission is correct.
LD M0.1
EU
CALL SBR1, AC0
AW" AC0, +0
MOVB 1, AC0
END_ORGANIZATION_BLOCK
SUBROUTINE_BLOCK SBR_0: SBR0
TITLE=Subprogram comment
VAR
Index1:INT;
Index2:INT;
END_VAR
BEGIN
Network 1
LD SM0.0
MOVD &VB2256, AC3
MOVD +0, AC2
FOR LW0, +1, +256
MOVW AC2, AC0
FOR LW2, +1, +8
SRW AC0, 1
Network 2
LD SM1.1
XORW 16#A001, AC0
Network 3
NEXT
Network 4
LD SM0.0
MOVW AC0, *AC3
INCW AC2
+I +2, AC3
Network 5
NEXT
Network 6 // Network title
// network annotation
END_SUBROUTINE_BLOCK
SUBROUTINE_BLOCK SBR_1: SBR1
TITLE=Subprogram comment
VAR_OUTPUT
Crc:INT;
END_VAR
VAR
Count:INT;
Ptr:DWORD;
END_VAR
BEGIN
Network 1
LD SM0.0
BTI VB2000, LW2
MOVD & VB2000, LD4
INCD LD4
XORD AC0, AC0
MOVD 16#FFFF, AC2
FOR AC1, +1, LW2
MOVB *LD4, AC0
XORW AC2, AC0
ANDW 16#FF, AC0
SLW AC0, 1
MOVD &VB2256, AC3
+I AC0, AC3
SWAP AC2
ANDW 16#FF, AC2
XORW *AC3, AC2
INCD LD4
Network 2
NEXT
Network 3
LD SM0.0
SWAP AC2
MOVW AC2, LW0
MOVW AC2, *LD4
Network 4 // Network title
// network annotation
END_SUBROUTINE_BLOCK
INTERRUPT_BLOCK INT_0: INT0
TITLE=interrupt program comment
BEGIN
Network 1 // Network title
// network annotation
END_INTERRUPT_BLOCK
Shenzhen ChengRong Technology Co.,Ltd. , https://www.laptopstandsuppliers.com