摘自STEP_7_WinCC_V15_1_enUS_en-US 12 Programming the PLC 1.2 Blocks in the user program
1.1 Operating system and user program
The following figure shows the interaction of the operating system and the user program:
Operating system (OS)
The tasks of the operating system, for example, include the following:
● Processing a warm restart
● Updating the process image of the inputs and outputs
● Calling the user program
● Detecting interrupts and calling interrupt OBs
● Detecting and handling errors
● Managing memory areas
1.2 Blocks in the user program
Organization blocks (OB)
Organization blocks (OBs) form the interface between the operating system and the user program. They are called by the operating system and control, for example, the following operations:
● Startup characteristics of the automation system
● Cyclic program processing
● Interrupt-driven program execution
● Error handling
You can program the organization blocks and at the same time determine the behavior of the CPU.
When certain organization blocks are started, the operating system provides information that can be evaluated in the user program.
Functions (FCs)
Functions (FCs) are code blocks without memory. You have no data memory in which values of block parameters can be stored. Therefore, when a function is called, all formal parameters must be assigned actual parameters.
Functions can use global data blocks to store data permanently.
A function contains a program that is executed when the function is called by another code block. Functions can be used, for example, for the following purposes:
● To return function values to the calling block, e.g. for mathematical functions
● To execute technological functions, e.g. individual controls using bit logic operations
A function can also be called several times at different points in a program. As a result, they simplify programming of frequently recurring functions.
Function blocks (FB)
Function blocks are code blocks that store their input, output and in-out parameters permanently in instance data blocks, so that they remain available even after the block has been executed. Therefore they are also referred to as blocks "with memory".
Function blocks can also operate with temporary tags. Temporary tags are will not be stored in the instance DB, but are available for one cycle only.
A call of a function block is referred to as an instance. An instance data block is required for each instance of a function block; it contains instance-specific values for the formal parameters declared in the function block.
The function block can store its instance-specific data in its own i