Addressing Overview (GS 2.2)
Understanding Absolute and Symbolic Addresses
You can identify the operands of the instructions in your program absolutely or symbolically. An absolute reference uses the memory area and bit or byte location to identify the address. A symbolic reference uses a combination of alphanumeric characters to identify the address.
SIMATIC programmers are much more likely to use absolute addresses than IEC programmers; however, STEP 7-Micro/WIN 32 does support absolute addressing for the IEC editor.
Examples Of How The Program Editor Displays Addresses
|I0.0||Absolute address is designated by memory area and address number (SIMATIC program editor)|
|%I0.0||Percent sign precedes an absolute address in IEC (IEC program editor)|
|#INPUT1||Pound symbol precedes a local variable (SIMATIC or IEC program editor)|
|INPUT1||Global symbol name (SIMATIC or IEC program editor)|
|??.? or ????||Red question marks indicate an undefined address (must be defined before program is compiled)|
Global versus Local Scope
Symbolic values assigned in the Symbol Table (Global Variable Table) have global scope. Symbolic values assigned in a Local Variable Table have local scope.
Global symbols can be used in both SIMATIC and IEC program editors.
In SIMATIC programs, you make global symbol assignments by using the Symbol Table. In IEC programs, you make global symbol assignments by using the Global Variable Table. You do not have to make symbol assignments before you use symbols in your program; you can make symbol assignments at any time.
Local variables can be used in both SIMATIC and IEC program editors.
Local variables are assigned in the Local Variable Table of the respective (POU), and are limited in scope to the POU where they were created. Each POU has its own separate Local Variable Table.
You define a variable called INPUT1 in the Local Variable Table of a subroutine called SBR1.
When you refer to INPUT1 from within SBR1, the program editor recognizes it as a local variable of SBR1.
However, if you refer to INPUT1 from elsewhere in the program (for instance, from OB1 or from a second subroutine), the program editor does not recognize it as a local variable (because it is outside of SBR1) and treats INPUT1 as an undefined global symbol.
·If you use the same name for an address at the local and global level, the local use takes precedence. In other words, if the program editor finds a definition for the name in the Local Variable Table for a given program block, that definition is used. If no definition is found, the program editor then checks the Symbol Table/ Global Variable Table.
You define PumpOn as a global symbol. You also define it as a local variable in SBR2, but not SBR1.
When the program is compiled, the local definition is used for PumpOn in SBR2; the global definition is used for PumpOn in SBR1.
·Local variables use temporary PLC L memory, rather than requiring PLC program memory space. Subroutines that use only local variable parameters, or no parameters at all, are portable and can be reused in more than one program. You are not required to use local variables. It is an option for advanced programming techniques. If you want to use a parameter in several POUs , it may make more sense to define it as a global symbol in the Symbol Table/Global Variable Table than to define it as a local variable, because you would have to make separate assignments to the Local Variable Table of each POU.
·Because local variables use temporary memory, be sure that you initialize your local variables within the POU each time the POU is called. You cannot be sure that the local variable will retain a data value from one iteration to the next.
Hardware Support for the Local Variable Table
The Local Variable Table feature of STEP 7-Micro/WIN 32 requires hardware support. You must have a CPU 221, CPU 222, CPU 224, CPU 226, or CPU 226XM to make use of the Local Variable Table.
Direct and Indirect Addressing
Select Mnemonic Set
How to Enter Addresses in LAD (GS 3.5)
How to Enter Addresses in FBD (GS 4.5)
How to Enter a Statement in STL (GS 5.2)