![background image](http://html1.mh-extra.com/html/omron/cvm1d/cvm1d_operation-manual_742532370.webp)
365
5-30 Subroutines
Subroutines break large control tasks into smaller ones and enable you to reuse
a given set of instructions. When the main program calls a subroutine, control is
transferred to the subroutine and the subroutine instructions are executed. The
instructions within a subroutine are written in the same way as main program
code. When all the subroutine instructions have been executed, control returns
to the main program to the point just after the point from which the subroutine
was entered (unless otherwise specified in the subroutine).
5-30-1 SUBROUTINE ENTRY and RETURN: SBN(150)/RET(152)
SUBROUTINE ENTRY: SBN(150)
(150)
SBN
N
N: Subroutine number
#
Operand Data Area
Ladder Symbol
SUBROUTINE RETURN: RET(152)
(152)
RET
Ladder Symbol
SBN(150) is used to mark the beginning of a subroutine program; RET(152) is
used to mark the end. Each subroutine is identified with a subroutine number, N,
that is programmed as the definer for SBN(150). This same subroutine number
is used in any SBS(151) that calls the subroutine (see next subsection). No sub-
routine number is required with RET(152).
All subroutines must be programmed at the end of the main program. When one
or more subroutines have been programmed, the main program will be ex-
ecuted up to the first SBN(150) before returning to address 00000 for the next
scan; if part of the main program is placed after a SBN(150), it will be executed
only as part of a subroutine, if at all. Subroutines will not be executed unless
called by SBS(151).
END(001) must be placed at the end of the last subroutine program, i.e., after the
last RET(152). END(001) is not required at any other point in the program. (Re-
fer to the next subsection for further details.)
N must be between 000 and 999 and each subroutine number can be used in
SBN(150) once only.
If SBN(150) is mistakenly placed in the main program, it will inhibit program ex-
ecution past that point, i.e., program execution will return to the beginning when
SBN(150) is encountered.
If either DIFU(013) or DIFU(014) is placed within a subroutine, the operand bit
will not be turned OFF until the next time the subroutine is executed, i.e., the op-
erand bit may stay ON longer than one cycle.
The step instructions, STEP(008) and SNXT(009), cannot be used within a sub-
routine.
There are no flags directly affected by these instructions.
Description
Precautions
Flags
Subroutines
Section 5-30
Summary of Contents for CVM1D
Page 462: ...SYSMAC CVM1D Duplex System Programmable Controllers Operation Manual Revised August 2001...
Page 463: ...iv...
Page 465: ...vi...