71
4
4 Instructions 4.2.1 Subprogram
• A subprogram must end with the SRET statement.
• The subprogram starting from P*** can be called in multiple locations or by another subprogram, but the number
of nested layers cannot exceed ve.
• A subprogram cannot be called within itself; otherwise, an innite loop or program running timeout occurs.
• Subprograms support the T192–T199 or T246–T249 timers.
Subprograms are programmed in an independent window in AutoShop, which eliminates the problems
of the FEND and SRET instructions. The names (including Chinese characters) of subprograms can be
modied according to your need.
SRET: Subprogram return
◆
Overview
The SRET instruction forces the PLC to return to a subprogram.
SRET
Subprogram return Applicable model:
H3U
An independent instruction without operands and contact driving
16-bit instruction
(1 step)
SRET:
Continuous
execution
◆
Function
The SRET statement is located at the end of a subprogram. After the SRET instruction is executed, the
PLC returns to the statement that calls the subprogram and continues program execution.
In AutoShop, the SRET instruction does not need to be programmed at the end of a subprogram.
Example 1:
When X1 = ON,
the CALL instruction is executed. The
system jumps to the P2 designated subprogram and
starts scanning. When scanning proceeds to the SRET
instruction, the system returns to the instruction (address:
14) next to the CALL instruction and continues scanning.
When X1 = OFF, the CALL instruction is not executed
and the P2 subprogram is not called.
P2 subroutine
The format of the previous example instruction in AutoShop is as follows:
Right
-click the subprogram SBR_01 in the program
block and choose Property, and then name 01 as
needed.
Main program Subprogram: SBR_01