Professional Documents
Culture Documents
INDUSTRIAL AUTOMATION
TRAINING
SIEMENS
S7-300 PROGRAMMING
IN STATEMENT LIST
PAGE 1
CONTENTS:
PAGE NO
1. STEP7 OVERVIEW
3. ADDRESSING OF MODULES
12
13
6. DATA TYPES
14
16
23
9. COMPARISON INSTRUCTIONS
27
29
38
45
48
49
51
54
56
58
71
73
75
22. GLOSSARY
86
PAGE 2
SIMATIC S7
PLC
RANGE
S7-400
S7-300
S7-200
SIMATIC S7-300 COMPONENTS
S.No.
COMPONENT
FUNCTION
1.
Rail
2.
3.
CPU
4.
Signal Modules(SM)DI,DO,AI,AO
5.
6.
Communication Processor
(CP)
7.
Interface Module(IM)
8.
9.
Programmer Cable
10.
RS 485 Repeater
Interfaces the S7-300 over large distances to other S7300s or programming devices
PAGE 3
Overview of STEP 7
What is STEP 7?
STEP 7 is the standard software package used for configuring and programming
SIMATIC programmable logic controllers. It is part of the SIMATIC industry software.
Basic Tasks
When you create an automation solution with STEP 7, there are a series of basic tasks. The following
figure shows the tasks that need to be performed for most projects and assigns them to a basic
procedure.
Alternative Procedures
As shown in the figure above, you have two alternative procedures:
You can configure the hardware first and then program the blocks.
You can, however, program the blocks first without configuring the hardware. This is
recommended for service and maintenance work, for example, to integrate programmed
blocks into in an existing project.
PAGE 4
PAGE 6
COMPARISON OF CPU'S
CPU's
CPU312IFM
Mem Statement/Bytes
Memory Cards
2K/6KB
-
CPU313
CPU314IFM
CPU314
8K/24KB
-
0.6 ms
4K/12KB
512KB
FEPROM
0.6 ms
0.3 ms
16K/48KB
512KB
FEPROM
0.3 ms
256
64
1-Tier
8
1024
32
64
Yes
256
64
1-Tier
8
2048
32
64
Yes
1024
256
4-Tier
31
2048
64
72
Yes
1024
256
4-Tier
31
2048
64
128
Yes
10DI/6DQ
onboard. int.
functions:Count
ers/Freq.
Measuremensts
20DI/16DQ
,4AI,1AO
onboard. int.
functions:Co
unters/Freq.
Measuremen
sts/Positionin
g PID Control
CPU's
CPU315
CPU315-2DP
CPU316-2DP
CPU318-2
Mem Statement/Bytes
Memory Cards
16K/48KB
512KB FEPROM
0.3 ms
42K/128KB
4MB
FEPROM
0.3 ms
256KB
4MB FEPROM
16K/48KB
512KB
FEPROM
0.3 ms
1024
256
4-Tier
32
2048
64
128
Yes
2048
256
4-Tier
32
2048
64
128
Yes
4096
256
4-Tier
32
2048
64
128
Yes
16384
1024
4-Tier
32
8192
512
512
Upto 12Mbaud
PROFIBUSDP
Master/Slave
(64 DP
stations,12M
baud)
PROFIBUSDP
Master/Slave
(64 DP
stations,12M
baud)
PROFIBUS-DP
Master/Slave
(125 DP
stations,12Mb
aud)
0.1 ms
PAGE 7
DIGITAL INPUTS
16 X 24 VDC
8 X 120 / 230 VAC
16 X 120 V AC
32 X 24 V DC
DIGITAL OUTPUTS
16 x 24 VDC ,0.5A
8 X 24 VDC ,2A
8 X 120 / 230 VAC, 2A
16 X 120 VAC, 1A
32 X 24 V DC, 0.5A
RELAY OUTPUTS
DI/DO MODULES
2. FUNCTION MODULES
High Speed Counter Modules - Upto 100 KHz range
Positioning Modules - For position control, Stepper Motor Control, Cam Controllers
All function modules are enclosed and can be installed in any slot.
3. COMMUNICATION PROCESSORS - FOR DATA EXCHANGE WITH PRINTERS,COMPUTERS,
SIMATIC SYSTEMS
CP340 - Point to Point Communication for the serial link with RS232, 3964R and any ASCII
protocol
4. INTERFACE MODULES - FOR MULTI TIER CONFIGURATION
For Central Controller Expansion
For Expansion Unit Connection
5. POWER SUPPLY MODULES - FOR 24 VDC LOAD CIRCUITS WITH DIFFERENT RATINGS.
ADDRESSING OF MODULES
RACK 0
PS
CPU
10
11
Digital Address
12
16
20
24
28
Analog Address
256
272
288
304
320
336
352
368
Slot Number
IM
AI / AO / DI / DO Modules
10
11
Digital Address
64
32
36
40
44
48
52
56
60
Analog Address
512
384
400
416
432
448
464
480
496
RACK 1
Slot Number
PAGE 9
RACK 2
10
11
Digital Address
64
68
72
76
80
84
88
92
Analog Address
512
528
544
560
576
592
608
624
Slot Number
AI / AO / DI / DO Modules
RACK 3
10
11
Digital Address
64
96
100
104
108
112
116
120
124
Analog Address
512
640
656
672
688
704
720
736
752
Slot Number
PAGE 10
Rack 3
Slot Number
IM
10
11
64
512
Rack 2
Slot Number
IM
10
11
Connecting
cable 368
64
512
Rack 1
Slot Number
IM
10
11
Connecting
cable 368
64
512
Rack 0
PS
Slot Number 1
CPU
2 (IM) 3
10
11
PAGE 11
PAGE 12
Block
SFBs and SFCs are integrated in the S7 CPU and allow you
access to some important system functions.
FBs are blocks with a "memory" which you can program yourself.
Functions (FC)
DBs are data areas for storing user data. In addition to the data
that are assigned to a function block, shared data can also be
defined and used by any blocks.
OBs, FBs, SFBs, FCs, and SFCs contain sections of the program and are therefore also known as
logic blocks. The permitted number of blocks per block type and the permitted length of the blocks is
CPU-specific.
PAGE 13
DATA TYPES
Introduction to Data Types and Parameter Types
All the data in a user program must be identified by a data type. The following data types are
available:
Elementary data types provided by STEP 7
Complex data types that you yourself can create by combining elementary data types
Parameter types with which you define parameters to be transferred to FBs or FCs
General Information
Statement List, Ladder Logic, and Function Block Diagram instructions work with data objects of
specific sizes. Bit logic instructions work with bits, for example. Load and transfer instructions (STL)
and move instructions (LAD and FBD) work with bytes, words, and double words.
A bit is a binary digit "0" or "1." A byte is made up of eight bits, a word of 16 bits, and a double word of
32 bits.
Math instructions also work with bytes, words, or double words. In these byte, word, or double word
addresses you can code numbers of various formats such as integers and floating-point numbers.
When you use symbolic addressing, you define symbols and specify a data type for these symbols
(see table below). Different data types have different format options and number notations.
This chapter describes only some of the ways of writing numbers and constants. The following table
lists the formats of numbers and constants that will not be explained in detail.
Format
Size in Bits
Number Notation
Hexadecimal
8, 16, and 32
Binary
8, 16, and 32
2#
date
16
D#
time
32
T#
Time of day
32
TOD#
Character
'A'
BYTE
(Byte)
Boolean text
Hexadecimal number
TRUE/FALSE
TRUE
B16#0 to B16#FF
L B#16#10
L byte#16#10
L 2#0001_0000_0000_0000
2. 0 to
2#1111_1111_1111_1111
L W#16#1000
Hexadecimal number
W#16#0 to W#16#FFFF
L word16#1000
L C#998
BCD
C#0 to C#999
L B#(10,20)
Decimal number unsigned B#(0.0) to B#(255.255)
L byte#(10,20)
Binary number
WORD
(Word)
16
Binary number
DWORD
(Double word)
32
Hexadecimal number
2#0 to
2#1111_1111_1111_1111
1111_1111_1111_1111
DW#16#0000_0000 to
DW#16#FFFF_FFFF
2#1000_0001_0001_1000_
1011_1011_0111_1111
L DW#16#00A2_1234
L dword#16#00A2_1234
PAGE 14
16
-32768 to 32767
L1
DINT
32
(Integer, 32 bits)
L#-2147483648 to
L#2147483647
L L#1
REAL
(Floating-point
number)
32
IEEE
Floating-point number
16
S7 time in
steps of
10 ms (default)
S5T#0H_0M_0S_10MS to
S5T#2H_46M_30S_0MS
and
S5T#0H_0M_0S_0MS
INT
(Integer)
S5TIME
(SIMATIC time)
L S5T#0H_1M_0S_0MS
L
S5TIME#0H_1H_1M_0S_0
MS
TIME
(IEC time)
32
T#24D_20H_31M_23S_64 L T#0D_1H_1M_0S_0MS
8MS to
L
T#24D_20H_31M_23S_64 TIME#0D_1H_1M_0S_0MS
7MS
DATE
(IEC date)
16
D#1990-1-1 to
D#2168-12-31
L D#1996-3-15
L DATE#1996-3-15
TIME_OF_DAY
(Time)
32
Time in steps of 1 ms
TOD#0:0:0.0 to
TOD#23:59:59.999
L TOD#1:10:3.3
L TIME_OF_DAY#1:10:3.3
CHAR
(Character)
ASCII characters
'A','B' etc.
L 'E'
Parameter Types
In addition to elementary and complex data types, you can also define parameter types for formal
parameters that are transferred between blocks. STEP 7 recognizes the following parameter types:
TIMER or COUNTER: this specifies a particular timer or particular counter that will be used
when the block is executed. If you supply a value to a formal parameter of the TIMER or
COUNTER parameter type, the corresponding actual parameter must be a timer or a counter,
in other words, you enter "T" or "C" followed by a positive integer.
BLOCK: specifies a particular block to be used as an input or output. The declaration of the
parameter determines the block type to be used (FB, FC, DB etc.). If you supply values to a
formal parameter of the BLOCK parameter type, specify a block address as the actual
parameter. Example: FC101" (when using absolute addressing) or Valve" (with symbolic
addressing).
Parameter
TIMER
COUNTER
Capacity
Description
BLOCK_FB
BLOCK_FC
2 bytes
BLOCK_DB
BLOCK_SDB
PAGE 16
PAGE 17
PAGE 18
PAGE 19
PAGE 20
PAGE 21
PAGE 22
Nesting Closed
Assign
And
And with Nesting Open
And Not
And Not with Nesting Open
Edge Negative
Edge Positive
Or
And before Or
Or with Nesting Open
Or Not
Or Not with Nesting Open
Reset
Set
PAGE 23
PAGE 24
PAGE 25
PAGE 26
Comparison Instructions
PAGE 27
PAGE 28
Conversion Instructions
PAGE 29
BTD
BCD to Double Integer (32-Bit)
Example:
L
MD10
Load the BCD number into ACCU 1.
BTD
Convert from BCD to integer; store result in ACCU 1.
T
MD20
Transfer result (double integer number) to MD20.
BTI
BCD to Integer (16-Bit)
Example:
L
MW10
Load the BCD number into ACCU 1-L.
BTI
Convert from BCD to integer; store result in ACCU 1-L.
T
MW20
Transfer result (integer number) to MW20.
CAD
Change Byte Sequence in ACCU 1 (32-Bit)
Example:
L
MD10
Load the value of MD10 into ACCU 1.
CAD
Reverse the sequence of bytes in ACCU 1.
T
MD20
Transfer the results to MD20.
Contents of ACCU 1 before execution of CAD:
ACCU 1-H-H: ACCU 1-H-L: ACCU 1-L-H:
value "A"
value "B"
value "C"
ACCU 1-L-L:
value "D"
ACCU 1-L-L:
value "A"
PAGE 30
CAW
Change Byte Sequence in ACCU 1-L (16-Bit)
Example:
L
MW10
Load the value of MW10 into ACCU 1.
CAW
Reverse the sequence of bytes in ACCU 1-L.
T
MW20
Transfer the result to MW20.
Contents of ACCU 1 before execution of CAW:
ACCU 1-H-H:
value "A"
ACCU 1-H-L:
value "B"
ACCU 1-L-H:
value "C"
ACCU 1-L-L:
value "D"
ACCU 1-L-L:
value "C"
DTB
Double Integer (32-Bit) to BCD
Example:
L
MD10
Load the 32-bit integer into ACCU 1.
DTB
Convert from integer (32-bit) to BCD, store result in ACCU 1.
T
MD20
Transfer result (BCD number) to MD20.
DTR
Example:
L
DTR
MD10
MD20
INVD
Example:
Bit
16
15
Contents of ACCU 1
before execution of INVD
0110
1111
1000
1100
0110
0011
1010
1110
Contents of ACCU 1
after execution of INVD
1001
0000
0111
0011
1001
1100
0101
0001
0011
1100
1010
0101
1110
0001
L
INVD
T
ID8
MD10
INVI
Ones Complement Integer (16-Bit)
Example:
Bit
15
Contents of ACCU 1-L before execution of INVI 0110
Contents of ACCU 1-L after execution of INVI 1001
L
INVI
T
IW8
MW10
PAGE 32
ITB
Integer (16-Bit) to BCD
Example:
L
MW10
Load the integer number into ACCU 1-L.
ITB
Convert from integer to BCD (16-bit); store result in ACCU 1-L.
T
MW20
Transfer result (BCD number) to MW20.
ITD
Integer (16-Bit) to Double Integer (32-Bit)
Example:
L
MW12
Load the integer number into ACCU 1.
ITD
Convert from integer (16-bit) to double integer (32-bit); store result in
ACCU 1.
T
MD20
Transfer result (double integer) to MD20.
Bit:
ACCU 1-H
31
XXXX
1111
XXXX
1111
ACCU 1-L
16 : 15
XXXX
1111
XXXX
1111
1111
1111
1111
1111
0
1111
1111
0110
0110
NEGD
Example:
31
0101
1010
L
ID8
NEGD
T
MD10
.0
1111
0000
IW8
MW10
0110
1001
0100
1011
0101
1010
0011
1100
0
1000
1000
1101
0010
0011
1100
1000
1000
NEGI
Twos Complement Integer (16-Bit)
Example:
Bit
15
Contents of ACCU 1-L before execution of NEGI 0101
Contents of ACCU 1-L after execution of NEGI 1010
L
NEGI
T
ACCU 1-L
1101
0010
NEGR
Negate Floating-Point Number (32-Bit, IEEE-FP)
Example:
L
ID8
Load value into ACCU 1 (example: ID 8 = 1.5E+02).
NEGR
Negate floating-point number (32-bit, IEEE-FP); stores the result in ACCU 1.
T
MD10
Transfer result to MD10 (example: result = -1.5E+02).
PAGE 34
RND
Round
Example:
L
MD10
Load the floating-point number into ACCU 1-L.
RND
Convert the floating-point number (32-bit, IEEE-FP) into an integer (32-bit)
and
round off the result.
T
MD20
Transfer result (double integer number) to MD20.
Value before conversion:
Value after conversion:
MD10 = "100.5"
=> RND => MD20 = "+100"
MD10 = "-100.5"
=> RND => MD20 = "-100"
PAGE 35
RND+
Round to Upper Double Integer
Example:
L
MD10
Load the floating-point number (32-bit, IEEE-FP) into ACCU 1-L.
RND+
Convert the floating-point number (32-bit, IEEE-FP) to an integer (32-bit) and
round
result.Store output in ACCU 1.
T
MD20
Transfer result (double integer number) to MD20.
Value before conversion:
Value after conversion:
MD10 = "100.5"
=> RND+ => MD20 = "+101"
MD10 = "-100.5"
=> RND+ => MD20 = "-100"
TRUNC
Truncate
Example:
L
MD10
Load the floating-point number into ACCU 1-L.
TRUNC
Convert the floating-point number (32-bit, IEEE-FP) to an integer (32-bit) and
round
result.Store the result in ACCU 1.
T
MD20
Transfer result (double integer number) to MD20.
Value before conversion:
Value after conversion:
MD10 = "100.5"
=> TRUNC =>
MD20 = "+100"
MD10 = "-100.5"
=> TRUNC =>
MD20 = "-100"
PAGE 37
Counter Instructions
PAGE 38
PAGE 39
PAGE 40
PAGE 41
PAGE 42
PAGE 43
CD
Example:
L
C#14
A
I 0.1
S
C1
A
I 0.0
CD
C1
input
AN
=
C1
Q 0.0
Counter Down
Counter preset value.
Preset counter after detection of rising edge of I 0.1.
Load counter 1 preset if enabled.
One count down per rising edge of I 0.0.
Decrement counter C1 by 1 when RL0 transitions from 0 to 1 depending on
I 0.0.
Zero detection using the C1 bit.
Q 0.0 = 1 if counter 1 value is zero.
CU
Example:
A
I 2.1
CU
C3
Counter Up
L
Example:
L
C3
LC
Example:
LC
C3
format.
R
Example:
A
I 2.3
R
C3
Reset Counter
S
Example:
A
I 2.3
L
C#3
S
C1
Load ACCU 1-L with the count value of counter C3 in binary format.
Load ACCU 1-L with the count value of counter C3 in binary coded decimal
PAGE 44
DB10
DBW35
MW22
DI20
DIB12
DBB37
JCB
Example:
A
A
JCB
L
T
JOVR: A
JCN
Example:
A
A
JCN
L
T
JOVR: A
JM
Example:
L
L
-I
JM
AN
S
JU
Jump if RLO = 1
I 1.0
I 1.2
JOVR Jump if RLO=1 to jump label JOVR.
IW8
Program scan continues here if jump is not executed.
MW22
I 2.1
Program scan resumes here after jump to jump label JOVR.
Jump if RLO = 0
I 1.0
I 1.2
JOVR Jump if RLO = 0 to jump label JOVR.
IW8
Program scan continues here if jump is not executed.
MW22
I 2.1
Program scan resumes here after jump to jump label JOVR.
Jump if Minus
IW8
MW12
//Subtract contents of MW12 from contents of IW8.
NEG //Jump if result < 0 (that is, contents of ACCU 1 < 0).
M 4.0 //Program scan continues here if jump is not executed.
M 4.0
NEXT
PAGE 45
NEG:
AN
M 4.1
S
M 4.1
NEXT: NOP 0
JMZ
Jump if Minus or Zero
Example:
L
IW8
L
MW12
-I
Subtract contents of MW12 from contents of IW8.
JMZ
RGE0
Jump if result <=0 (that is, contents of ACCU 1 <= 0).
AN
M 4.0
Program scan continues here if jump is not executed.
S
M 4.0
JU
NEXT
RGE0: AN
M 4.1 Program scan resumes here after jump to jump label RGE0.
S
M 4.1
NEXT: NOP 0
Program scan resumes here after jump to jump label NEXT.
JN
Example:
L
L
XOW
JN
AN
S
JU
NOZE: AN
S
NEXT: NOP 0
JP
Example:
L
L
-I
JP
AN
S
JU
POS: AN
S
NEXT: NOP 0
JPZ
Example:
L
L
-I
JPZ
AN
S
JU
REG0: AN
Jump if Plus
IW8
MW12
Subtract contents of MW12 from contents of IW8.
POS Jump if result >0 (that is, ACCU 1 > 0).
M 4.0 Program scan continues here if jump is not executed.
M 4.0
NEXT
M 4.1 Program scan resumes here after jump to jump label POS.
M 4.1
Program scan resumes here after jump to jump label NEXT.
S
M 4.1
NEXT: NOP 0
JU
Example:
A
A
JC
L
INC
T
JU
DELE: L
T
FORW: A
Jump Unconditional
I 1.0
I 1.2
DELE Jump if RLO=1 to jump label DELE.
MB10
1
MB10
FORW Jump unconditionally to jump label FORW.
0
MB10
I 2.1
Program scan resumes here after jump to jump label FORW.
JUO
Example:
L
L
/D
JUO
T
A
R
JU
ERRO: AN
S
NEXT: NOP 0
Jump if Unordered
JZ
Example:
L
SRW
JZ
L
INC
T
JU
ZERO: L
INC
T
NEXT: NOP 0
Jump if Zero
MD10
ID2
Divide contents of MD10 by contents of ID2.
ERRO Jump if division by zero (that is, ID2 = 0).
MD14 Program scan continues here if jump is not executed.
M 4.0
M 4.0
NEXT
M 4.0 Program scan resumes here after jump to jump label ERRO.
M 4.0
Program scan resumes here after jump to jump label NEXT.
MW10
1
ZERO Jump to jump label ZERO if bit that has been shifted out = 0.
MW2 Program scan continues here if jump is not executed.
1
MW2
NEXT
MW4 Program scan resumes here after jump to jump label ZERO.
1
MW4
Program scan resumes here after jump to jump label NEXT.
LOOP
Loop
Example for calculating the factor of 5:
L
L#1
Load the integer constant (32 bit) into ACCU 1.
T
MD20 Transfer the contents from ACCU 1 into MD20 (initialization).
L
5
Load number of loop cycles into ACCU 1-L.
NEXT: T
MW10 Jump label = loop start / transfer ACCU 1-L to loop counter.
L
MD20
*
D
Multiply current contents of MD20 by the current contents of MB10.
T
MD20 Transfer the multiplication result to MD20.
L
MW10 Load contents of loop counter into ACCU 1.
LOOP
NEXT
Decr. the contents of ACCU 1 and jump to the NEXT jump label if ACCU 1-L > 0.
PAGE 47
L
L
>I
T
Transfer
T <address> transfers (copies) the contents of ACCU 1 to the destination address if the Master
Control Relay is switched on (MCR = 1). If MCR = 0, then the destination address is written with 0.
The number of bytes copied from ACCU 1 depends on the size expressed in the destination address.
ACCU 1 also saves the data after the transfer procedure. A transfer to the direct I/O area (memory
type PQ) also transfers the contents of ACCU 1 or "0" (if MCR=0) to the corresponding address of the
process image output table (memory type Q). The instruction is executed without regard to, and
without affecting, the status bits.
Example:
T
QB10
T
MW14
T
DBD2
PAGE 48
+R
Add ACCU 1 and ACCU 2 as a Floating Point Number (32-Bit IEEE-FP)
Example:
OPN DB10
L
ID10
Load the value of ID10 into ACCU 1.
L
MD14
Load the value of ACCU 1 into ACCU 2.Load the value of MD14 into
ACCU 1.
+R
Add ACCU 2 and ACCU 1; store the result in ACCU 1.
T
DBD25
The content of ACCU 1 (result) is transferred to DBD25 in DB10.
-R
Example:
OPN DB10
L
ID10
L
MD14
ACCU 1.
-R
T
DBD25
/R
Divide ACCU 2 by ACCU 1 as a Floating Point Number (32-Bit IEEE-FP)
Example:
OPN DB10
L
ID10
Load the value of ID10 into ACCU 1.
L
MD14
Load the contents of ACCU 1 into ACCU 2.Load the value of MD14 into
ACCU 1.
/R
Divide ACCU 2 by ACCU 1; store the result in ACCU 1.
T
DBD20
The content of ACCU 1 (result) is transferred to DBD20 in DB10.
ABS
Absolute Value of a Floating Point Number (32-Bit IEEE-FP)
Example:
L
ID8
Load value into ACCU 1 (example: ID8 = -1.5E+02).
ABS
Form the absolute value; store the result in ACCU 1.
T
MD10
Transfer result to MD10 (example: result = 1.5E+02).
PAGE 49
PAGE 50
25
DB1.DBW25
Example 2:
L
IW12
L
IW14
+
100
>I
JC
NEXT
Example 3:
L
MD20
L
MD24
+D
+
L#-200
T
MD28
Add ACCU 1-L and 100; store the result in ACCU 1-L.
If ACCU 2 > ACCU 1, or IW12 > (IW14 + 100)
then conditional jump to jump label NEXT.
+D
Add ACCU 1 and ACCU 2 as Double Integer (32-Bit)
Example:
L
ID10
Load the value of ID10 into ACCU 1.
L
MD14
Load the contents of ACCU 1 to ACCU 2.Load the value of MD14 into
ACCU 1.
+D
Add ACCU 2 and ACCU 1; store the result in ACCU 1.
T
DB1.DBD25
The contents of ACCU 1 (result) are transferred to DBD25 of DB1.
-D
Example:
L
ID10
L
MD14
ACCU 1.
-D
T
DB1.DBD25
Load the contents of ACCU 1 into ACCU 2.Load the value of MD14 into
*D
Example:
L
ID10
L
MD14
*D
T
DB1.DBD25
/D
Divide ACCU 2 by ACCU 1 as Double Integer (32-Bit)
Example:
L
ID10
Load the value of ID10 into ACCU 1.
L
MD14
Load the contents of ACCU 1 into ACCU 2.Load the value of MD14 into
ACCU 1.
/D
Divide ACCU 2 by ACCU 1; store the result (quotient) in ACCU 1.
T
MD20
The contents of ACCU 1 (result) are transferred to MD20.
Example above: 13 divided by 4
Contents of ACCU 2 before instruction (ID10):
Contents of ACCU 1 before instruction (MD14):
Instruction /D (ACCU 2 / ACCU 1)
Contents of ACCU 1 after instruction (quotient):
"13"
"4"
:
"3"
"13/4"
+I
Add ACCU 1 and ACCU 2 as Integer (16-Bit)
Example:
L
IW10
Load the value of IW10 into ACCU 1-L.
L
MW14
Load the contents of ACCU 1-L into ACCU 2-L.Load the value of MW14 into
ACCU 1-L.
+I
Add ACCU 2-L and ACCU 1-L; store the result in ACCU 1-L.
T
DB1.DBW25
The contents of ACCU 1-L (result) are transferred to DBW25 of DB1.
-I
Subtract ACCU 1 from ACCU 2 as Integer (16-Bit)
Example:
L
IW10
Load the value of IW10 into ACCU 1-L.
L
MW14
Load the contents of ACCU 1-L into ACCU 2-L.Load the value of MW14 into
ACCU 1-L.
-I
Subtract ACCU 1-L from ACCU 2-L; store the result in ACCU 1-L.
T
DB1.DBW25
The contents of ACCU 1-L (result) are transferred to DBW25 of DB1.
*I
Multiply ACCU 1 and ACCU 2 as Integer (16-Bit)
Example:
L
IW10
Load the value of IW10 into ACCU 1-L.
L
MW14
Load contents of ACCU 1-L into ACCU 2-L.Load contents of MW14 into
ACCU 1L.
*I
Multiply ACCU 2-L and ACCU 1-L, store result in ACCU 1.
T
DB1.DBD25
The contents of ACCU 1 (result) are transferred to DBW25 in DB1.
PAGE 52
/I
Example:
L
L
IW10
MW14
/I
quotient,
MOD
Division Remainder Double Integer (32-Bit)
Example:
L
ID10
Load the value of ID10 into ACCU 1.
L
MD14
Load the contents of ACCU 1 into ACCU 2.Load the value of MD14 into
ACCU 1.
MOD
Divide ACCU 2 by ACCU 1, store the result (remainder) in ACCU 1.
T
MD20
The contents of ACCU 1 (result) are transferred to MD20.
Example above : 13 divided by 4
Contents of ACCU 2 before instruction (ID10): "13"
Contents of ACCU 1 before instruction (MD14): "4"
Instruction MOD (ACCU 2 / ACCU 1):
"13/4"
Contents of ACCU 1 after instruction (remainder):
"3"
PAGE 53
BEC
Block End Conditional
If RLO = 1, then BEC (block end conditional) interrupts the program scan in the current block and
causes a jump to the block that called the current block.
Example:
A
I 1.0
BEC
L
IW4
T
MW10
Update RLO.
End block if RLO = 1.
Continue here if BEC is not executed, RLO = 0.
BEU
Block End Unconditional
BEU (block end unconditional) terminates the program scan in the current block and causes a jump to
the block that called the current block. The program scan resumes with the first instruction that follows
the block call.
Example:
A
I 1.0
JC
NEXT
Jump to NEXT jump label if RLO = 1 (I 1.0 = 1).
L
IW4
Continue here if no jump is executed.
T
IW10
A
I 6.0
A
I 6.1
S
M 12.0
BEU
Block end unconditional.
NEXT: NOP 0
Continue here if jump is executed.
CALL
Block Call
CALL <logic block identifier> is used to call functions (FCs) or function blocks (FBs), system functions
(SFCs) or system function blocks (SFBs) you created yourself or to call the standard pre-programmed
blocks shipped by Siemens. The CALL instruction calls the FC and SFC or the FB and SFB that you
input as an address, independent of the RLO or any other condition.
Example: CALL FB1, DB1 or CALL FILLVAT1, RECIPE1
Logic Block
FC
SFC
FB
SFB
Block Type
Function
System function
Function block
System function block
CALL
CC
Conditional Call
CC <logic block identifier> (conditional block call) calls a logic block if RLO=1. CC is used to call logic
blocks of the FC or SFC type without parameters.
Example:
A
I 2.0
Check signal state at input I 2.0.
CC
FC6
Call function FC6 if I 2.0 is "1".
A
M 3.0
Executed upon return from called function (I 2.0 = 1) or directly after A I 2.0
statement if I 2.0 = 0.
UC
Unconditional Call
UC <logic block identifier> (unconditional block call) calls a logic block of the FC or SFC type. UC is
like the CALL instruction, except that you cannot transfer parameters with the called block.
Example 1:
UC
FC6
Example 2:
UC
SFC43 Call system function SFC43 (without parameters).
PAGE 55
Shift Instructions
SLD
Shift Left Double Word (32-Bit)
SLD <number>: The number of shifts is specified by the address <number>. The permissible value
range is from 0 to 32. The status word bits CC 0 and OV are reset to zero if <number> is greater than
zero. If <number> is equal to zero, then the shift instruction is regarded as a NOP operation.
Examples:
ACCU 1-H
Bit:
31
ACCU 1 before execution of SLD 5: 0101
ACCU 1 after execution of SLD 5: 1110
Example 1:
L
MD4
SLD
5
T
MD8
1111
1100
0110
1000
ACCU 1-L
16
0100
1011
15
0101
1010
1101
0111
0011
0110
0
1011
0000
SLW
Shift Left Word (16-Bit)
SLW <number>: The number of shifts is specified by the address <number>. The permissible value
range is from 0 to 15. The status word bits CC 0 and OV are reset to zero if <number> is greater than
zero. If <number> is equal to zero, then the shift instruction is regarded as a NOP operation.
Examples:
ACCU 1-H
Bit:
31
0101
0101
Example 1:
L
MW4
SLW 5
T
MW8
1111
1111
0110
0110
ACCU 1-L
16
15
0100
0100
0101
1010
0
1101
0111
0011
0110
1011
0000
SRD
Shift Right Double Word (32-Bit)
SRD <number>: The number of shifts is specified by the address <number>. The permissible value
range is from 0 to 32. The status word bits CC 0 and OV are reset to 0 if <number> is greater thnan
zero.
Examples:
ACCU 1-H
ACCU 1-L
Bit:
31
ACCU 1 before execution of SRD 7: 0101
ACCU 1 after execution of SRD 7: 0000
Example 1:
L
MD4
SRD 7
T
MD8
1111
0000
0110
1011
16
0100
1110
15
0101
1100
1101
1000
0011
1011
0
1011
1010
SRW
Shift Right Word (16-Bit)
SRW <number>: The number of shifts is specified by the address <number>. The permissible value
range is from 0 to 15. The status word bits CC 0 and OV are reset to 0 if <number> is greater than
zero.
Examples:
ACCU 1-H
ACCU 1-L
Bit:
31
16
15
PAGE 56
Example 1:
L
MW4
SRW 6
T
MW8
0101
1111
0110
1111
0110
0100
0100
0000
0101
1101
0001
0111
PAGE 57
Timer Instructions
PAGE 58
SD
On-Delay Timer
SD <timer> starts the addressed timer when the RLO transitions from "0" to "1". The programmed
time interval elapses as long as RLO = 1. The time is stopped if RLO transitions to "0" before the
programmed time interval has expired. This timer start instruction expects the time value and the time
base to be stored as a BCD number in ACCU 1-L.
Example:
A
I 2.1
L
S5T#10s
SD
T1
PAGE 59
PAGE 60
SE
Extended Pulse Timer
SE <timer> starts the addressed timer when the RLO transitions from "0" to "1". The programmed
time interval elapses, even if the RLO transitions to "0" in the meantime. The programmed time
interval is started again if RLO transitions from "0" to "1" before the programmed time has expired.
This timer start command expects the time value and the time base to be stored as a BCD number in
ACCU 1-L.
Example:
A
I 2.1
L
S5T#10s
Preset 10 seconds into ACCU 1.
SE
T1
Start timer T1 as an extended pulse timer.
A
I 2.2
R
T1
Reset timer T1.
A
T1
Check signal state of timer T1.
=
Q 4.0
PAGE 61
PAGE 62
SF
Off-Delay Timer
SF <timer> starts the addressed timer when the RLO transitions from "1" to "0". The programmed
time elapses as long as RLO = 0. The time is stopped if RLO transitions to "1" before the programmed
time interval has expired. This timer start command expects the time value and the time base to be
stored as a BCD number in ACCU 1-L.
Example:
A
I 2.1
L
S5T#10s
Preset 10 seconds into ACCU 1.
SF
T1
Start timer T1 as an off-delay timer.
A
I 2.2
R
T1
Reset timer T1.
A
T1
Check signal state of timer T1.
=
Q 4.0
PAGE 63
PAGE 64
SP
Pulse Timer
SP <timer> starts the addressed timer when the RLO transitions from "0" to "1". The programmed
time elapses as long as RLO = 1. The timer is stopped if RLO transitions to "0" before the
programmed time interval has expired. This timer start command expects the time value and the time
base to be stored as a BCD number in ACCU 1-L.
Example:
A
I 2.1
L
S5T#10s
Preset 10 seconds into ACCU 1.
SP
T1
Start timer T1 as a pulse timer.
A
I 2.2
R
T1
Reset timer T1.
A
T1
Check signal state of timer T1.
=
Q 4.0
PAGE 65
PAGE 66
SS
Retentive On-Delay Timer
SS <timer> (start timer as a retentive ON timer) starts the addressed timer when the RLO transitions
from "0" to "1". The full programmed time interval elapses, even if the RLO transitions to "0" in the
meantime. The programmed time interval is re-triggered (started again) if RLO transitions from "0" to
"1" before the programmed time has expired. This timer start command expects the time value and
the time base to be stored as a BCD number in ACCU 1-L.
Example:
A
I 2.1
L
S5T#10s
Preset 10 seconds into ACCU 1.
SS
T1
Start timer T1 as a retentive on-delay timer.
A
I 2.2
R
T1
Reset timer T1.
A
T1
Check signal state of timer T1.
=
Q 4.0
PAGE 67
PAGE 68
PAGE 69
R
Reset Timer
R <timer> stops the current timing function and clears the timer value and the time base of the
addressed timer word if the RLO transitions from 0 to 1.
Example:
A
I 2.1
R T1
Check the signal state of input I 2.1 If RLO transitioned from 0 = 1, then reset timer
T1.
PAGE 70
L
L
AD
T
ID20
ID24
MD8
1111
1000
1000
1100
0101
0100
1000
0111
0000
1001
0110
0000
0011
1011
0011
Bit:0
1011
0101
0001
AW
AND Word (16-Bit)
AW (AND word) combines the contents of ACCU 1-L with ACCU 2-L or a 16 bit-constant bit by bit
according to the Boolean logic operation AND. A bit in the result word is "1" only when the
corresponding bits of both words combined in the logic operation are "1".
Examples:
Bit:
15
Bit:0
ACCU 1-L before execution of AW:
0101 1001 0011 1011
ACCU 2-L or 16-bit constant:
1111 0110 1011 0101
Result (ACCU 1-L) after execution of AW:
0101 0000 0011 0001
L
L
AW
T
IW20
IW22
OD
OR Double Word (32-Bit)
OD (OR double word) combines the contents of ACCU 1 with ACCU 2 or a 32-bit constant bit by bit
according to the Boolean logic operation OR. A bit in the result double word is "1" when at least one of
the corresponding bits of both double words combined in the logic operation is "1".
Examples:
Bit:
31
L
L
OD
T
ID20
ID24
MD8
Bit:0
1111
1000
1111
1100
0101
1101
1000
0111
1111
0101
0110
0111
0011
1011
1011
1011
0101
1111
OW
OR Word (16-Bit)
OW (OR word) combines the contents of ACCU 1-L with ACCU 2-L or a 16 bit-constant bit by bit
according to the Boolean logic operation OR. A bit in the result word is "1" when at least one of the
corresponding bits of both words combined in the logic operation is "1".
Examples:
Bit:
15
Bit:0
PAGE 71
IW20
IW22
MW8
0101
0110
1111
0011
1011
0111
1011
0101
1011
1111
XOD
Exclusive OR Double Word (32-Bit)
XOD (XOR double word) combines the contents of ACCU 1 with ACCU 2 or a 32-bit constant bit by
bit according to the Boolean logic operation XOR (Exclusive Or). A bit in the result double word is "1"
when only one of the corresponding bits of both double words combined in the logic operation is "1".
Examples:
Bit:
31
L
L
XOD
T
ID20
ID24
MD8
Bit:0
1111
1000
0111
1100
0101
1001
1000
0111
1111
0101
0110
0011
0011
1011
1000
1011
0101
1110
XOW
Exclusive OR Word (16-Bit)
XOW (XOR word) combines the contents of ACCU 1-L with ACCU 2-L or a 16 bit-constant bit by bit
according to the Boolean logic operation XOR. A bit in the result word is "1" only when one of the
corresponding bits of both words combined in the logic operation is "1".
Examples:
Bit:
15
Bit:0
ACCU 1 before execution of XOW:
0101 0101 0011 1011
ACCU 2-L or 16-bit constant:
1111 0110 1011 0101
Result (ACCU 1) after execution of XOW:
1010 0011 1000 1110
L
L
XOW
T
IW20
IW22
MW8
PAGE 72
Accumulator Instructions
DEC
Decrement ACCU 1-L-L
Example:
L
MB250
Load the value of MB250
DEC 1
Instruction "Decrement ACCU 1-L-L by 1"; store result in ACCU 1-L-L.
T
MB250
Transfer the contents of ACCU 1-L-L (result) back to MB250.
INC
Increment ACCU 1-L-L
Example:
L
MB22
Load the value of MB22
INC
1
Instruction "Increment ACCU 1 (MB22) by 1"; store result in ACCU 1-L-L
T
MB22
Transfer the contents of ACCU 1-L-L (result) back to MB22
TAK
Toggle ACCU 1 with ACCU 2
Example:
Subtract smaller value from greater value:
Example:
L
MW10
Load contents of MW10 into ACCU 1-L.
L
MW12
Load contents of ACCU 1-L into ACCU 2-L.Load contents of MW12
into ACCU 1>I
Check if ACCU 2-L (MW10) greater than ACCU 1-L (MW12).
JC
NEXT
Jump to NEXT jump label if ACCU 2 (MW10) is greater than ACCU 1
(MW12).
TAK
Swap contents ACCU 1 and ACCU 2
NEXT: -I
Subtract contents of ACCU 2-L from contents of ACCU 1-L.
T
MW14
Transfer result (= greater value minus smaller value) to MW14.
PAGE 73
PROGRAMMING EXAMPLES
PAGE 74
PAGE 75
PAGE 76
PAGE 77
PAGE 78
PAGE 79
PAGE 80
PAGE 81
PAGE 82
PAGE 83
PAGE 84
PAGE 85
PAGE 86
PAGE 87
PAGE 88
PAGE 89
PAGE 90
PAGE 91
PAGE 92
PAGE 93
PAGE 94
----------------------------------------------------------------------------------------------------------------
PAGE 95