Date:2010-7-30File:FCFBs.1SIMATIC®S7SiemensAG2003.Allrightsreserved.功能和功能块Date:2010-7-30File:FCFBs.2SIMATIC®S7SiemensAG2003.Allrightsreserved.目标学习了本章之后,你将......熟悉临时变量的用途...能够声明临时变量并在程序中使用...熟悉可赋值参数的块的用途...能够编程可赋值参数的功能和它们的调用...了解功能(FC)和功能块(FB)之间的差别...熟悉背景模型和多重背景模型...熟悉静态变量的用途...能够声明静态变量并在程序中使用...能够编程可赋值参数的功能块和它们的调用Date:2010-7-30File:FCFBs.3SIMATIC®S7SiemensAG2003.Allrightsreserved.局部变量临时变量•当相关块执行完毕后被清除•临时存储在Lstack中•可在下列块中使用OB/FC/FB静态变量•当相关块执行完毕后仍然保留•永久存储在DB中•只能在FB中使用局部变量/数据(只在一个块中有效)全局变量/数据(在全部程序中有效)•PII/PIQ•I/O•M/T/C•DBareas符号地址绝对地址访问方式Date:2010-7-30File:FCFBs.4SIMATIC®S7SiemensAG2003.Allrightsreserved.临时变量Date:2010-7-30File:FCFBs.5SIMATIC®S7SiemensAG2003.Allrightsreserved.256Bytes事件所占用的Lstack1OB1OB11操作系统程序所占用的局部数据区的总长度FC20有临时变量OB1FC20FC1733OB1FC1744OB1FC1766FC20有临时变量OB1FC20FC1755FC17有临时变量2OB1FC1727OB17Date:2010-7-30File:FCFBs.6SIMATIC®S7SiemensAG2003.Allrightsreserved.执行的程序局部数据堆栈的大小对于S7-300:局部堆栈大小优先级256bytes127总容量:1.5Kbyte(CPU313..316)总容量:1.5Kbyte(CPU313..316)启动程序(只执行一次)循环扫描程序256bytes256bytes256bytes1232时间中断日时钟中断延时处理中断循环处理中断循环扫描中的错误处理中断256bytes162826256bytes事件驱动中断硬件中断启动过程中的错误处理中断Date:2010-7-30File:FCFBs.7SIMATIC®S7SiemensAG2003.Allrightsreserved.块所需要的局部数据区的长度RightClickDate:2010-7-30File:FCFBs.8SIMATIC®S7SiemensAG2003.Allrightsreserved.练习:使用临时变量#Setpoint#Setpoint替换为临时变量#SetpointDate:2010-7-30File:FCFBs.9SIMATIC®S7SiemensAG2003.Allrightsreserved.示例:用输出LED故障信息指示Fault_SignalDisplayAcknowledgeStored_Fault要求解决方案AcknowledgeStored_FaultFault_SignalStored_FaultFault_SignalDisplayEdge_MemoryFlash_FrequencyPRSSRQDate:2010-7-30File:FCFBs.10SIMATIC®S7SiemensAG2003.Allrightsreserved.Fault_SignalEdge_MemoryAcknowledgeStored_FaultDisplayFlash_freqFC20调用FC20(e.g.inOB1)可以分配参数的块A(AI1.0RM40.0AI1.1FPM40.1SM40.0AM40.0)AM10.3OAI1.1ANM40.0=Q5.1不可以分配参数的块形式参数M40.0M40.1I1.3I1.0Q5.1M10.3实际参数A(A#AcknowledgeR#Stored_FaultA#Fault_SignalFP#Edge_MemoryS#Stored_FaultA#Stored_Fault)A#Flash_Freq.OA#Fault_SignalAN#Stored_Fault=#Display可以分配参数的块FC20的STL程序Date:2010-7-30File:FCFBs.11SIMATIC®S7SiemensAG2003.Allrightsreserved.定义FC20形式参数使用方法图形显示只能读在块的左侧只能写在块的右侧参数类型输入参数输出参数输入/输出参数定义inoutIn_out可读/可写在块的左侧形式参数Date:2010-7-30File:FCFBs.12SIMATIC®S7SiemensAG2003.Allrightsreserved.编辑可以分配参数的块Date:2010-7-30File:FCFBs.13SIMATIC®S7SiemensAG2003.Allrightsreserved.调用可以分配参数的块Date:2010-7-30File:FCFBs.14SIMATIC®S7SiemensAG2003.Allrightsreserved.练习:编辑可以分配参数的FC块Date:2010-7-30File:FCFBs.15SIMATIC®S7SiemensAG2003.Allrightsreserved.练习:调用可以分配参数的FC块第一次调用FC20时的参数分配第二次调用FC20时的参数分配Date:2010-7-30File:FCFBs.16SIMATIC®S7SiemensAG2003.Allrightsreserved.功能块(FB)DB2OB1FB块的变量声明表FB20ENFault_SignalAcknowledgeDisplayFlash_FrequencyENODate:2010-7-30File:FCFBs.17SIMATIC®S7SiemensAG2003.Allrightsreserved.用功能块实现的故障信息显示FB的声明表背景数据块Date:2010-7-30File:FCFBs.18SIMATIC®S7SiemensAG2003.Allrightsreserved.生成背景数据块1.在FB调用时生成背景数据块2.创建一个新的背景数据块在LAD/STL/FBDEditor在SIMATICManagerDate:2010-7-30File:FCFBs.19SIMATIC®S7SiemensAG2003.Allrightsreserved.之后插入/删除块的参数SaveDate:2010-7-30File:FCFBs.20SIMATIC®S7SiemensAG2003.Allrightsreserved.检查块的一致性Date:2010-7-30File:FCFBs.21SIMATIC®S7SiemensAG2003.Allrightsreserved.调用被修改过的块时应做的更正单击鼠标右键Date:2010-7-30File:FCFBs.22SIMATIC®S7SiemensAG2003.Allrightsreserved.练习:编辑功能块Date:2010-7-30File:FCFBs.23SIMATIC®S7SiemensAG2003.Allrightsreserved.练习:调用功能块并测试添加Network2&3删除Network2Date:2010-7-30File:FCFBs.24SIMATIC®S7SiemensAG2003.Allrightsreserved.多重背景模型DB10普通背景模型FB20OB1CallFB20,DB10Disturb._Input:=Acknowledge:=Flash_Freq:=Display:=DB11FB20CallFB20,DB11Disturb._Input:=Acknowledge:=Flash_Freq:=Display:=DB12FB20CallFB20,DB12Disturb._Input:=Acknowledge:=Flash_Freq:=Display:=多重背景模型FB100DB100CallFB100,DB100OB1statDist_1FB20statDist_2FB20第二次调用FB20的参数和静态参数CallDist_2Disturb._Input:=Acknowledge:=Flash_Freq:=Display:=第一次调用FB20的参数和静态参数CallDist_1Disturb._Input:=Acknowledge:=Flash_Freq:=Display:=Date:2010-7-30File:FCFBs.25SIMATIC®S7SiemensAG2003.Allrightsreserved.练习:识别变量的类型AbsoluteSymbolicTemporaryStaticParameterL#Number_1T#Maximum_valueTMW40StatementL#Number_2L#Intermediate_resultL“Number_1”T#Number_2GlobalLocalDate:2010-7-30File:FCFBs.26SIMATIC®S7SiemensAG2003.Allrightsreserved.LAD/FBDSTL在块调用时使用EN/ENO参数CALLFC1NOP0例子??.?FC1ENENOFC2ENENOFC3ENENO=FC1ENENO??.?无条件调用AI0.1JNB_001CALLFC1_001:ABR=Q5.0FC1ENENOI0.1=Q5.0条件调用Date:2010-7-30File:FCFBs.27SIMATIC®S7SiemensAG2003.Allrightsreserved.总结:块的调用•CALLFC1•UCFC1•CCFC1STLLADFBDFC1ENENOFC1ENENOFC1(CALL)FB无参数,无静态参数•UCFB1•CCFB1CALL有参数•CALLFC2Par1:...Par2:...Par3:...FC2ENENOPar3Par1Par2FC2ENENOPar1Par2Par3有参数,和/或静态参数•CALLFB2,DB3Par1:...Par2:...Par3:...FB2ENENOPar3Par1Par2DB3FB2ENENOPar3Par1Par2DB3无参数语言FCFC1Date:2010-7-30File:FCFBs.28SIMATIC®S7SiemensAG2003.Allrightsreserved.练习(选作):多台设备的风扇监控功能ABC=1S_ODTTIMER_NOACKNSIG&ABCRSQ=1FLTFC8REPORTABCACKNTIMER_NOTVFLTSIG功能符号Date:2010-7-30File:FCFBs.29SIMATIC®S7SiemensAG2003.Allrightsreserved.练习(选作):风扇监控功能的扩展ABC=1S_ODTTIMER_NOACKNSIG&ABCRSQ=1FLTFC8REPORTABCACKNTIMER_NOTVFLT功能符号ENAB&ENABENABSIG