《数据块中数据存储.ppt》由会员分享,可在线阅读,更多相关《数据块中数据存储.ppt(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Date:2022/12/3File:DBs.1SIMATIC S7Siemens AG 2003.All rights reserved.SITRAIN Training for Automation and Drives数据块中数据存储 Still waters run deep.流静水深流静水深,人静心深人静心深 Where there is life,there is hope。有生命必有希望。有生命必有希望Date:2022/12/3File:DBs.2SIMATIC S7Siemens AG 2003.All rights reserved.SITRAIN Training for
2、 Automation and Drives目标学习了本章之后,你将学习了本章之后,你将.懂得全局数据块的用途.熟悉基本和复杂数据类型.能够对带有单元变量的数据块编辑、存储和下装到CPU.熟悉并能够应用编址数据块变量Date:2022/12/3File:DBs.3SIMATIC S7Siemens AG 2003.All rights reserved.SITRAIN Training for Automation and Drives位存储器位存储器PIQPII数据存储区数据存储区数据块数据块DBxDByDBz.I/O 区区L 堆栈堆栈Date:2022/12/3File:DBs.4SIMA
3、TIC S7Siemens AG 2003.All rights reserved.SITRAIN Training for Automation and Drives数据块数据块(DB)功能功能FC10功能功能FC20功能块功能块FB1OB1全局数据全局数据 DB20 所有块可以访问所有块可以访问背景数据背景数据 DB5 FB1的背景的背景DBDate:2022/12/3File:DBs.5SIMATIC S7Siemens AG 2003.All rights reserved.SITRAIN Training for Automation and DrivesSTEP 7数据类型概述数据
4、类型概述基本数据类型(到32 位)复杂数据类型(长于32位)用户定义数据类型(长于 32 位)位数据类型位数据类型(BOOL,BYTE,WORD,DWORD,CHAR)数学数据类型数学数据类型(INT,DINT,REAL)定时器类型定时器类型(S5TIME,TIME,DATE,TIME_OF_DAY)时间时间(DATE_AND_TIME)矩阵矩阵(ARRAY)结构结构(STRUCT)字符串字符串(STRING)数据类型数据类型 UDT(用户定义数据类型)Date:2022/12/3File:DBs.6SIMATIC S7Siemens AG 2003.All rights reserved.S
5、ITRAIN Training for Automation and DrivesSTEP 7基本数据类型基本数据类型BOOL1True 或 False(1 或0)BYTE8B#16#A9WORD16W#16#12AFDWORD32DW#16#ADAC1EF5CHAR8 w S5TIME16S5T#5s_200msINT16123DINT32L#65539REAL321.2 或 34.5E-12TIME32T#2D_1H_3M_45S_12MSDATE16D#1993-01-20TIME_OF_DAY32TOD#12:23:45.12关键字关键字长度长度(位位)该类型的常数举例该类型的常数举例
6、Date:2022/12/3File:DBs.7SIMATIC S7Siemens AG 2003.All rights reserved.SITRAIN Training for Automation and Drives建立新数据块建立新数据块Date:2022/12/3File:DBs.8SIMATIC S7Siemens AG 2003.All rights reserved.SITRAIN Training for Automation and Drives输入、保存、下载和监视数据块输入、保存、下载和监视数据块Declaration ViewData ViewDate:2022/1
7、2/3File:DBs.9SIMATIC S7Siemens AG 2003.All rights reserved.SITRAIN Training for Automation and Drives寻址数据单元寻址数据单元078 位数据字节 0 DBB 0数据字节 1 DBW 0数据字节 8191DBD 8188DBW 8190DBB 8191数据字节 2 DBD 0数据字节 3 DBX 4.1Date:2022/12/3File:DBs.10SIMATIC S7Siemens AG 2003.All rights reserved.SITRAIN Training for Automat
8、ion and Drives访问数据单元访问数据单元DB 99 Values传统访问方法完全表示访问或LDB99.DBB1或LValues.States或A DB99.DBX0.0或AValues.Status或TDB99.DBW2或T Values.Number或LDB99.DBD8或L Values.Weight2绝对寻址符号寻址OPNDB 99LDBB 11.0StatesBYTEOPNValuesADBX 0.00.0StatusBOOLOPNValuesTDBW 22.0NumberINT4.0 Weight1REALOPNDB 99LDBD 88.0 Weight2REALAdd.
9、NameTypeDate:2022/12/3File:DBs.11SIMATIC S7Siemens AG 2003.All rights reserved.SITRAIN Training for Automation and Drives练习练习:计数传送的零件计数传送的零件(FC 18,DB 18):0 8 1 5QW 6ACTUAL-number of partsSETPOINT-number of partsIW 2Q 8.4模拟器模拟器CPU 程序程序:DB 18,FC 18传送带模型传送带模型-LED ACTUAL=SETPOINTDate:2022/12/3File:DBs.1
10、2SIMATIC S7Siemens AG 2003.All rights reserved.SITRAIN Training for Automation and Drives练习练习:计数传送的零件计数传送的零件(FC 18),答案提示答案提示NW 2:Counting using memory word,ACTUAL number of partsNW 1:Set counter to 0MOVEENINOUTENO复位的条件0DB_Parts.ACT_Number_of_partsNW 4:Readin SETPOINT number of parts and convert from
11、 BCD to Integer来自数码拨轮(IW 2)的值从 BCD 转换到整数-把零件的给定值(Integer)存储在 MW 200NW 5:ACTUAL-SETPOINT comparison,LED(red LED Q8.4)比较实际值(“DB_Parts”.ACT_Number_of_parts)和给定值(MW 200),比较的结果送到红色的LEDNW 3:Display ACTUAL number of parts on BCD digital display零件的实际值(DB_Parts.ACT_Number_of_parts)从整数到BCD转换-结果在 BCD 数字显示(QW 6
12、)ADD_IENIN1IN2OUTENO计数事件的上升沿1DB_Parts.ACT_Number_of_partsDB_Parts.ACT_Number_of_partsDate:2022/12/3File:DBs.13SIMATIC S7Siemens AG 2003.All rights reserved.SITRAIN Training for Automation and Drives复杂数据类型复杂数据类型关键字关键字长度长度(位位)举例举例DATE_AND_TIME64DT#97-09-24-12:14:55.0STRING8*(字符个数+2)This is a string(最多
13、254个字符的字符串)SIEMENS ARRAY用户定义 Measured values:ARRAY1.20(相同数据类型的元素组)INT STRUCT 用户定义 Motor:STRUCT(不同数据类型的元素组)Speed :INTCurrent:REALEND_STRUCTUDTUDT 作为块 UDT作为array 元素(用户定义数据类型=用户定义 基本或复杂数据类型 STRUCT Drive:ARRAY1.4组成的模板)Speed:INT UDT1 Current:REAL END_STRUCT Date:2022/12/3File:DBs.14SIMATIC S7Siemens AG 2
14、003.All rights reserved.SITRAIN Training for Automation and Drives矩阵举例矩阵举例程序编辑器中的显示程序编辑器中的显示(数据块数据块 DB 2):Measuring_point1.Measuring_point,data type Real2.Measuring_point,data type Real3.Measuring_point,data type Real10.Measuring_point,data type Real带有名字“Measuring_point”的矩阵(相同数据类型的几个元素)Date:2022/12/
15、3File:DBs.15SIMATIC S7Siemens AG 2003.All rights reserved.SITRAIN Training for Automation and Drives结构举例结构举例程序编辑器中的显示程序编辑器中的显示(数据块数据块 DB 1):Motor_dataSpeed,data type IntegerRated_current,data type RealStarting_current,data type RealDirection,data type Bool带有名字“Motor_data”的结构(不同数据类型的几个元素)Date:2022/12/3File:DBs.16SIMATIC S7Siemens AG 2003.All rights reserved.SITRAIN Training for Automation and Drives练习(选作):数据块和数据格式 IB1 DB10.DBW2 DB11.DBW8 BIN BCD QW6 DB11.DBW10 BIN BCD QW6 IB2MW2 BCD BINMW4 IB3MW6 BCD BINMW8 I0.7=“0”:BEC:BE
限制150内