SIMATIC Structured Control Language (SCL) For S7-300/S7-400 . - Siemens

Transcription

Preface, ContentsPart 1: Designing ProgramsPart 2: Operating and DebuggingSIMATICStructured Control Language(SCL) for S7-300/S7-400ProgrammingManualThis manual has the order number:6ES7811-1CA02-8BA0Part 3: Language DescriptionAppendixGlossary, Index

iiSafety Guidelines!!!This manual contains notices which you should observe to ensure your own personal safety, as well as toprotect the product and connected equipment. These notices are highlighted in the manual by a warningtriangle and are marked as follows according to the level of danger:Dangerindicates that death, severe personal injury or substantial property damage will result if proper precautions arenot taken.Warningindicates that death, severe personal injury or substantial property damage can result if proper precautions arenot taken.Cautionindicates that minor personal injury or property damage can result if proper precautions are not taken.Notedraws your attention to particularly important information on the product, handling the product, or to a particularpart of the documentation.Qualified PersonnelThe device/system may only be set up and operated in conjunction with this manual.Only qualified personnel should be allowed to install and work on this equipment. Qualified persons aredefined as persons who are authorized to commission, to ground, and to tag circuits, equipment, andsystems in accordance with established safety practices and standards.Correct Usage!TrademarksNote the following:WarningThis device and its components may only be used for the applications described in the catalog or the technicaldescription, and only in connection with devices or components from other manufacturers which have beenapproved or recommended by Siemens.SIMATIC , SIMATIC NET and SIMATIC HMI are registered trademarks of SIEMENS AG.Third parties using for their own purposes any other names in this document which refer totrademarks might infringe upon the rights of the trademark owners.Copyright Siemens AG 1998 All rights reservedDisclaimer of LiabilityThe reproduction, transmission or use of this document or its contents isnot permitted without express written authority. Offenders will be liable fordamages. All rights, including rights created by patent grant or registrationof a utility model or design, are reserved.We have checked the contents of this manual for agreement with thehardware and software described. Since deviations cannot be precludedentirely, we cannot guarantee full agreement. However, the data in thismanual are reviewed regularly and any necessary corrections included insubsequent editions. Suggestions for improvement are welcomed.Siemens AGBereich Automatisierungs- und AntriebstechnikGeschaeftsgebiet Industrie-AutomatisierungssystemePostfach 4848, D-90327 Nuernberg Siemens AG 1998Technical data subject to change.Siemens Aktiengesellschaft6ES7811-1CA02-8BA0Structured Control Language (SCL) for S7-300/S7-400, ProgrammingC79000 G7076 C522 01

PrefacePurposeThis manual is your guide to creating user programs in the Structured ControlLanguage (SCL) programming language. The manual explains the basicprocedures for creating programs using the SCL editor, SCL compiler andSCL debugger.This manual also includes a reference section that describes the syntax andfunctions of the language elements of SCL.AudienceThis manual is intended for S7 programmers, commissioning engineers, andmaintenance/service personnel. A working knowledge of automationprocedures is essential.Scope of theManualThis manual is valid for release 3.0 of the STEP 7 standard programmingsoftware package.Compliance withStandardsSCL corresponds to the Structured Control Language defined in theDIN EN-61131-3 (IEC 1131-3) standard, although there are essentialdifferences with regard to the operations. For further details, refer to the tableof standards in the STEP 7 file NORM.TAB.Structured Control Language (SCL) for S7-300/S7-400, ProgrammingC79000-G7076-C522-01iii

PrefaceOverview of theSTEP 7DocumentationThere is a wide range of both general and task-oriented user documentationavailable to support you when configuring and programming an S7programmable controller. The following descriptions and the figure belowwill help you to find the user documentation you require.This symbol indicates the order in which you should read themanuals, particularly if you are a first-time user of S7.MeaningSymbolThis documentation introduces the methodology.This is a reference manual on a specific topic.The documentation is supported by online help.S7-300 Programmable ControllerQuick StartPrimer/30/Manuals onS7-300/S7-400HardwareManualProgr.ManualSystem Software for S7-300/S7-400Program Design/234/Online HelpUserManualStandard Software for S7 and M7STEP 7/232/Standard Software for S7Converting S5 /250/ReferenceManualGRAPHfor S7/251/HiGraph/252/CFCs forS7/235/System Software forS7-300/400System and StandardFunctions/254/Language Packages/xxx/: Number in the list of referencesivStructured Control Language (SCL) for S7-300/S7-400, ProgrammingC79000-G7076-C522-01

