laitimes

Siemens S7-1200 CPU program case, very detailed!

author:Technical training

Example: Traffic light

Design traffic light PLC control system, control requirements:

1) East-west: green light for 5 seconds, green light flashes 3 times (off 0.5 seconds for 0.5 seconds), yellow light for 2 seconds, red light for 10 seconds.

2) North-south: red light for 10 seconds, green light for 5 seconds, green light flashes 3 times, yellow light for 2 seconds.

3) Press to start normal operation, press to stop and wait for the whole process to stop, and then the two-way yellow light flashes (off for 0.5 seconds, on for 0.5 seconds).

Case Operation Diagram:

Siemens S7-1200 CPU program case, very detailed!

Case program: The first way to write: SCL programming language is written in a process method (process: project program execution steps)

1. Variables

Siemens S7-1200 CPU program case, very detailed!

Written in FB blocks, the variables are built under the Static option of the background block of FB

2. Procedure

Start OR Stop

#R_TRIG_Instance(CLK:=#启动);

IF #R_TRIG_Instance.Q AND #流程=0 THEN

#流程 := 1;

#停止标志 :=#停止:= 0;

#东西黄灯 := #南北黄灯 := 0;

END_IF;

#R_TRIG_Instance_1(CLK:=#停止);

IF #R_TRIG_Instance_1.Q THEN

#停止标志 := 1;

#启动 := 0;

END_IF;

The green light is on for 5s

IF #流程 = 1 THEN

#南北红灯 := #东西绿灯 := 1;

END_IF;

#T0(IN:=#流程 = 1,

PT:=T#5S);

IF #T0. Q THEN

#流程 := 2;

END_IF;

The green light flashes 3 times

IF #流程 = 2 THEN

#东西绿灯 :=0;

END_IF;

#T1(IN:=#流程 = 2,

PT:=T#0.5S);

IF #T1. Q THEN

#东西绿灯 := 1;

END_IF;

#T2(IN:=#T1. Q,

PT:=T#0.5S);

IF #T2. Q THEN

