1. 基于PLC的路灯控制系统设计

GSV(wallclocktime,,datetime,Data[0]); //获取系统时间

case Data[1] of //对不同月份进行判断

1,2:
if(Data[3]>=18 or Data[3]<=7) then //对开灯时间进行判断
Street_Lamp := 1;
end_if;

3:
if(Data[2]>=21) then //3,6.9.12月份要对日期进行判断
if(Data[3]>=19 or Data[3]<=6) then //对开灯时间进行判断
Street_Lamp := 1;
end_if;
end_if;

if(Data[2]<21) then
if(Data[3]>=18 or Data[3]<=7) then
Street_Lamp := 1;
end_if;
end_if;

4,5:

if(Data[3]>=19 or Data[3]<=6) then
Street_Lamp := 1;
end_if;

6:
if(Data[2]<21) then
if(Data[3]>=19 or Data[3]<=6) then
Street_Lamp := 1;
end_if;
end_if;

if(Data[2]>=21) then
if(Data[3]>=20 or Data[3]<=5) then
Street_Lamp := 1;
end_if;
end_if;

7,8:

if(Data[3]>=20 or Data[3]<=5) then
Street_Lamp := 1;
end_if;

9:
if(Data[2]<21) then
if(Data[3]>=20 or Data[3]<=5) then
Street_Lamp := 1;
end_if;
end_if;

if(Data[2]>=21) then
if(Data[3]>=20 or Data[3]<=5) then
Street_Lamp := 1;
end_if;
end_if;

10,11:

if(Data[3]>=19 or Data[3]<=6) then
Street_Lamp := 1;
end_if;

12:
if(Data[2]<21) then
if(Data[3]>=19 or Data[3]<=6) then
Street_Lamp := 1;
end_if;
end_if;

if(Data[2]>=21) then
if(Data[3]>=18 or Data[3]<=7) then
Street_Lamp := 1;
end_if;
end_if;
end_case;

if (s:fs) then //初始化。
Humidity_SP_Low :=0;
Humidity_SP_High :=0;
Brightness_Bright :=0;
Brightness_Mid :=0;
Brightness_Dark :=0;
end_if;

if (Humidity_SP_Low > Humidity_SP_High) then //防止低湿度设定值高于高湿度设定值。
Humidity_SP_High := Humidity_SP_Low;
end_if;

if (Street_Lamp) then //两度调节逻辑。

if (Humidity_In > Humidity_SP_High) then
Brightness_Mid :=0;
Brightness_Dark :=0;
Brightness_Bright :=1;
end_if;
if (Humidity_SP_High > Humidity_In and Humidity_In > Humidity_SP_Low) then
Brightness_Mid :=1;
Brightness_Dark :=0;
Brightness_Bright :=0;
end_if;
if (Humidity_In < Humidity_SP_Low) then
Brightness_Mid :=0;
Brightness_Dark :=0;
Brightness_Bright :=1;
end_if;
end_if;

这是用AB编写的程序,希望对你有用。