Some of the PLC instructions are program control instructions. The program control instructions include jump instructions used to change the order of program execution, and instructions used for control during program operation.
This article first introduces jump and label instructions.
For S7-200/200 SMART PLC, the only jump instruction is JMP, but for S7-1200 PLC, some new instructions are added, such as the jump instruction JMP_LIST that defines the jump list, and the jump branch Instruction SWITCH and so on, we will introduce the different places of the instruction. Let’s start now~
Learn complete physical and online PLC Training by the Best Technical Training Institute
Ask a question first?
What is a jump, and what function can be achieved by using a jump instruction?
The so-called jump is to skip a certain section of the program without executing it. The function of changing the execution order of the program can be realized by using the jump instruction. If we do not execute the jump instruction, each program segment is executed in order from top to bottom. When the jump instruction is executed, the jump instruction will stop the sequence execution of the program and jump to the program at the specified location. Start to execute down.
So how do we specify this location?
At this time we need to use label instructions!
Therefore, the jump instruction and the label instruction are used in pairs. When jumping, the CPU will no longer scan and execute the program between the jump instruction and the label instruction. This is what we need to pay attention to.
The jump instructions of S7-1200 PLC include logic structure jump instruction, jump instruction JMP_LIST that defines jump list and jump branch instruction SWITCH.
Let’s take a look at the functions of these commands respectively.
Jump instruction of logic result
When the logic operation result is 1, the jump instruction JMP is executed, and when the logic operation result is 0, the jump instruction JMPN is executed. The matching label command is LABLE, and the label number needs to be marked on the label command, which can be numbers, letters or Chinese characters. The jump instruction for S7-200/200 SMART PLC only has JMP and the matching LBL instruction, it is not a jump instruction based on the logic result, so there is no JMPN instruction, and for the label LBL instruction, S7-200/200 SMART PLC The label number can only be numbers, not letters and Chinese characters.
Define the jump instruction JMP_LIST of the jump list
The JMP_LIST instruction can define multiple conditional jumps, jump to the program of the label segment specified by the value of the K pin to continue execution, and the jump label number is specified at the output of the instruction box. We can increase the output pins by clicking the button on the command to increase the output pins, up to 32 pins, that is, DEST0~DEST31, so the value of K should also be in the range of 0~31. If it is not for these numbers, no jump is performed.
when the EN driving condition of the JMP_LIST instruction is met, it will jump to the corresponding label to start execution according to the value of K. The value of K is 1, which means that it jumps to the label _002 linked to the DEST1 pin. Start execution.
Jump branch instruction SWITCH
The SWITCH instruction is based on the results of one or more comparison instructions to define the jump to multiple program labels to be executed. The value to be compared is specified in pin K, and this value is compared with the value provided by each input pin. Compare, if the comparison condition is met, jump to the corresponding label and start executing the program.
when the value of K is equal to 47.0, it jumps to the 001 tag corresponding to the DEST0 pin to start execution, and when the value of K is equal to 24.6, it jumps to the 002 tag corresponding to the DEST1 pin to start execution, When the value of K is less than or equal to 14.9, it jumps to the 003 labels corresponding to the DEST2 pin to start execution. If the value of K does not meet the comparison results of the above three comparison conditions, it jumps to the ELSE tube Start execution at the 004 labels corresponding to the foot.
When we use jump instructions, there are some precautions that need to be paid attention to.
- The jump instruction can jump forward or backwards.
- You can only jump in the same code block, and cannot jump from one code block to another code block.
- The name of the jump label can only be used once in a block.
- Only one jump label can be set in a program break.
In the process of executing the jump, there is another problem. If the program after the jump execution hopes to be executed to the specified place, it can automatically return, and no longer execute it. What should I do at this time?
In fact, in this case, we can use another instruction-the return instruction RET to achieve. The return instruction RET can be used to control the execution of the program. When the RET instruction is executed, the execution of the code block is exited, that is, the RET instruction The following blocks will no longer be executed by the CPU.
Therefore, the jump instruction and the return instruction RET are used together to realize the selection and execution of the program segment.
For example, if you add this RET instruction to each label segment, after executing the program from this label to the RET instruction, you can automatically return without executing subsequent programs.
The above is the related content of the jump instruction of S7-1200 PLC. This instruction can be used for functions such as automatic hand switching. There are still many applications. You still need to master the use of this instruction!
In the next article, I will continue to introduce you to the control instructions at runtime. You can continue to pay attention to it~
(Original from Training Network, the author.