Hi thiagoralves. Sorry about the late. I check what you said and I found the proble. The problem is when the compiler create the ".st" file. It consider diferent actions in the line 1 and 2 when "lamp" and "M0" are "seted" or "reseted".
Here the "st" code by the compiler:
PROGRAM My_Program
VAR
I0 AT %IX0.2 : BOOL;
M0 AT %MX0.0 : BOOL;
Lamp AT %QX0.1 : BOOL;
MemTest AT %QX0.2 : BOOL;
END_VAR
IF NOT(Lamp) AND M0 AND NOT(I0) THEN
Lamp := TRUE; (*set*) END_IF;
IF NOT(Lamp) AND M0 AND NOT(I0) THEN
M0 := FALSE; (*reset*) END_IF;
IF Lamp AND M0 AND NOT(I0) THEN
Lamp := FALSE; (*reset*) END_IF;
IF Lamp AND M0 AND NOT(I0) THEN
M0 := FALSE; (*reset*) END_IF;
IF NOT(M0) AND I0 THEN
M0 := TRUE; (*set*)
END_IF;
MemTest := M0;
END_PROGRAM
CONFIGURATION Config0
RESOURCE Res0 ON PLC
TASK TaskMain(INTERVAL := T#50ms,PRIORITY := 0);
PROGRAM Inst0 WITH TaskMain : My_Program;
END_RESOURCE
END_CONFIGURATION
Here the "st" file fixed by me.
PROGRAM My_Program
VAR
button AT %IX0.0 : BOOL;
M0 AT %MX0.0 : BOOL;
lamp AT %QX0.0 : BOOL;
MemTest AT %QX0.1 : BOOL;
END_VAR
IF NOT(lamp) AND M0 AND NOT(button) THEN
lamp := TRUE; (*set*)
M0 := FALSE; (*reset*)
END_IF;
IF lamp AND M0 AND NOT(button) THEN
lamp := FALSE; (*reset*)
M0 := FALSE; (*reset*)
END_IF; IF NOT(M0) AND button THEN
M0 := TRUE; (*set*)
END_IF; MemTest := M0;
END_PROGRAM
CONFIGURATION Config0
RESOURCE Res0 ON PLC
TASK TaskMain(INTERVAL := T#50ms,PRIORITY := 0);
PROGRAM Inst0 WITH TaskMain : My_Program;
END_RESOURCEEND_CONFIGURATION
And here the ladder diagram
Can you see the problem ?. Can be fixed the problem at the compiler ??.
By the way, your code work just fine, I never doubt it. But my intrigue was about why my program doesn't work. Like you said, it doesn't compile parallel output lines right.