Basic Elements For Constructing A Program - Siemens Simatic S7-200 System Manual

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

Advertisement

Basic Concepts for Programming an S7-200 CPU
6.4

Basic Elements for Constructing a Program

The S7-200 CPU continuously executes your program to control a task or process. You
create this program with STEP 7-Micro/WIN and download it to the CPU. From the main
program, you can call different subroutines or interrupt routines.
Organizing the Program
Programs for an S7-200 CPU are constructed from three basic elements: the main program,
subroutines (optional), and interrupt routines (optional). As shown in Figure 6-6, an S7-200
program is structured into the following organizational elements:
Main program: The main body of the program is where you place the instructions that
control your application. The instructions in the main program are executed sequentially,
once per scan of the CPU. To terminate the main program, use an Unconditional End coil
in ladder or a Main Program End instruction (MEND) in STL. See (1) in Figure 6-6.
Subroutines: These optional elements of your program are executed only when called
from the main program. Place the subroutines after the end of the main program
(following the Unconditional End coil in ladder logic or the MEND instruction in STL). Use
a Return (RET) instruction to terminate each subroutine. See (2) in Figure 6-6.
Interrupt routines: These optional elements of your program are executed on each
occurrence of the interrupt event. Place the interrupt routines after the end of the main
program (following the Unconditional End coil in ladder logic or the MEND instruction in
STL). Use a Return From Interrupt (RETI) instruction to terminate each interrupt routine.
See (3) in Figure 6-6.
Subroutines and interrupt routines follow the Unconditional End coil or MEND instruction of
the main program; there is no other requirement for locating the subroutines and interrupt
routines within your program. You can mix subroutines and interrupt routines following the
main program; however, in order to provide a program structure that is easy to read and
understand, consider grouping all of the subroutines together after the main program, and
then group all of the interrupt routines together after the subroutines.
User Program
Figure 6-6
6-8
Main Program
MEND
SBR 0 Subroutine (optional)
RET
SBR 1 Subroutine (optional)
RET
SBR n Subroutine (optional)
RET
INT 0 Interrupt Routine (optional)
RETI
INT 1 Interrupt Routine (optional)
RETI
INT n Interrupt Routine (optional)
RETI
Program Structure for an S7-200 CPU
Main Program:
(1)
Executed once per scan
Subroutine:
Executed when called
(2)
from the main program
Interrupt Routine:
Executed on each
(3)
occurrence of the
interrupt event
S7-200 Programmable Controller System Manual
C79000-G7076-C230-02

Advertisement

Table of Contents
loading

Table of Contents