PrefaceTable 1-1Summary of the DocumentationTitleS7-300 ProgrammableLogic ControllerQuick Start, PrimerSubjectThe primer provides you with a very simple introduction to the methods ofconfiguring and programming an S7-300/400. It is particularly suitable for first-timeusers of an S7 programmable controller.S7-300/400 Program Design The “S7-300/400 Program Design” programming manual provides you with theProgramming Manualbasic information you require about the structure of the operating system and a userprogram for an S7 CPU. First-time users of an S7-300/400 should read this manual toget a basic overview of programming methods on which to base the design of a userprogram.S7-300/400 System andStandard FunctionsReference ManualThe S7 CPUs have system functions and organization blocks integrated in theoperating system that can be used when programming. The manual provides youwith an overview of the system functions, organization blocks and loadable standardfunctions available with an S7 programmable controller and contains detailedinterface descriptions explaining how to use the functions and blocks in your userprogram.STEP 7User ManualThe “STEP 7” User Manual explains the basic use and functions of the STEP 7automation software. Whether you are a first-time user of STEP 7 or an experiencedSTEP 5 user, the manual will provide you with an overview of the procedures forconfiguring, programming and getting started with an S7-300/400 programmablecontroller. When working with the software, you can call up the online help whichsupports you with information about specific details of the program.Converting S5 ProgramsUser ManualYou require the “Converting S5 Programs” User Manual if you want to convertexisting S5 programs and to run them on S7 CPUs. The manual explains how to usethe converter. The online help system provides more detailed information about usingthe specific converter functions. The online help system also includes an interfacedescription of the available converted S7 functions.STL, LAD, FBD, SCL1ManualsThe manuals for the language packages STL, LAD, FBD, and SCL contain bothinstructions for the user and a description of the language. To program anS7-300/400, you only require one of the languages, but you can, if required, mix thelanguages within a project. When using one of the languages for the first time, it isadvisable to familiarize yourself with the methods of creating a program as explainedin the manual.When working with the software, you can use the online help system which providesyou with detailed information about using the editors and compilers.GRAPH1 , HiGraph1,CFC1Manuals1The GRAPH, HiGraph, and CFC languages provide you with optional methods forimplementing sequential control systems, status control systems, or graphicalinterconnection of blocks. The manuals contain both the user instructions and thedescription of the language. When using one of these languages for the first time, it isadvisable to familiarize yourself with the methods of creating a program based on the“S7-300 and S7-400 Program Design” manual. When working with the software,you can also use the online help system (with the exception of HiGraph) whichprovides you with detailed information about using the editors and compilers.Optional package for system software for S7-300/S7-400Structured Control Language (SCL) for S7-300/S7-400, ProgrammingC79000-G7076-C522-01v

