Date,2009-7-30
File,SSP1_09C.1
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
数字指令
CMP ==I
IN1
IN2
IW0
IW2
M0.0 Q 5.7
T4
S_ODT
TV
S Q
BCD
BI
R
I0.7
I0.5
S5T#35s
Q4.5
MW0
QW6
Date,2009-7-30
File,SSP1_09C.2
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
数据格式十进制 BCD
数 数
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10
11
12
13
14
15
1 1 0 0 1 1 0 1
7 0
0 0 0 0 0 0 0
15 8
0
128 + 64 8 4 1
符号位 数据类型 整型 例如 205
+ + +十进制值,
0
7 015 8
0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
23 1631 24
指数 (8位 ) 尾数 (23 位 )
数据类型 实数 例如 45.6789
符号位
Date,2009-7-30
File,SSP1_09C.3
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
数据格式 (16 位 )
BCD
整数
BCD
28
=
256 +
0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
25
=
32 +
23
=
8 = 296
0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0
2 9 6符号 (+)
1 1 1 1 0 1 0 0 0 0 0 1 0 0 1 1
4 1 3符号 (-)
W#16#F413
27
=
128 +
1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
23
=
8+
22
=
4 = 412
28
=
256+
24
=
16+
- (412 + 1) = - 413
负数整数正数
W#16#296
+296
-413
PG CPU
Date,2009-7-30
File,SSP1_09C.4
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
数据格式 (32 位 )
实数 = +1,5 * 2 126-127 = 0,75
DW#16#296
L#+296
+0.75
或
+7.5 E-1
0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 031 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
28
=
256 +
25
=
32 +
23
=
8 = 296整数 (32 位 ) =
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 1 1 1 1 1 1 0 1 0 0 0 0 0
实数符号
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 031 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
e = 指数 (8 Bit) f = 底数 (23 Bit)
实数的通用格式 = (Sign)? (1.f)? (2e-127)
2021222324252627 2-232-1 2-2 2-4,....2-3
0 0 0 0
0 0 0符号 (+)
00 0 0 0 0 1 0 1 0 0 1 0 1 1 0
2 9 60
0 0 00 0 00 0 0 0 0 0
BCD
DINT
REAL
Date,2009-7-30
File,SSP1_09C.5
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
装载举例数据装入和传递 (1)
L +5 // 16-位常数 (整数 )
L L#523123 // 32-位常数 (双整数 )
L B#16#EF // 十六进制字节
L 2#0010 0110 1110 0011 // 16-位二进制值
L 3.14 // 32-位常数 (实数 )
MOVE
EN
IN
OUT
ENO
MB5
5
FBD
L +5
T MB5
STL
MOVE
EN
OUT
ENO
MB5
LAD
IN5
Date,2009-7-30
File,SSP1_09C.6
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
数据装入和传递 (2)
0 0 0 0
0 0 0 0
:
:
L W#16#CAFE
L W#16#AFFE
:
:
:
X X X X X X X XC A F E
A F F E
ACCU2
内容
ACCU1
内容程序
Y Y Y Y Y Y Y YX X X X X X X X
0 0 0 0 C A F E
Date,2009-7-30
File,SSP1_09C.7
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
数据装入和传递 (3)
31 23 15 7 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 MB0
31 23 15 7 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 MB1MB0
31 23 15 7 0
MB3MB2MB0 MB1
装载
L MB 0
程序
T QD 4
QD 4
QW 4
QB 4
传递
ACCU1内容
L MW 0
L MD 0
T QW 4
T QB 4
Date,2009-7-30
File,SSP1_09C.8
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
LAD STL
示例,
输入延时
S_ODT
A I0.7
L S5T#35s
SD T4
A I0.5
R T4
L T4
T MW0
LC T4
T MW2
A T4
= Q8.5
定时器概述
Date,2009-7-30
File,SSP1_09C.9
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
定时器:接通延时 (SD)
LAD
T4
S_ODT
TV
S Q
BCD
BI
R
I0.7
I0.5
S5T#35s
Q4.5
MW0
QW6
FBD
S_ODT
TV
Q
BI
R
I0.7
I0.5
S5T#35s
MW0
QW6
T4
BCD
=
Q4.5
S
STL
A I0.7
L S5T#35s
SD T4
A I0.5
R T4
L T4
T MW0
LC T4
T QW6
A T4
= Q4.5
例如
S处的 RLO
R处的 RLO
定时器操作
Q
时间值,0,,,999
0,01s <--
0,1s <--
1s <--
10s <--
0 0
0 1
1 0
1 1
S5TIME
数据类型
Date,2009-7-30
File,SSP1_09C.10
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
定时器,带保持接通延时 (SS)
STL
A I0.7
L S5T#35s
SS T4
A I0.5
R T4
L T4
T MW0
LC T4
T QW6
A T4
= Q4.5
LAD
T4
S_ODTS
TV
S Q
BCD
BI
R
I0.7
I0.5
S5T#35s
Q4.5
MW0
QW6
FBD
S_ODTS
TV
Q
BI
R
I0.7
I0.5
S5T#35s
MW0
QW6
T4
BCD
=
Q4.5
S
例如
S处的 RLO
R处的 RLO
定时器操作
Q
Date,2009-7-30
File,SSP1_09C.11
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
定时器:关断延时 (SF)
STL
A I0.7
L S5T#35s
SF T4
A I0.5
R T4
L T4
T MW0
LC T4
T QW6
A T4
= Q4.5
LAD
T4
S_OFFDT
TV
S Q
BCD
BI
R
I0.7
I0.5
S5T#35s
Q4.5
MW0
QW6
FBD
S_OFFDT
TV
Q
BI
R
I0.7
I0.5
S5T#35s
MW0
QW6
T4
BCD
=
Q4.5
S
例如
S处的 RLO
R处的 RLO
定时器操作
Q
Date,2009-7-30
File,SSP1_09C.12
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
定时器:脉冲 (SP)
FBD
S_PULSE
TV
Q
BI
R
I0.7
I0.5
S5T#35s
MW0
QW6
T4
BCD
=
Q4.5
S
S处的 RLO
R处的 RLO
定时器操作
Q
例如
STL
A I0.7
L S5T#35s
SP T4
A I0.5
R T4
L T4
T MW0
LC T4
T QW6
A T4
= Q8.5
MW0
LAD
T4
S_PULSE
TV
S Q
BCD
BI
R
I0.7
I0.5
S5T#35s
Q4.5
QW6
Date,2009-7-30
File,SSP1_09C.13
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
定时器:扩展脉冲 (SE)
LAD
T4
S_PEXT
TV
S Q
BCD
BI
R
I0.7
I0.5
S5T#35s
Q4.5
MW0
QW6
FBD
S_PEXT
TV
Q
BI
R
I0.7
I0.5
S5T#35s
MW0
QW6
T4
BCD
=
Q4.5
S
S处的 RLO
R处的 RLO
定时器操作
Q
例如
STL
A I0.7
L S5T#35s
SE T4
A I0.5
R T4
L T4
T MW0
LC T4
T QW6
A T4
= Q4.5
Date,2009-7-30
File,SSP1_09C.14
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
定时器:位指令
I0.0 T4
SD
S5T#5s
T4 Q 4.0
I0.1 T4
R
Network 1:
Network 2:
Network 3:
LAD
& SD
T4
I0.0
S5T#5s
& =
Q 4.0
T4
&I0.1
TV
R
T4
FBD
A I0.0
L S5T#5s
SD T4
A T4
= Q 4.0
A I0.1
R T4
STL
Date,2009-7-30
File,SSP1_09C.15
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.1,测试定时器
T4
S_PEXT
S
TV
R
BI
BCD
Q
I 0.7
S5T#5s
I 0.5 Q4.0
I 0.7
I 0.5
Q4.0
T4
S_PULSE
S
TV
R
BI
BCD
Q
I 0.7
S5T#5s
I 0.5 Q 4.0
I 0.7
I 0.5
Q4.0
5s
T4
S_ODT
S
TV
R
BI
BCD
Q
I 0.7
S5T#5s
I 0.5 Q 4.0
I 0.7
I 0.5
Q4.0
T4
S_ODTS
S
TV
R
BI
BCD
Q
I 0.7
S5T#5s
I 0.5 Q 4.0
I 0.7
I 0.5
Q4.0
I 0.7
I 0.5
Q4.0
T4
S_OFFDT
S
TV
R
BI
BCD
Q
I 0.7
S5T#5s
I 0.5 Q 4.0
Date,2009-7-30
File,SSP1_09C.16
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
设置定时器以下列形式设置时间:
常数 S5T#43S_200MS
输入字 IW2
输出字 QW12
标志字 MW24
数据字 DBW255
T10
TV
- - 0 1 0 1 0 0 0 0 1 1 0 0 1 0 定时器字的数据格式
(432× 0.1s = 43.2s)102 101 100
时间 0-999(BCD)
无用 0,0.01S 1,0.1S
2,1S 3,10S
Date,2009-7-30
File,SSP1_09C.17
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
使用定时器
T10
BI
Q
DBW1 L T10
T DBW1
MW2 L T10
T MW2
QW4 L T10
T QW4
二进制定时器字
T10
Q
DBW5 LC T10
T DBW5
MW6 LC T10
T MW6
QW6 LC T10
T QW6
十进制定时器字
BCD
13 12 9
9 0
0
时基 时间值
L T10
29 20
时间值
13 12 9
9 0
0
时基 时间值
LC T10
102 101 100
时间值
13 12 37 411
Bin BCD
定时器字累加器
Date,2009-7-30
File,SSP1_09C.18
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.2,由两个定时器组成的时钟发生器
I 1.7
Q 5.7
FC8
Q5.7
2S 4S
I 1.7
Date,2009-7-30
File,SSP1_09C.19
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.3,由单定时器构成的闪烁频率发生器
T64
Q5.3
T64
! G !
Q5.3 # M 0.2
S5T#5S
S_PEXT
TV
S
T64
M 0.2
M 1.0
M 0.2
M 0.3
# M 0.3 S
R
&
&
M 1.0
Q5.3
FC51
Segment1
Segment2
注意:输出点为继电器输出时,
开关频率不能太高。
Date,2009-7-30
File,SSP1_09C.20
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.4,三个风扇的监控程序
I0.0
I0.1
I0.2
=1
I0.3
&
S_ODT
T30
I0.7
M30.0
&
I0.0
I0.1
I0.2
I0.3
R
S Q >=1
Q4.0
Date,2009-7-30
File,SSP1_09C.21
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
STEP 7中的 S5计数器
STL
A I0.4
CU C5
A I0.5
CD C5
A I0.3
L C#20
S C5
A I0.7
R C5
L C5
T MW4
LC C5
T QW6
A C5
= Q4.3
LAD FBD
Q
I 0.4
I 0.5
CU
I 0.7
C#20
S_CUD
CD
S
I 0.3
PV
R
Q 4.3
CV
CV_BCD
MW 4
QW 6
C5
Q
I 0.4
I 0.5
CU
I 0.7
C#20
S_CUD
CD
SI 0.3
PV
R
Q 4.3
CV
CV_BCD
MW 4
QW 6
C5
=
Date,2009-7-30
File,SSP1_09C.22
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
计数器:位指令
STL
A I0.0
L C#20
S C5
A I0.1
CU C5
A I0.2
CD C5
A C5
= Q 4.0
LAD
I0.0 C5
SC
C#20
Network 1:
C5
Network 2:
I0.1
CU
Network 3:
I0.2 C5
CD
Network 4:
C5 Q 4.0
FBD
SC
C5
I0.0
C#20 CV
CU
C5
I0.1
CD
C5
I0.2
=
Q 4.0
C5
Date,2009-7-30
File,SSP1_09C.23
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
计数器:功能图
CU
CD
S
R
Q
计数
5
4
3
2
1
0
Date,2009-7-30
File,SSP1_09C.24
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
比较指令
STL
A M0.0
A (
L IW0
L IW2
==I
)
= Q5.7
LAD
CMP ==I
IN1
IN2
IW0
IW2
M0.0 Q 5.7
FBD
IN1
IN2
M0.0
IW0
IW2
& =Q5.7
CMP ==I
Date,2009-7-30
File,SSP1_09C.25
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.5,分频器
T65;M25.0
F
G
1Hz
&
&
C25
CU
CD
R
CV
BCD
Q
QW6 MW2
IN1
IN2
Q
>=
S
R Q
M25.1
Q4.7I1.7
I1.7
M25.0
C25
Q4.7
MW2
FC25
Date,2009-7-30
File,SSP1_09C.26
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
主容器
Q 5.0
灌装漏斗瓶子传感器
I 8.6
瓶子传感器
I 8.5
瓶子传感器
I 8.7
练习 9.6:瓶装线编程
(灌装循环和瓶子计数 )
Q 8.5 传送带向前
Q 8.6 传送带向后
I 0.0 = 启动 (瞬态常开触点 )
I 0.1 = 停止 (瞬态常闭触点 )
设备 ON/OFF:
I 0.4 = 手动 /自动
I 0.5 = 接受模式手动 /自动模式:
I 0.2 = 向前点动
I 0.3 = 向后点动
M
Date,2009-7-30
File,SSP1_09C.27
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
转换操作 BCD <-> 整数
IN
BCD_I
EN
ENO
OUT
IW4
MW20
IN
I_BCD
EN
ENO
OUT
MW10
QW6
FBD
L IW4
BTI
T MW20
L MW10
ITB
T QW6
STL
0 8 1 5用 BCD码输入的数用 BCD码显示的数转换
BCD->整数任务转换
BCD<-整数有数学运算的用户程序
0 2 4 8
IN
BCD_I
EN ENO
OUTIW4 MW20
I_BCD
IN
EN ENO
OUTMW10 QW6
LAD
Date,2009-7-30
File,SSP1_09C.28
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
转换指令 I -> DI -> REAL
STL
L MW12
ITD
DTR
T MD26
IN
I_DI
EN
ENO
OUT
MW12
MD14
IN
DI_R
EN
ENO
OUT
MD14
MD26
F
B
D
带有实数的运算程序从双整数到实数的转换从整数到双整数的转换任务整数格式的数据 (16 位 )
LAD
IN
DI_R
EN ENO
OUTMD14 MD26IN
I_DI
EN ENO
OUTMW12 MD14
Date,2009-7-30
File,SSP1_09C.29
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
数字逻辑指令
L IW 0
L W#16#5F2A
AW / OW / XOW
T MW10
015
IW0 =
W#16#5F2A =
WAND_W
WXOR_W
WOR_W
EN ENO
IN2 OUTW#16#5F2A MW10
IN1IW0
0 1 1 1 10 0 0 0 0 0 0 0 0 0 0
0 1 1 1 10 0 0 0 0011 1 1 1
XOR
XOW 后的 MW10 1 1 1 1 1 1 1 0 00000000
OR
OW 后的 MW10 0 1 1 10 0 0 0 01 1 1 1 1 1 1
AND
AW 后的 MW10 0 1 1 10 0 0 0 0 0 0 0 0 0 00
Date,2009-7-30
File,SSP1_09C.30
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
LAD FBD STL
基本数学功能减法乘法除法加法
L MW4
L MW10
+ I
T MW6MW10
ADD_I
IN2
EN ENO
OUT
IN1MW4
MW6 MW10
ADD_I
IN2
EN
ENO
OUT
IN1MW4
MW6
SUB_I
IN2
EN ENO
IN1MW5
MW11 MW7OUT MW11
SUB_I
IN2
EN
ENO
OUT
IN1MW5
MW7
L MW5
L MW11
- I
T MW7
MD6
MD12
MUL_R
EN ENO
IN1
MD66IN2 MD12
MUL_R
IN2
EN
ENO
OUT
IN1MD6
MD66 L MD6L MD12
* R
T MD66
MD40
MD4
EN ENO
IN1
IN2 MD32OUT
DIV_R
MD4
DIV_R
IN2
EN
ENO
OUT
IN1MD40
MD32 L MD40L MD4
/ R
T MD32
Date,2009-7-30
File,SSP1_09C.31
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.7,数字操作例子
Date,2009-7-30
File,SSP1_09C.32
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.8:瓶装线编程 (产量数据 )
满瓶空瓶
“碎,瓶
MW 100
MW 102
MW 104
Date,2009-7-30
File,SSP1_09C.33
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.9:瓶装线编程
(包装数量 )
Date,2009-7-30
File,SSP1_09C.34
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
移位指令 (字 / 双字 )
L MW8
L MW4
SLW
T MW12
SHL_W
EN
N OUT
ENO
MW12
INMW4
MW8
= +2
L MW4
SLW 2
T MW12
或:
0 0
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 0 0 0 0 0 0 0 0 0 0 0 0 1
OUT
IN
左移字,
0 0
OUT
1 1 1 0 0 0 0 0 0 0 0 0 0 0
11 1 0 0 0 0 0 0 0 0 0 0 0 0 1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IN
右移字,
EN0 =1 EN0 = 0
Date,2009-7-30
File,SSP1_09C.35
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
有符号整数右移位
SHR_I
EN
N OUT
EN0
MW12
INMW4
MW8
= +3
L MW8
L MW4
SSI
T MW12
L MW4
SSI 3
T MW12
或,
有符号整数右移:
1 1 1
1
1 0 1 0 0 0 0 0 0 0 0 0 1
01 1 0 0 0 0 0 0 0 0 0 1 0 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OUT
IN
EN0 = 0
0 0 0
1
0 1 1 0 0 0 0 0 0 0 0 0 1
10 1 0 0 0 0 0 0 0 0 0 1 1 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OUT
IN
EN0 = 1
Date,2009-7-30
File,SSP1_09C.36
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
双字循环移位指令
ROL_DW
EN
N OUT
ENO
MD12
INMD2
MW6
= +4
L MW6
L MD2
RLD
T MD12
L MD2
RLD 4
T MD12
或,
向左循环移动 4位:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 11 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 031 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IN,
1 0 1 10 0 0 0 0 0 0 0 0 0 1 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0OUT,
File,SSP1_09C.1
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
数字指令
CMP ==I
IN1
IN2
IW0
IW2
M0.0 Q 5.7
T4
S_ODT
TV
S Q
BCD
BI
R
I0.7
I0.5
S5T#35s
Q4.5
MW0
QW6
Date,2009-7-30
File,SSP1_09C.2
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
数据格式十进制 BCD
数 数
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10
11
12
13
14
15
1 1 0 0 1 1 0 1
7 0
0 0 0 0 0 0 0
15 8
0
128 + 64 8 4 1
符号位 数据类型 整型 例如 205
+ + +十进制值,
0
7 015 8
0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
23 1631 24
指数 (8位 ) 尾数 (23 位 )
数据类型 实数 例如 45.6789
符号位
Date,2009-7-30
File,SSP1_09C.3
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
数据格式 (16 位 )
BCD
整数
BCD
28
=
256 +
0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
25
=
32 +
23
=
8 = 296
0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 0
2 9 6符号 (+)
1 1 1 1 0 1 0 0 0 0 0 1 0 0 1 1
4 1 3符号 (-)
W#16#F413
27
=
128 +
1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
23
=
8+
22
=
4 = 412
28
=
256+
24
=
16+
- (412 + 1) = - 413
负数整数正数
W#16#296
+296
-413
PG CPU
Date,2009-7-30
File,SSP1_09C.4
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
数据格式 (32 位 )
实数 = +1,5 * 2 126-127 = 0,75
DW#16#296
L#+296
+0.75
或
+7.5 E-1
0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 031 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
28
=
256 +
25
=
32 +
23
=
8 = 296整数 (32 位 ) =
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 1 1 1 1 1 1 0 1 0 0 0 0 0
实数符号
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 031 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
e = 指数 (8 Bit) f = 底数 (23 Bit)
实数的通用格式 = (Sign)? (1.f)? (2e-127)
2021222324252627 2-232-1 2-2 2-4,....2-3
0 0 0 0
0 0 0符号 (+)
00 0 0 0 0 1 0 1 0 0 1 0 1 1 0
2 9 60
0 0 00 0 00 0 0 0 0 0
BCD
DINT
REAL
Date,2009-7-30
File,SSP1_09C.5
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
装载举例数据装入和传递 (1)
L +5 // 16-位常数 (整数 )
L L#523123 // 32-位常数 (双整数 )
L B#16#EF // 十六进制字节
L 2#0010 0110 1110 0011 // 16-位二进制值
L 3.14 // 32-位常数 (实数 )
MOVE
EN
IN
OUT
ENO
MB5
5
FBD
L +5
T MB5
STL
MOVE
EN
OUT
ENO
MB5
LAD
IN5
Date,2009-7-30
File,SSP1_09C.6
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
数据装入和传递 (2)
0 0 0 0
0 0 0 0
:
:
L W#16#CAFE
L W#16#AFFE
:
:
:
X X X X X X X XC A F E
A F F E
ACCU2
内容
ACCU1
内容程序
Y Y Y Y Y Y Y YX X X X X X X X
0 0 0 0 C A F E
Date,2009-7-30
File,SSP1_09C.7
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
数据装入和传递 (3)
31 23 15 7 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 MB0
31 23 15 7 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 MB1MB0
31 23 15 7 0
MB3MB2MB0 MB1
装载
L MB 0
程序
T QD 4
QD 4
QW 4
QB 4
传递
ACCU1内容
L MW 0
L MD 0
T QW 4
T QB 4
Date,2009-7-30
File,SSP1_09C.8
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
LAD STL
示例,
输入延时
S_ODT
A I0.7
L S5T#35s
SD T4
A I0.5
R T4
L T4
T MW0
LC T4
T MW2
A T4
= Q8.5
定时器概述
Date,2009-7-30
File,SSP1_09C.9
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
定时器:接通延时 (SD)
LAD
T4
S_ODT
TV
S Q
BCD
BI
R
I0.7
I0.5
S5T#35s
Q4.5
MW0
QW6
FBD
S_ODT
TV
Q
BI
R
I0.7
I0.5
S5T#35s
MW0
QW6
T4
BCD
=
Q4.5
S
STL
A I0.7
L S5T#35s
SD T4
A I0.5
R T4
L T4
T MW0
LC T4
T QW6
A T4
= Q4.5
例如
S处的 RLO
R处的 RLO
定时器操作
Q
时间值,0,,,999
0,01s <--
0,1s <--
1s <--
10s <--
0 0
0 1
1 0
1 1
S5TIME
数据类型
Date,2009-7-30
File,SSP1_09C.10
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
定时器,带保持接通延时 (SS)
STL
A I0.7
L S5T#35s
SS T4
A I0.5
R T4
L T4
T MW0
LC T4
T QW6
A T4
= Q4.5
LAD
T4
S_ODTS
TV
S Q
BCD
BI
R
I0.7
I0.5
S5T#35s
Q4.5
MW0
QW6
FBD
S_ODTS
TV
Q
BI
R
I0.7
I0.5
S5T#35s
MW0
QW6
T4
BCD
=
Q4.5
S
例如
S处的 RLO
R处的 RLO
定时器操作
Q
Date,2009-7-30
File,SSP1_09C.11
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
定时器:关断延时 (SF)
STL
A I0.7
L S5T#35s
SF T4
A I0.5
R T4
L T4
T MW0
LC T4
T QW6
A T4
= Q4.5
LAD
T4
S_OFFDT
TV
S Q
BCD
BI
R
I0.7
I0.5
S5T#35s
Q4.5
MW0
QW6
FBD
S_OFFDT
TV
Q
BI
R
I0.7
I0.5
S5T#35s
MW0
QW6
T4
BCD
=
Q4.5
S
例如
S处的 RLO
R处的 RLO
定时器操作
Q
Date,2009-7-30
File,SSP1_09C.12
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
定时器:脉冲 (SP)
FBD
S_PULSE
TV
Q
BI
R
I0.7
I0.5
S5T#35s
MW0
QW6
T4
BCD
=
Q4.5
S
S处的 RLO
R处的 RLO
定时器操作
Q
例如
STL
A I0.7
L S5T#35s
SP T4
A I0.5
R T4
L T4
T MW0
LC T4
T QW6
A T4
= Q8.5
MW0
LAD
T4
S_PULSE
TV
S Q
BCD
BI
R
I0.7
I0.5
S5T#35s
Q4.5
QW6
Date,2009-7-30
File,SSP1_09C.13
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
定时器:扩展脉冲 (SE)
LAD
T4
S_PEXT
TV
S Q
BCD
BI
R
I0.7
I0.5
S5T#35s
Q4.5
MW0
QW6
FBD
S_PEXT
TV
Q
BI
R
I0.7
I0.5
S5T#35s
MW0
QW6
T4
BCD
=
Q4.5
S
S处的 RLO
R处的 RLO
定时器操作
Q
例如
STL
A I0.7
L S5T#35s
SE T4
A I0.5
R T4
L T4
T MW0
LC T4
T QW6
A T4
= Q4.5
Date,2009-7-30
File,SSP1_09C.14
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
定时器:位指令
I0.0 T4
SD
S5T#5s
T4 Q 4.0
I0.1 T4
R
Network 1:
Network 2:
Network 3:
LAD
& SD
T4
I0.0
S5T#5s
& =
Q 4.0
T4
&I0.1
TV
R
T4
FBD
A I0.0
L S5T#5s
SD T4
A T4
= Q 4.0
A I0.1
R T4
STL
Date,2009-7-30
File,SSP1_09C.15
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.1,测试定时器
T4
S_PEXT
S
TV
R
BI
BCD
Q
I 0.7
S5T#5s
I 0.5 Q4.0
I 0.7
I 0.5
Q4.0
T4
S_PULSE
S
TV
R
BI
BCD
Q
I 0.7
S5T#5s
I 0.5 Q 4.0
I 0.7
I 0.5
Q4.0
5s
T4
S_ODT
S
TV
R
BI
BCD
Q
I 0.7
S5T#5s
I 0.5 Q 4.0
I 0.7
I 0.5
Q4.0
T4
S_ODTS
S
TV
R
BI
BCD
Q
I 0.7
S5T#5s
I 0.5 Q 4.0
I 0.7
I 0.5
Q4.0
I 0.7
I 0.5
Q4.0
T4
S_OFFDT
S
TV
R
BI
BCD
Q
I 0.7
S5T#5s
I 0.5 Q 4.0
Date,2009-7-30
File,SSP1_09C.16
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
设置定时器以下列形式设置时间:
常数 S5T#43S_200MS
输入字 IW2
输出字 QW12
标志字 MW24
数据字 DBW255
T10
TV
- - 0 1 0 1 0 0 0 0 1 1 0 0 1 0 定时器字的数据格式
(432× 0.1s = 43.2s)102 101 100
时间 0-999(BCD)
无用 0,0.01S 1,0.1S
2,1S 3,10S
Date,2009-7-30
File,SSP1_09C.17
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
使用定时器
T10
BI
Q
DBW1 L T10
T DBW1
MW2 L T10
T MW2
QW4 L T10
T QW4
二进制定时器字
T10
Q
DBW5 LC T10
T DBW5
MW6 LC T10
T MW6
QW6 LC T10
T QW6
十进制定时器字
BCD
13 12 9
9 0
0
时基 时间值
L T10
29 20
时间值
13 12 9
9 0
0
时基 时间值
LC T10
102 101 100
时间值
13 12 37 411
Bin BCD
定时器字累加器
Date,2009-7-30
File,SSP1_09C.18
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.2,由两个定时器组成的时钟发生器
I 1.7
Q 5.7
FC8
Q5.7
2S 4S
I 1.7
Date,2009-7-30
File,SSP1_09C.19
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.3,由单定时器构成的闪烁频率发生器
T64
Q5.3
T64
! G !
Q5.3 # M 0.2
S5T#5S
S_PEXT
TV
S
T64
M 0.2
M 1.0
M 0.2
M 0.3
# M 0.3 S
R
&
&
M 1.0
Q5.3
FC51
Segment1
Segment2
注意:输出点为继电器输出时,
开关频率不能太高。
Date,2009-7-30
File,SSP1_09C.20
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.4,三个风扇的监控程序
I0.0
I0.1
I0.2
=1
I0.3
&
S_ODT
T30
I0.7
M30.0
&
I0.0
I0.1
I0.2
I0.3
R
S Q >=1
Q4.0
Date,2009-7-30
File,SSP1_09C.21
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
STEP 7中的 S5计数器
STL
A I0.4
CU C5
A I0.5
CD C5
A I0.3
L C#20
S C5
A I0.7
R C5
L C5
T MW4
LC C5
T QW6
A C5
= Q4.3
LAD FBD
Q
I 0.4
I 0.5
CU
I 0.7
C#20
S_CUD
CD
S
I 0.3
PV
R
Q 4.3
CV
CV_BCD
MW 4
QW 6
C5
Q
I 0.4
I 0.5
CU
I 0.7
C#20
S_CUD
CD
SI 0.3
PV
R
Q 4.3
CV
CV_BCD
MW 4
QW 6
C5
=
Date,2009-7-30
File,SSP1_09C.22
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
计数器:位指令
STL
A I0.0
L C#20
S C5
A I0.1
CU C5
A I0.2
CD C5
A C5
= Q 4.0
LAD
I0.0 C5
SC
C#20
Network 1:
C5
Network 2:
I0.1
CU
Network 3:
I0.2 C5
CD
Network 4:
C5 Q 4.0
FBD
SC
C5
I0.0
C#20 CV
CU
C5
I0.1
CD
C5
I0.2
=
Q 4.0
C5
Date,2009-7-30
File,SSP1_09C.23
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
计数器:功能图
CU
CD
S
R
Q
计数
5
4
3
2
1
0
Date,2009-7-30
File,SSP1_09C.24
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
比较指令
STL
A M0.0
A (
L IW0
L IW2
==I
)
= Q5.7
LAD
CMP ==I
IN1
IN2
IW0
IW2
M0.0 Q 5.7
FBD
IN1
IN2
M0.0
IW0
IW2
& =Q5.7
CMP ==I
Date,2009-7-30
File,SSP1_09C.25
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.5,分频器
T65;M25.0
F
G
1Hz
&
&
C25
CU
CD
R
CV
BCD
Q
QW6 MW2
IN1
IN2
Q
>=
S
R Q
M25.1
Q4.7I1.7
I1.7
M25.0
C25
Q4.7
MW2
FC25
Date,2009-7-30
File,SSP1_09C.26
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
主容器
Q 5.0
灌装漏斗瓶子传感器
I 8.6
瓶子传感器
I 8.5
瓶子传感器
I 8.7
练习 9.6:瓶装线编程
(灌装循环和瓶子计数 )
Q 8.5 传送带向前
Q 8.6 传送带向后
I 0.0 = 启动 (瞬态常开触点 )
I 0.1 = 停止 (瞬态常闭触点 )
设备 ON/OFF:
I 0.4 = 手动 /自动
I 0.5 = 接受模式手动 /自动模式:
I 0.2 = 向前点动
I 0.3 = 向后点动
M
Date,2009-7-30
File,SSP1_09C.27
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
转换操作 BCD <-> 整数
IN
BCD_I
EN
ENO
OUT
IW4
MW20
IN
I_BCD
EN
ENO
OUT
MW10
QW6
FBD
L IW4
BTI
T MW20
L MW10
ITB
T QW6
STL
0 8 1 5用 BCD码输入的数用 BCD码显示的数转换
BCD->整数任务转换
BCD<-整数有数学运算的用户程序
0 2 4 8
IN
BCD_I
EN ENO
OUTIW4 MW20
I_BCD
IN
EN ENO
OUTMW10 QW6
LAD
Date,2009-7-30
File,SSP1_09C.28
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
转换指令 I -> DI -> REAL
STL
L MW12
ITD
DTR
T MD26
IN
I_DI
EN
ENO
OUT
MW12
MD14
IN
DI_R
EN
ENO
OUT
MD14
MD26
F
B
D
带有实数的运算程序从双整数到实数的转换从整数到双整数的转换任务整数格式的数据 (16 位 )
LAD
IN
DI_R
EN ENO
OUTMD14 MD26IN
I_DI
EN ENO
OUTMW12 MD14
Date,2009-7-30
File,SSP1_09C.29
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
数字逻辑指令
L IW 0
L W#16#5F2A
AW / OW / XOW
T MW10
015
IW0 =
W#16#5F2A =
WAND_W
WXOR_W
WOR_W
EN ENO
IN2 OUTW#16#5F2A MW10
IN1IW0
0 1 1 1 10 0 0 0 0 0 0 0 0 0 0
0 1 1 1 10 0 0 0 0011 1 1 1
XOR
XOW 后的 MW10 1 1 1 1 1 1 1 0 00000000
OR
OW 后的 MW10 0 1 1 10 0 0 0 01 1 1 1 1 1 1
AND
AW 后的 MW10 0 1 1 10 0 0 0 0 0 0 0 0 0 00
Date,2009-7-30
File,SSP1_09C.30
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
LAD FBD STL
基本数学功能减法乘法除法加法
L MW4
L MW10
+ I
T MW6MW10
ADD_I
IN2
EN ENO
OUT
IN1MW4
MW6 MW10
ADD_I
IN2
EN
ENO
OUT
IN1MW4
MW6
SUB_I
IN2
EN ENO
IN1MW5
MW11 MW7OUT MW11
SUB_I
IN2
EN
ENO
OUT
IN1MW5
MW7
L MW5
L MW11
- I
T MW7
MD6
MD12
MUL_R
EN ENO
IN1
MD66IN2 MD12
MUL_R
IN2
EN
ENO
OUT
IN1MD6
MD66 L MD6L MD12
* R
T MD66
MD40
MD4
EN ENO
IN1
IN2 MD32OUT
DIV_R
MD4
DIV_R
IN2
EN
ENO
OUT
IN1MD40
MD32 L MD40L MD4
/ R
T MD32
Date,2009-7-30
File,SSP1_09C.31
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.7,数字操作例子
Date,2009-7-30
File,SSP1_09C.32
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.8:瓶装线编程 (产量数据 )
满瓶空瓶
“碎,瓶
MW 100
MW 102
MW 104
Date,2009-7-30
File,SSP1_09C.33
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
练习 9.9:瓶装线编程
(包装数量 )
Date,2009-7-30
File,SSP1_09C.34
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
移位指令 (字 / 双字 )
L MW8
L MW4
SLW
T MW12
SHL_W
EN
N OUT
ENO
MW12
INMW4
MW8
= +2
L MW4
SLW 2
T MW12
或:
0 0
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 0 0 0 0 0 0 0 0 0 0 0 0 1
OUT
IN
左移字,
0 0
OUT
1 1 1 0 0 0 0 0 0 0 0 0 0 0
11 1 0 0 0 0 0 0 0 0 0 0 0 0 1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IN
右移字,
EN0 =1 EN0 = 0
Date,2009-7-30
File,SSP1_09C.35
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
有符号整数右移位
SHR_I
EN
N OUT
EN0
MW12
INMW4
MW8
= +3
L MW8
L MW4
SSI
T MW12
L MW4
SSI 3
T MW12
或,
有符号整数右移:
1 1 1
1
1 0 1 0 0 0 0 0 0 0 0 0 1
01 1 0 0 0 0 0 0 0 0 0 1 0 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OUT
IN
EN0 = 0
0 0 0
1
0 1 1 0 0 0 0 0 0 0 0 0 1
10 1 0 0 0 0 0 0 0 0 0 1 1 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OUT
IN
EN0 = 1
Date,2009-7-30
File,SSP1_09C.36
SIMATIC S7
Siemens AG 2000,All rights reserved.
Information and Training Center
Know ledge for Automation
双字循环移位指令
ROL_DW
EN
N OUT
ENO
MD12
INMD2
MW6
= +4
L MW6
L MD2
RLD
T MD12
L MD2
RLD 4
T MD12
或,
向左循环移动 4位:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 11 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 031 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IN,
1 0 1 10 0 0 0 0 0 0 0 0 0 1 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0OUT,