RESET_TIMER(#T1);

#东西绿灯闪3次 += 1;

END_IF;

IF #东西绿灯闪3次>=3 THEN

#流程 := 3;

#东西绿灯 := 0;

#东西绿灯闪3次 := 0;

END_IF;

The yellow light is on for 2s

IF #流程 = 3 THEN

#东西黄灯 := 1;

END_IF;

#T3(IN:=#流程 = 3,

PT:=T#2S);

IF #T3. Q THEN

#东西黄灯 :=0;

#南北红灯 := 0;

#流程 := 4;

END_IF;

The green light in the north and south is on for 5s

IF #流程 = 4 THEN

#东西红灯 := #南北绿灯 := 1;

END_IF;

#T4(IN := #流程 = 4,

PT := T#5S);

IF #T4. Q THEN

#流程 := 5;

END_IF;

The green light flashes 3 times in the north and south

IF #流程 = 5 THEN

#南北绿灯 := 0;

END_IF;

#T5(IN := #流程 = 5,

PT := T#0.5S);

IF #T5. Q THEN

#南北绿灯 := 1;

END_IF;

#T6(IN := #T5. Q,

PT := T#0.5S);

IF #T6. Q THEN

RESET_TIMER(#T5);

#南北绿灯闪3次 += 1;

END_IF;

IF #南北绿灯闪3次 >= 3 THEN

#流程 := 6;

#南北绿灯 := 0;

#南北绿灯闪3次 := 0;

END_IF;

The yellow light in the north and south is on for 2s

IF #流程 = 6 THEN

#南北黄灯 := 1;

END_IF;

#T7(IN := #流程 = 6,

PT := T#2S);

IF #T7. Q THEN

#南北黄灯 := 0;

#东西红灯 := 0;

#流程 := 7;

END_IF;

Cycle OR stops

IF #流程 = 7 AND NOT #停止标志 THEN

#流程 := 1;

END_IF;

IF #流程 = 7 AND #停止标志 THEN

#流程 := 0;

END_IF;

Yellow light flashes in both directions

IF #流程 = 0 AND #停止标志 THEN

#东西黄灯 := #南北黄灯 := 0;

END_IF;

#T8(IN:=#流程 = 0 AND #停止标志,

PT:=T#0.5S);

IF #T8. Q THEN

#东西黄灯 := #南北黄灯 := 1;

END_IF;

#T9(IN:=#T8. Q,

PT:=T#0.5S);

IF #T9. Q THEN

RESET_TIMER(#T8);

END_IF;

The second way to write it: The SCL programming language is written using comparative instructions

1. Variables

Siemens S7-1200 CPU program case, very detailed!

Written in FB blocks, the variables are built under the Static option of the background block of FB

2. Procedure

#R_TRIG_Instance(CLK:=#启动);

IF #R_TRIG_Instance.Q THEN

#启动标志 := 1;

#双黄闪标志 :=#停止:= 0;

END_IF;

#R_TRIG_Instance_1(CLK:=#停止);

IF #R_TRIG_Instance_1.Q THEN

#停止标志 := 1;

#启动 := 0;

END_IF;

#T0(IN:=#启动标志,

PT:=T#20S);

#南北红灯 := T#0S < #T0.ET AND #T0.ET <= T#10S;

#东西红灯 := T#10S < #T0.ET AND #T0.ET <= T#20S;

#东西绿灯 := (T#0S < #T0.ET AND #T0.ET <= T#5S)OR(T#5.5S < #T0.ET AND #T0.ET <= T#6S) OR(T#6.5S < #T0.ET AND #T0.ET <= T#7S) OR(T#7.5S < #T0.ET AND #T0.ET <= T#8S);

#南北绿灯 := (T#10S < #T0.ET AND #T0.ET <= T#15S) OR(T#15.5S < #T0.ET AND #T0.ET <= T#16S) OR(T#16.5S < #T0.ET AND #T0.ET <= T#17S) OR(T#17.5S < #T0.ET AND #T0.ET <= T#18S);

#东西黄灯 := (T#8S < #T0.ET AND #T0.ET <= T#10S) OR (T#0.5S < #T1.ET AND #T1.ET <= T#1S);

#南北黄灯 := (T#18S < #T0.ET AND #T0.ET <= T#20S)OR (T#0.5S < #T1.ET AND #T1.ET <= T#1S);

IF #T0. Q AND NOT #停止标志 THEN

RESET_TIMER(#T0);

END_IF;

IF #T0. Q AND #停止标志 THEN

#启动标志 := 0;

#双黄闪标志 := 1;

#停止标志 := 0;

END_IF;

#T1(IN:=#双黄闪标志,

PT:=T#1S);

IF #T1. Q THEN

RESET_TIMER(#T1);

END_IF;

The third way to write it: the LAD (ladder diagram) programming language is written in a flow way

1. Variables

Siemens S7-1200 CPU program case, very detailed!

Written in FC blocks, variables are built in DB blocks.

2. Procedure:

LAD Programming Overview:

Siemens S7-1200 CPU program case, very detailed!

Programming details for each segment:

Siemens S7-1200 CPU program case, very detailed!
Siemens S7-1200 CPU program case, very detailed!
Siemens S7-1200 CPU program case, very detailed!
Siemens S7-1200 CPU program case, very detailed!
Siemens S7-1200 CPU program case, very detailed!
Siemens S7-1200 CPU program case, very detailed!
Siemens S7-1200 CPU program case, very detailed!
Siemens S7-1200 CPU program case, very detailed!
Siemens S7-1200 CPU program case, very detailed!
Siemens S7-1200 CPU program case, very detailed!
Siemens S7-1200 CPU program case, very detailed!

The case is for reference only!

Disclaimer: This article is transferred from the Internet, the copyright belongs to the original author, if it involves the copyright of the work, please contact us to delete it in time, thank you

Siemens S7-1200 CPU program case, very detailed!

Read on