西门子S7300PLC可编程序控制技术培训主讲:骆老师15811515136数据格式十进制BCD数数00000100012001030011401005010160110701118100091001101112131415110011017000000001580128+64841符号位数据类型整型例如205+++十进制值:070158000000000000000000000000000000023163124指数(8位)尾数(23位)数据类型实数例如45.6789符号位数据格式(16位)BCD整数BCD28=256+0000000100101000151413121110987654321025=32+23=8=2960000001010010110296符号(+)1111010000010011413符号(-)W#16#F41327=128+1111111001100011151413121110987654321023=8+22=4=41228=256+24=16+-(412+1)=-413负数整数正数W#16#296+296-413PGCPU数据格式(32位)实数=+1,5*2126-127=0,75DW#16#296L#+296+0.75或+7.5E-10000000100101000000000000000000015141312111098765432103130292827262524232221201918171628=256+25=32+23=8=296整数(32位)=00000000000000000001111110100000实数符号151413121110987654321031302928272625242322212019181716e=指数(8Bit)f=底数(23Bit)实数的通用格式=(Sign)•(1.f)•(2e-127)20212223242526272-232-12-22-4.....2-30000000符号(+)00000010100101102960000000000000BCDDINTREAL定时器:带保持接通延时(SS)STLAI0.7LS5T#35sSST4AI0.5RT4LT4TMW0LCT4TQW6AT4=Q4.5LADT4S_ODTSTVSQBCDBIRI0.7I0.5S5T#35sQ4.5MW0QW6FBDS_ODTSTVQBIRI0.7I0.5S5T#35sMW0QW6T4BCD=Q4.5S例如S处的RLOR处的RLO定时器操作Q定时器:关断延时(SF)STLAI0.7LS5T#35sSFT4AI0.5RT4LT4TMW0LCT4TQW6AT4=Q4.5LADT4S_OFFDTTVSQBCDBIRI0.7I0.5S5T#35sQ4.5MW0QW6FBDS_OFFDTTVQBIRI0.7I0.5S5T#35sMW0QW6T4BCD=Q4.5S例如S处的RLOR处的RLO定时器操作Q定时器:脉冲(SP)FBDS_PULSETVQBIRI0.7I0.5S5T#35sMW0QW6T4BCD=Q4.5SS处的RLOR处的RLO定时器操作Q例如STLAI0.7LS5T#35sSPT4AI0.5RT4LT4TMW0LCT4TQW6AT4=Q8.5MW0LADT4S_PULSETVSQBCDBIRI0.7I0.5S5T#35sQ4.5QW6定时器:扩展脉冲(SE)LADT4S_PEXTTVSQBCDBIRI0.7I0.5S5T#35sQ4.5MW0QW6FBDS_PEXTTVQBIRI0.7I0.5S5T#35sMW0QW6T4BCD=Q4.5SS处的RLOR处的RLO定时器操作Q例如STLAI0.7LS5T#35sSET4AI0.5RT4LT4TMW0LCT4TQW6AT4=Q4.5定时器:位指令I0.0T4SDS5T#5sT4Q4.0I0.1T4RNetwork1:Network2:Network3:LAD&SDT4I0.0S5T#5s&=Q4.0T4&I0.1TVRT4FBDAI0.0LS5T#5sSDT4AT4=Q4.0AI0.1RT4STL练习9.1:测试定时器T4S_PEXTSTVRBIBCDQI0.7S5T#5sI0.5Q4.0I0.7I0.5Q4.0T4S_PULSESTVRBIBCDQI0.7S5T#5sI0.5Q4.0I0.7I0.5Q4.05sT4S_ODTSTVRBIBCDQI0.7S5T#5sI0.5Q4.0I0.7I0.5Q4.0T4S_ODTSSTVRBIBCDQI0.7S5T#5sI0.5Q4.0I0.7I0.5Q4.0I0.7I0.5Q4.0T4S_OFFDTSTVRBIBCDQI0.7S5T#5sI0.5Q4.0设置定时器以下列形式设置时间:常数S5T#43S_200MS输入字IW2输出字QW12标志字MW24数据字DBW255T10TV--01010000110010定时器字的数据格式(432×0.1s=43.2s)102101100时间0-999(BCD)无用0:0.01S1:0.1S2:1S3:10S使用定时器T10BIQDBW1LT10TDBW1MW2LT10TMW2QW4LT10TQW4二进制定时器字T10QDBW5LCT10TDBW5MW6LCT10TMW6QW6LCT10TQW6十进制定时器字BCD13129900时基时间值LT102920时间值13129900时基时间值LCT10102101100时间值131237411BinBCD定时器字累加器练习9.2:由两个定时器组成的时钟发生器I1.7Q5.7FC8Q5.72S4SI1.7练习9.3:由单定时器构成的闪烁频率发生器T64Q5.3T64!G!Q5.3#M0.2S5T#5SS_PEXTTVST64M0.2M1.0M0.2M0.3#M0.3SR&&M1.0Q5.3FC51Segment1Segment2注意:输出点为继电器输出时,开关频率不能太高。练习9.4:三个风扇的监控程序I0.0I0.1I0.2=1I0.3&S_ODTT30I0.7M30.0&I0.0I0.1I0.2I0.3RSQ=1Q4.0STEP7中的S5计数器STLAI0.4CUC5AI0.5CDC5AI0.3LC#20SC5AI0.7RC5LC5TMW4LCC5TQW6AC5=Q4.3LADFBDQI0.4I0.5CUI0.7C#20S_CUDCDSI0.3PVRQ4.3CVCV_BCDMW4QW6C5QQI0.4I0.5CUI0.7C#20S_CUDCDSI0.3PVRQ4.3CVCV_BCDMW4QW6C5=Q计数器:位指令STLAI0.0LC#20SC5AI0.1CUC5AI0.2CDC5AC5=Q4.0LADI0.0C5SCC#20Network1:C5Network2:I0.1CUNetwork3:I0.2C5CDNetwork4:C5Q4.0FBDSCC5I0.0C#20CVCUC5I0.1CDC5I0.2=Q4.0C5转换指令I-DI-REALSTLLMW12ITDDTRTMD26INI_DIENENOOUTINMW12MD14INDI_RENENOOUTINMD14MD26FBD带有实数的运算程序从双整数到实数的转换从整数到双整数的转换任务整数格式的数据(16位)LADINDI_RENENOOUTMD14MD26ININI_DIENENOOUTMW12MD14IN数字逻辑指令LIW0LW#16#5F2AAW/OW/XOWTMW10015IW0=W#16#5F2A=WAND_WWXOR_WWOR_WENENOIN2OUTW#16#5F2AMW10IN1IW001111000000000000111100000011111XORXOW后的MW101111111000000000OROW后的MW100111000001111111ANDAW后的MW100111000000000000LADFBDSTL基本数学功能减法乘法除法加法LMW4LMW10+ITMW6MW10ADD_IIN2ENENOOUTIN1MW4MW6MW10ADD_IIN2ENENOOUTIN1MW4MW6SUB_IIN2ENENOIN1MW5MW11MW7OUTMW11SUB_IIN2ENENOOUTIN1MW5MW7LMW5LMW11-ITMW7MD6MD12MUL_RENENOIN1MD66IN2MD12MUL_RIN2ENENOOUTIN1MD6MD66LMD6LMD12*RTMD66MD40MD4ENENOIN1IN2MD32OUTDIV_RMD4DIV_RIN2ENENOOUTIN1MD40MD32LMD40LMD4/RTMD32练习9.7:数字操作例子练习9.8:瓶装线编程(产量数据)满瓶空瓶“碎”瓶MW100MW102MW104练习9.9:瓶装线编程(包装数量)移位指令(字/双字)LMW8LMW4SLWTMW12SHL_WENNOUTENOMW12INMW4MW8=+2LMW4SLW2TMW12或:001110000000000001151413121110987654321010000000000001OUTIN左移字:00OUT1110000000000011100000000000011514131211109876543210IN右移字:EN0=1EN0=0有符号整数右移位SHR_IENNOUTEN0MW12INMW4MW8=+3LMW8LMW4SSITMW12LMW4SSI3TMW12或:有符号整数右移:111110100000000010110000000001001514131211109876543210OUTINEN0=0000101100000000011010000000001101514131211109876543210OUTINEN0=1双字循环移位指令ROL_DWENNOUTENOMD12INMD2MW6=+4LMW6LMD2RLDTMD12LMD2RLD4TMD12或:向左循环移动4位:00000000000000111011000000000000151413121110987654321031302928272625242322212019181716IN:10110000000000110000000000000000OUT:位存储器PIQPII数据存储区数据块DBxDByDBz...I/O区L堆栈数据块(DB)功能FC10功能FC20功能块FB1OB1全局数据DB20所有块可以访问背景数据DB5FB1的背景DBSTEP7数据类型概述基本数据类型(到32位)复杂数据类型(长于32位)用户定义数据类型(长于32位)•位数据类型(BOOL,BYTE,WORD,DWORD,CHAR)•数学数据类型(INT,DINT,REAL)•定时器类型(S5TIME,TIME,DATE,TIME_OF_DAY)•时间(DATE_AND_TIME)•矩阵(ARRAY)•结构(STRUCT)•字符串(STRING)数据类型UDT(用户定义数据类型)STEP7基本数据类型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关键字长度(位)该类型的常数举例复杂数据类型关键字长度(位)举例DATE_AND_TIME64DT#97-09-24-12:14:55.0STRING8*(字符个数+2)´Thisisastring´(最多254个字符的字符串)´SIEMENS´ARRAY用户定义测量值:ARRAY[1..20](相同数据类型的