本文使用SCL语言进行程序编写,一个简单的霓虹灯控制程序,文末附程序截图与仿真视频,不足之处还望海涵,烦请多多指教。
干货★★★★★资料
使用SCL语言IF(条件语句)、CASE...OF(选择语句)控制霓虹灯,实现以下功能:
1、当按下启动按钮后,16盏彩灯依次以1S的时间间隔进行点亮;
2、当16盏灯全部点亮后,16盏灯以0.5Hz的频率闪烁10S;
3、10S完成后,16盏灯依次以1S的时间间隔进行熄灭;
4、当16盏灯全部熄灭后,16盏灯偶数灯全部点亮并且以0.5Hz频率进行闪烁,闪烁3S;
5、完成后16盏灯奇数灯全部点亮并且以0.5Hz的频率进行闪烁,闪烁3S;
6、偶数灯奇数灯交替闪烁6S,程序执行完毕,循环控制。
-----------------------------------------------------------------------------------------------------------------
SCL控制程序编程语句:
(*启动控制*)
IF ("03_启动" OR "03_中继1") AND NOT "03_停止" THEN
//典型的起保停电路
"03_中继1" := TRUE; //按下启动按钮,中继得电
ELSE
"03_中继1" := FALSE; //按下停止按钮,中继失电
END_IF;
(*控制复位*)
IF "03_启动" OR "03_停止" OR "03_中继2"THEN
//按下启动或停止按钮,进行灯和累加器复位
"霓虹灯控制定时".CV := 0; //复位累加器当前值
"03_霓虹灯_1" := FALSE; //复位霓虹灯状态
"03_霓虹灯_2" := FALSE;
"03_霓虹灯_3" := FALSE;
"03_霓虹灯_4" := FALSE;
"03_霓虹灯_5" := FALSE;
"03_霓虹灯_6" := FALSE;
"03_霓虹灯_7" := FALSE;
"03_霓虹灯_8" := FALSE;
"03_霓虹灯_9" := FALSE;
"03_霓虹灯_10" := FALSE;
"03_霓虹灯_11" := FALSE;
"03_霓虹灯_12" := FALSE;
"03_霓虹灯_13" := FALSE;
"03_霓虹灯_14" := FALSE;
"03_霓虹灯_15" := FALSE;
"03_霓虹灯_16" := FALSE;
END_IF;
(*使用加计数器设计成定时器*)
IF "03_中继1" THEN //启动后累加器开始运行
"霓虹灯控制定时".CTU(CU:="Clock_1Hz",
//使用1200PLC自带的1秒脉冲进行累加计时
R:="03_中继2" OR "03_停止" OR "03_启动", //累加器复位条件
PV:=56, //累加器复位条件
Q=>"03_中继2", //累加器输出
CV=>"03_计数器当前值"); //累加器当前计数值
END_IF;
(*控制程序*)
CASE "03_计数器当前值" OF
//16盏彩灯依次以1S的时间间隔进行点亮
1:
"03_霓虹灯_1" := TRUE;
2:
"03_霓虹灯_2" := TRUE;
3:
"03_霓虹灯_3" := TRUE;
4:
"03_霓虹灯_4" := TRUE;
5:
"03_霓虹灯_5" := TRUE;
6:
"03_霓虹灯_6" := TRUE;
7:
"03_霓虹灯_7" := TRUE;
8:
"03_霓虹灯_8" := TRUE;
9:
"03_霓虹灯_9" := TRUE;
10:
"03_霓虹灯_10" := TRUE;
11:
"03_霓虹灯_11" := TRUE;
12:
"03_霓虹灯_12" := TRUE;
13:
"03_霓虹灯_13" := TRUE;
14:
"03_霓虹灯_14" := TRUE;
15:
"03_霓虹灯_15" := TRUE;
16:
"03_霓虹灯_16" := TRUE;
//16盏灯以0.5Hz的频率闪烁10S;
17..27:
"03_霓虹灯_1" := "Clock_0.5Hz";
"03_霓虹灯_2" := "Clock_0.5Hz";
"03_霓虹灯_3" := "Clock_0.5Hz";
"03_霓虹灯_4" := "Clock_0.5Hz";
"03_霓虹灯_5" := "Clock_0.5Hz";
"03_霓虹灯_6" := "Clock_0.5Hz";
"03_霓虹灯_7" := "Clock_0.5Hz";
"03_霓虹灯_8" := "Clock_0.5Hz";
"03_霓虹灯_9" := "Clock_0.5Hz";
"03_霓虹灯_10" := "Clock_0.5Hz";
"03_霓虹灯_11" := "Clock_0.5Hz";
"03_霓虹灯_12" := "Clock_0.5Hz";
"03_霓虹灯_13" := "Clock_0.5Hz";
"03_霓虹灯_14" := "Clock_0.5Hz";
"03_霓虹灯_15" := "Clock_0.5Hz";
"03_霓虹灯_16" := "Clock_0.5Hz";
//16盏灯以0.5Hz的频率闪烁10S
28:
"03_霓虹灯_16" := FALSE;
"03_霓虹灯_2" := TRUE;
"03_霓虹灯_4" := TRUE;
"03_霓虹灯_6" := TRUE;
"03_霓虹灯_8" := TRUE;
"03_霓虹灯_10" := TRUE;
"03_霓虹灯_12" := TRUE;
"03_霓虹灯_14" := TRUE;
"03_霓虹灯_1" := TRUE;
"03_霓虹灯_3" := TRUE;
"03_霓虹灯_5" := TRUE;
"03_霓虹灯_7" := TRUE;
"03_霓虹灯_9" := TRUE;
"03_霓虹灯_11" := TRUE;
"03_霓虹灯_13" := TRUE;
"03_霓虹灯_15" := TRUE;
29:
"03_霓虹灯_15" := FALSE;
30:
"03_霓虹灯_14" := FALSE;
31:
"03_霓虹灯_13" := FALSE;
32:
"03_霓虹灯_12" := FALSE;
33:
"03_霓虹灯_11" := FALSE;
34:
"03_霓虹灯_10" := FALSE;
35:
"03_霓虹灯_9" := FALSE;
36:
"03_霓虹灯_8" := FALSE;
37:
"03_霓虹灯_7" := FALSE;
38:
"03_霓虹灯_6" := FALSE;
', '#imageElem', { tips: [1, '#fff'], area: ['210px'] // 这里定义大图的大小 }); }); $('#imageElem').mouseout(function (){ layer.closeAll('tips'); }); });