you could do this but ..............
a big if

is the portd.7 signal is a limit switch or an emergency stop switch ?... if it is then its best done in hardware a hung loop here could cause fire/smoke/damage or hurt


'-----------------------OPEN WINDOW ------------------------------------------------------
IF BUTTON_STATE[2] THEN
IF BUTTON_STATE[2] >4 then
if PORTD.7 ==0 then
PORTD.0=1
else
PORTD.0=0
endif
else
PORTD.0=0
BUTTON_STATE[2]=0
endif
endif