PrefaceHow to Use ThisManualTo use this SCL manual effectively, you should already be familiar with thetheory behind S7 programs. This is explained in the Programming Manual/234/. The language packages also use the standard software for S7, so youyou should also be familiar with the standard software as described in theUser Manual /231/.The manual is divided into the following parts:S Chapter 1 introduces you to programming with SCL.S Chapter 2 describes the design process on the basis of an example whichyou can also run.S Chapters 3 to 6 demonstrate how to use the SCL developmentenvironment. They introduce you to the SCL Editor, Compiler andDebugger.S Chapters 7 to 19 form the reference section which provides you withdetailed information about the functions of the individual SCLinstructions.The Appendix contains the following:S A complete explanation of the SCL syntax conventions.S The glossary includes definitions of the basic terms.S The index will help you to locate a topic quickly.ConventionsReferences to other manuals and documentation are indicated by numbers inslashes /./. These numbers refer to the titles of manuals listed inAppendix D.AdditionalAssistanceIf you have any questions regarding the software described in this manualand cannot find an answer here or in the online help, please contact theSiemens representative in your area. You will find a list of addresses in theAppendix of /70/ or /100/, or in catalogs, and in Compuserve (goautforum). You can also contact our Hotline under the following phone orfax number:Tel. ( 49) (911) 895–7000 (Fax 7001)If you have any questions or comments on this manual, please fill out theremarks form at the end of the manual and return it to the address shown onthe form. We would be grateful if you could also take the time to answer thequestions giving your personal opinion of the manual.Siemens also offers a number of training courses to introduce you to theSIMATIC S7 automation system. Please contact your regional training centeror the central training center in Nuremberg, Germany for details:D–90327 Nuremberg, Tel. ( 49) (911) 895–3154.Notes on Using theManualviThe user’s guide sections in this manual do not describe procedures instep-by-step detail, but simply outline basic procedures. You will find moredetailed information on the individual dialogs in the software and how to usethem in the online help.Structured Control Language (SCL) for S7-300/S7-400, ProgrammingC79000-G7076-C522-01

ContentsPart 1: Designing Programs12Product Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-11.1What is SCL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-21.2What Are the Advantages of SCL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-31.3Performance Characteristics of the Development Environment . . . . . . . . .1-5Designing SCL Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-12.1Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-22.2Defining the Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-32.32.3.12.3.22.3.32.3.42.3.5Using SCL Blocks to Perform the Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Defining the Subtasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Selecting and Assigning the Available Block Types . . . . . . . . . . . . . . . . . . .Defining the Interfaces Between the Blocks . . . . . . . . . . . . . . . . . . . . . . . . . .Defining the Input/Output Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Programming the Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-52-52-62-72-92-102.4Creating the Organization Block CYCLE . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-112.5Creating the Function Block RECORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-122.6Creating the Function Block ANALYZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-172.7Creating the Function SQUARE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-212.8Debugging Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-22Structured Control Language (SCL) for S7-300/S7-400, ProgrammingC79000-G7076-C522-01vii

ContentsPart 2: Operating and Debugging3456viiiInstalling the SCL Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-13-13.1User Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-23.2Installing / Uninstalling the SCL Software . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-4Using SCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-14.1Starting the SCL Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-24.2Customizing the User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-34.3Working with the SCL Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-5Programming with SCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-15.1Creating User Programs Using SCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-25.2Creating and Opening an SCL Source File . . . . . . . . . . . . . . . . . . . . . . . . . .5-35.3Entering Declarations, Statements and Comments . . . . . . . . . . . . . . . . . . .5-45.4Saving and Printing an SCL Source File . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-55.5The Compilation Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-65.6Transferring the Compiled User Program to the PLC . . . . . . . . . . . . . . . . . .5-95.7Creating a Compilation Control File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-10Debugging Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-16.1Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-26.2“Monitor Continuously” Debugging Function . . . . . . . . . . . . . . . . . . . . . . . . .6-36.3“Breakpoints Active” Debugging Function . . . . . . . . . . . . . . . . . . . . . . . . . . .6-56.4“Monitoring/Modifying Variables” Debugging Function . . . . . . . . . . . . . . . . .6-86.5“Reference Data” Debugging Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-96.6Using the STEP 7 Debugging Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-10Structured Control Language (SCL) for S7-300/S7-400, ProgrammingC79000-G7076-C522-01

