Berger Automating with STEP 7 in STL and SCL
Automating with
STEP7 in STL and SCL
Programmable Controllers
SIMATIC S7-300/400
by Hans Berger
6th revised and enlarged edition, 2012
Publicis Publishing
Bibliographic information published by the Deutsche Nationalbibliothek
The Deutsche Nationalbibliothek lists this publication in the Deutsche Nationalbibliografie;
detailed bibliographic data are available in the Internet at http://dnb.d-nb.de.
This book contains one Trial DVD. “SIMATIC STEP 7 Professional, Edition 2010 SR1, Trial
License” encompasses: SIMATIC STEP 7 V5.5 SP1, S7-GRAPH V5.3 SP7, S7-SCL V5.3 SP6,
S7-PLCSIM V5.4 SP5 and can be used for trial purposes for 14 days.
This Software can only be used with the Microsoft Windows XP 32 Bit Professional Edition SP3
or Microsoft Windows 7 32/64 Bit Professional Edition SP1 or Microsoft Windows 7 32/64 Bit
Ultimate Edition SP1 operating systems.
Additional information can be found in the Internet at:
http://www.siemens.com/sce/contact
http://www.siemens.com/sce/modules
http://www.siemens.com/sce/tp
The programming examples concentrate on describing the STL and SCL functions and providing
SIMATIC S7 users with programming tips for solving specific tasks with this controller.
The programming examples given in the book do not pretend to be complete solutions or to be
executable on future STEP 7 releases or S7-300/400 versions. Additional care must be taken in order
to comply with the relevant safety regulations.
The author and publisher have taken great care with all texts and illustrations in this book.
Nevertheless, errors can never be completely avoided. The publisher and the author accept no liability,
regardless of legal basis, for any damage resulting from the use of the programming examples.
The author and publisher are always grateful to hear your responses to the contents of the book.
Publicis Publishing
P.O. Box 3240
91050 Erlangen
E-mail: publishing-distribution@publicis.de
Internet: www.publicis-books.de
ISBN 978-3-89578-412-5
6th edition, 2012
Editor: Siemens Aktiengesellschaft, Berlin and Munich
Publisher: Publicis Publishing, Erlangen
© 2012 by Publicis Erlangen, Zweigniederlassung der PWW GmbH
This publication and all parts thereof are protected by copyright. Any use of it outside the
strict provisions of the copyright law without the consent of the publisher is forbidden and will
incur penalties. This applies particularly to reproduction, translation, microfilming or other
processing‚ and to storage or processing in electronic systems. It also applies to the use of
individual illustrations or extracts from the text.
Printed in Germany
Preface
dling of STEP 7 when configuring, networking
and programming SIMATIC PLCs. The
description of the “Basic Functions” of a binary
control, such as logic operations or latching/
unlatching functions, makes it particularly easy
for first-time users or users changing from relay
contactor controls to become acquainted with
STEP 7. The digital functions explain how dig-
ital values are combined; for example, basic
calculations, comparisons or data type conver-
sion.
The book shows how you can control program
processing (program flow) and design struc-
tured programs. In addition to the cyclically
processed main program, you can also incorpo-
rate event-driven program sections as well as
influence the behavior of the controller at
startup and in the event of errors/faults.
One section of the book is dedicated to the
description of the SCL programming language.
SCL is especially suitable for programming
complex algorithms or for tasks in the data
management area, and it supplements STL
towards higher-level programming languages.
The book concludes with the description of a
program for converting STEP 5 programs to
STEP 7 programs, and a general overview of
the system functions and the function set for
STL and SCL.
The contents of this book describe Version 5.5
of the STEP 7 programming software and Ver-
sion 5.3 SP5 of the S7-SCL optional package.
Nuremberg, May 2012
Hans Berger
Preface
The SIMATIC automation system unites all the
subsystems of an automation solution under a
uniform system architecture to form a homoge-
neous whole from the field level right up to pro-
cess control. This Totally Integrated Automa-
tion (TIA) enables integrated configuring and
programming, data management and communi-
cations throughout the complete automation
system.
As the basic tool for SIMATIC, STEP 7 plays
an integrating role in Totally Integrated Auto-
mation. STEP 7 is used to configure and pro-
gram the SIMATIC S7, SIMATIC C7 and
SIMATIC WinAC automation systems. Micro-
soft Windows has been chosen as the operating
system to take advantage of the familiar user
interface of standard PCs as also used in office
environments.
For block programming STEP 7 provides pro-
gramming languages that comply with DIN EN
6.1131-3: STL (statement list; an Assembler-
like language), LAD (ladder logic; a represen-
tation similar to relay logic diagrams), FBD
(function block diagram) and the S7-SCL
optional package (Structured Control Lan-
guage, a Pascal-like high-level language). Sev-
eral optional packages supplement these lan-
guages: S7-GRAPH (sequential control), S7-
HiGraph (programming with state-transition
diagrams) and CFC (connecting blocks; similar
to function block diagram). The various meth-
ods of representation allow every user to select
the suitable control function description. This
broad adaptability in representing the control
task to be solved significantly simplifies work-
ing with STEP 7.
This book describes the STL and SCL program-
ming languages for S7-300/400. As a valuable
supplement to the description of the languages,
and following an introduction to the S7-300/
400 automation system, it provides valuable,
practice-oriented information on the basic han-
5
6
The Contents of the Book at a Glance
Overview of the S7-
300/400 programma-
ble logic controller
PLC functions compa-
rable to a contactor
control system
Numbers, manipulat-
ing the contents of the
accumulators
Program run control,
block functions
Introduction
Basic Functions
Digital Functions
Program Flow
Control
1 SIMATIC S7-300/
400 Programmable
Controller
Structure of the Pro-
grammable Controller
(Hardware Components
of S7-300/400);
Memory Areas;
Distributed I/O
(PROFIBUS DP);
Communications
(Subnets);
Modules Addresses;
Addresses Areas
2 STEP 7 Program-
ming Software
Editing Projects;
Configuring Stations;
Configuring the Net-
work; Symbol Editor;
STL Program Editor;
SCL Program Editor;
Online Mode;
Testing the Program
3 SIMATIC S7
Program
Program Processing;
Block Types;
Programming STL and
SCL Code Blocks;
Programming Data
Blocks;
Addressing Variables,
Constant Representa-
tions, Data Types
(Overview)
4 Binary Logic
Operations
AND, OR and
Exclusive OR
Functions;
Nesting Functions
5 Memory
Functions
Assign, Set and Reset;
Edge Evaluation;
Example of a
Conveyor Belt
Control System
6 Move Functions
Load Functions,
Transfer Functions;
Accumulator
Functions;
System Functions for
Data Transfer
7 Timer Functions
Start SIMATIC Timers
with Five Different
Types;
IEC Timers
8 Counter Functions
SIMATIC Counters;
Count up, Count
down, Set, Reset and
Scan Counters;
IEC Counters
9 Comparison
Functions
Comparison Accord-
ing to Data Types INT,
DINT and REAL
15 Status Bits
Binary Flags,
Digital Flags;
EN/ENO
Mechanism
10 Arithmetic
Functions
Four-function Math
with INT, DINT and
REAL numbers;
Adding Constants,
Decrementing and
Incrementing
11 Math Functions
Trigonometric
Functions;
Arc Functions;
Powers, Logarithm
12 Converting
Functions
Data Type Conversion;
Complement Forma-
tion
13 Shift Functions
Shifting and Rotating
14 Word Logic
AND, OR,
Exclusive OR
16 Jump
Functions
Unconditional Jump;
Jumps Conditional on
the RLO, BR and the
Digital Flags;
Jump Distributor,
Loop Jump
17 Master Control
Relay
MCR Dependency,
MCR Area,
MCR Zone
18 Block Functions
Block Call,
Block End;
Temporary and Static
Local Data;
Data Addresses
19 Block
Parameters
Formal Parameters,
Actual Parameters;
Declarations,
Assignments and
“Parameter Passing”
Processing the user
program
Working with complex
variables, indirect
addressing
Description of the
Programming
Language SCL
S5/S7 Converter,
block libraries,
overviews
Program
Processing
Variable Handling
Structured Control
Language SCL
Appendix
20 Main Program
Program Structure;
Scan Cycle Control
(Response Time, Start
Information, Back-
ground Scanning);
Program Functions;
Communications via
Distributed I/O and
Global Data;
S7 and S7-Basic
Communications
21 Interrupt
Handling
Time-of-Day Inter-
rupts; Time-Delay In-
terrupts; Watchdog
Interrupts; Hardware
Interrupts; DPV1 In-
terrupts; Multiproces-
sor Interrupt; Handling
Interrupts
22 Restart
Characteristics
Cold Restart,
Hot Restart,
Warm Restart;
STOP, HOLD,
Memory Reset;
Parameterizing
Modules
23 Error Handling
Synchronous Errors;
Asynchronous Errors;
System Diagnostics
24 Data Types
Structure of the
Data Types,
Declaration and
Use of Elementary and
Complex Data Types;
Programming of User
Defined Data Types
UDT
25 Indirect
Addressing
Area Pointer,
DB Pointer,
ANY Pointer;
Indirect Addressing
via Memory and
Register (Area-internal
and Area-crossing);
Working with Address
Registers
26 Direct Variable
Access
Load Variable
Address
Data Storage of
Variables in the
Memory;
Data Storage when
Transferring Parame-
ters; “Variable” ANY
Pointer;
Brief Description of
the “Message Frame
Example”
27 Introduction,
Language
Elements
Addressing,
Operators,
Expressions,
Value Assignments
28 Control
Statements
IF, CASE, FOR,
WHILE, REPEAT,
CONTINUE, EXIT,
GOTO, RETURN
29 SCL Block
Calls
Function Value; OK
Variable, EN/ENO
Mechanism, Descrip-
tion of Examples
30 SCL Functions
Timer Functions;
Counter Functions;
Conversion and Math
Functions;
Shifting and Rotating
31 IEC Functions
Conversion and Com-
parison Functions;
STRING Functions;
Date/Time-of-Day
Functions;
Numerical Functions
32 S5/S7
Converter
Preparations for
Conversion;
Converting STEP 5
Programs;
Postprocessing
33 Block
Libraries
Organization Blocks;
System Function
Blocks;
IEC Function Blocks;
S5-S7 Converting
Blocks;
TI-S7 Converting
Blocks;
PID Control Blocks;
DP Functions
34 STL Operation
Overview
Basic Functions;
Digital Functions;
Program Flow Control;
Indirect Addressing
35 SCL Statement
and Function
Overview
Operators;
Control Statements;
Block Calls;
Standard Functions
7