Subroutine Instructions - Siemens SIMATIC S7-200 System Manual

Programmable controller
Hide thumbs Also See for SIMATIC S7-200:
Table of Contents

Advertisement

S7-200 Programmable Controller System Manual

Subroutine Instructions

The Call Subroutine instruction (CALL) transfers control to
the subroutine SBR_N. You can use a Call Subroutine
instruction with or without parameters. After the subroutine
completes its execution, control returns to the instruction that
follows the Call Subroutine.
The Conditional Return from Subroutine instruction (CRET)
terminates the subroutine based upon the preceding logic.
To add a subroutine, select the Edit > Insert > Subroutine
menu command.
Error conditions that set ENO = 0
H 0008 (maximum subroutine nesting exceeded)
H 0006 (indirect address)
From the main program, you can nest subroutines (place a
subroutine call within a subroutine) to a depth of eight. From
an interrupt routine, you cannot nest subroutines.
A subroutine call cannot be placed in any subroutine called from an interrupt routine. Recursion (a
subroutine that calls itself) is not prohibited, but you should use caution when using recursion with
subroutines.
Table 6-78
Valid Operands for the Subroutine Instruction
Inputs/Output
s
SBR_N
IN
IN/OUT
OUT
1
Must be offset 1 or above
2
Must be offset 30 or above
Tip
STEP 7--Micro/WIN automatically adds an unconditional return from each subroutine.
When a subroutine is called, the entire logic stack is saved, the top of stack is set to one, all other
stack locations are set to zero, and control is transferred to the called subroutine. When this
subroutine is completed, the stack is restored with the values saved at the point of call, and
control is returned to the calling routine.
Accumulators are common to subroutines and the calling routine. No save or restore operation is
performed on accumulators due to subroutine use.
When a subroutine is called more than once in the same cycle, the edge/up, edge/down, timer
and counter instructions should not be used.
204
Data Types
Operands
WORD
Constant
BOOL
V, I, Q, M, SM, S, T, C, L, Power Flow
BYTE
VB, IB, QB, MB, SMB, SB, LB, AC, *VD, *LD, *AC
WORD, INT
VW, T, C, IW, QW, MW, SMW, SW, LW, AC, AIW, *VD, *LD, *AC
constant
DWORD, DINT
VD, ID, QD, MD, SMD, SD, LD, AC, HC, *VD, *LD, *AC
&VB, &IB, &QB, &MB, &T, &C, &SB, &AI, &AQ, &SMB, constant
STRING
*VD, *LD, *AC, constant
BOOL
V, I, Q, M, SM
BYTE
VB, IB, QB, MB, SMB
WORD, INT
VW, T, C, IW, QW, MW, SMW
DWORD, DINT
VD, ID, QD, MD, SMD
BOOL
V, I, Q, M, SM
BYTE
VB, IB, QB, MB, SMB
WORD, INT
VW, T, C, IW, QW, MW, SMW
DWORD, DINT
VD, ID, QD, MD, SMD
for CPU 221, CPU 222, CPU 224:
for CPU 224XP and CPU 226
2
, S, T, C, L
2
, SB, LB, AC, *VD, *LD, *AC
2
, SW, LW, AC, *VD, *LD, *AC
2
, SD, LD, AC, *VD, *LD, *AC
2
, S, T, C, L
2
, SB, LB, AC, *VD, *LD, *AC
2
, SW, LW, AC, AQW, *VD, *LD, *AC
2
, SD, LD, AC, *VD, *LD, *AC
0 to 63
0 to 127
1
, constant
1
,
1
,
1
1
1
1
1
1

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents