继续练习SCL编程,按照前面第2个练习的要求,使用SCL实现红绿黄等倒计时还有5秒进行闪烁。
前面程序新建一个SCL编程的FB,建立下面的变量
写下面的SCL程序
IF #stopbtn = 1 THEN
#CurrentState := 4;
END_IF;
IF #startbrn = 1 THEN
#CurrentState := 1;
END_IF;
(*红灯控制*)
IF #CurrentState = 1 THEN
#RedLight_in := 1;
IF NOT #RedLightsparkle THEN
#RedLight := 1;
ELSE
#RedLight := 0;
END_IF;
#RedLightTime:=T_SUB(IN1 := #RedLightDuration, IN2 := "RedLight_TON3".ET);(*计算剩余时间*)
IF #RedLightTime <= t#5s AND "Clock_0.5Hz" THEN
#RedLightsparkle := 1;
ELSE
#RedLightsparkle := 0;
END_IF;
ELSE
#RedLight_in := 0;
#RedLight := 0;
END_IF;
"RedLight_TON4".TON(IN:=#RedLight_in,
PT:=#RedLightDuration);
IF "RedLight_TON3".Q THEN
#CurrentState := 2;
END_IF;
(*绿灯控制*)
IF #CurrentState = 2 THEN
#GreenLight_in := 1;
IF NOT #GreenLightsparkle THEN
#GreenLight := 1;
ELSE
#GreenLight := 0;
END_IF;
#GreenLightTime := T_SUB(IN1 := #GreenLightDuration, IN2 :="GreenLight_TON4".ET);(*计算剩余时间*)
IF #GreenLightTime <= t#5s AND "Clock_0.5Hz" THEN
#GreenLightsparkle := 1;
ELSE
#GreenLightsparkle := 0;
END_IF;
ELSE
#GreenLight_in := 0;
#GreenLight := 0;
END_IF;
"GreenLight_TON4".TON(IN:=#GreenLight_in,
PT:=#GreenLightDuration);
IF "GreenLight_TON4".Q THEN
#CurrentState := 3;
END_IF;
(*黄灯控制*)
IF #CurrentState = 3 THEN
#yellowLight_in := 1;
IF NOT #YellowLightsparkle THEN
#YellowLight := 1;
ELSE
#YellowLight := 0;
END_IF;
#YellowLightTime := T_SUB(IN1 := #YellowLightDuration, IN2 := "YellowLight_TON4".ET);(*计算剩余时间*)
IF #YellowLightTime <= t#5s AND "Clock_0.5Hz" THEN
#YellowLightsparkle := 1;
ELSE
#YellowLightsparkle := 0;
END_IF;
ELSE
#yellowLight_in := 0;
#YellowLight := 0;
END_IF;
"YellowLight_TON4".TON(IN := #yellowLight_in,
PT := #YellowLightDuration);
IF "YellowLight_TON4".Q THEN
#CurrentState := 1;
END_IF;
在OB1调用这个FB
在WINCC建立变量,关联M1.6和M1.7,WINCC画面放置按钮,用于启动停止功能,关联前面建立的变量,鼠标按下变量为1,鼠标弹起变量为0
保存运行wincc,启动控制功能,就可以看到效果了。
WINCC这边设置比较简单,我就不做截图了。