ContentsPart 3: Language Description789General Introduction to Basic SCL Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-17.1Language Definition Aids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-27.2The SCL Character Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-47.3Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-57.4Identifiers in SCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-77.5Standard Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-87.6Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-107.7Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-127.8Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-147.9Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-167.10Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-177.11SCL Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-187.12Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-20Structure of an SCL Source File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-18.1Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Order of Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-28-28-28.2Beginning and End of a Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-48.3Block Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-58.4Declaration Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-78.5Code Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-108.6Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-118.7Structure of a Function Block (FB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-128.8Structure of a Function (FC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-148.9Structure of an Organization Block (OB) . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-168.10Structure of a Data Block (DB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-178-178.11Structure of a User-Defined Data Type (UDT) . . . . . . . . . . . . . . . . . . . . . . . .8-19Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-19.1Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-29.2Elementary Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-39.39.3.19.3.29.3.39.3.4Complex Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .DATE AND TIME Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .STRING Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .ARRAY Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .STRUCT Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-49-59-69-79-8Structured Control Language (SCL) for S7-300/S7-400, ProgrammingC79000-G7076-C522-01ix

Contents10111213x9.4User-Defined Data Type (UDT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-109.5Parameter Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-12Declaring Local Variables and Block Parameters . . . . . . . . . . . . . . . . . . . . . . . . . .10-110.1Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-210.2Declaring Variables and Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-410.3Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-510.4Instance Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-710.5Static Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-810.6Temporary Variables10-910.7Block Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-1010.8Flags (OK Flag) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-12.Declaring Constants and Jump Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-111.1Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-211.2Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-311.3Formats for Integer and Real Number Literals . . . . . . . . . . . . . . . . . . . . . . .11-411.4Formats for Character and String Literals . . . . . . . . . . . . . . . . . . . . . . . . . . .11-711.5Formats for Times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-1011.6Jump Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-14Declaring Global Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-112.1Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-212.2CPU Memory Areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-312.3Absolute Access to CPU Memory Areas . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-412.4Symbolic Access to CPU Memory Areas . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-612.5Indexed Access to CPU Memory Areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-712.6Data Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-812.7Absolute Access to Data Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-912.8Indexed Access to Data Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-1112.9Structured Access to Data Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-12Expressions, Operators and Addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13-113.1Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13-213.213.2.1Syntax of Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13-313-513.3Mathematical Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13-713.4Exponential Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13-913.5Comparative Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-10Structured Control Language (SCL) for S7-300/S7-400, ProgrammingC79000-G7076-C522-01

Contents13.614151617Logical Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-12Value Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14-114.1Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14-214.2Value Assignments Using Variables of Elementary Data Types . . . . . . . . .14-314.3Value Assignments Using Variables of the Types STRUCT or UDT . . . . .14-414.4Value Assignments Using Variables of the Type ARRAY . . . . . . . . . . . . . . .14-614.5Value Assignments Using Variables of the Type STRING . . . . . . . . . . . . . .14-814.6Value Assignments Using Variables of the Type DATE AND TIME . . . . .14-914.7Value Assignments using Absolute Variables for Memory Areas . . . . . . . . 14-1014.8Value Assignments using Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 14-11Control Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15-115.1Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15-215.2IF Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15-415.3CASE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15-615.4FOR Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15-815.5WHILE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-1015.6REPEAT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-1115.7CONTINUE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-1215.8EXIT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-1315.9GOTO Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-1415.10RETURN Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-16Calling Functions and Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16-116.1Calling and Transferring Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16-216.216.2.116.2.216.2.316.2.416.2.5Calling Function Blocks (FB or SFB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-3FB Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-5Input Assignment (FB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-7In/Out Assignment (FB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-8Example of Calling a Global Instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-10Example of Calling a Local Instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-1216.316.3.116.3.216.3.316.3.4Calling Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .FC Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Input Assignment (FC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Output and In/Out Assignment (FC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Example of a Function Call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16.4Implicitly Defined Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-2016-1316-1516-1616-1716-19Counters and Timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-117.117.1.117.1.217-217-617-7Counter Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Input and Evaluation of the Counter Reading . . . . . . . . . . . . . . . . . . . . . . . .Counter Up (CU) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Structured Control Language (SCL) for S7-300/S7-400, ProgrammingC79000-G7076-C522-01xi

Contents1819xii17.1.317.1.417.1.5Counter Down (CD) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Counter Up/Down (CUD) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Example of the Function S CD (Counter Down) . . . . . . . . . . . . . . . . . . . . . 2.617.2.717.2.8Timer Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Input and Evaluation of the Timer Reading . . . . . . . . . . . . . . . . . . . . . . . . . .Pulse Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Extended Pulse Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .On-Delay Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Retentive On-Delay Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Off-Delay Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Example of Program Using Extended Pulse Timer Function . . . . .

STL, LAD, FBD, SCL1 Manuals The manuals for the language packages STL, LAD, FBD, and SCL contain both instructions for the user and a description of the language. To program an S7-300/400, you only require one of the languages, but you can, if required, mix the languages within a project. When using one of the languages for the first time, it is