just can't help myself
now have flashing led gpio.0 when gate in motion
Code:
CMCON=%00000111
ANSEL=%00000000

@ DEVICE pic12F675, XT_OSC
_NOCLKOUT
@ DEVICE pic12F675, WDT_ON
@ DEVICE pic12F675, PWRT_ON
@ DEVICE pic12F675, MCLR_OFF
@ DEVICE pic12F675, BOD_ON

DEFINE OSC 4
trisio= %111000
btn var gpio.3          ; assume low is active
gate_state var byte  ; 0=closed ,1= open , 2=moving
open_led var gpio.0
open_gate var gpio.1
close_gate var gpio.2
button_count var byte   ;counter to bebounce btn and ensure hold time
RUN_COUNT VAR BYTE
gpio_shadow var byte     ;shadow gpio  to eliminate rmw issues
'initialise
open_gate  = 0
close_gate = 0
gate_state = 0    ;assume closed on power up
button_count=0
gpio_shadow=0
open_led =0
RUN_COUNT=0
mainloop:
gosub Check4Button
if (button_count > 30) and (gate_state.1 != 1)  then gosub move_gate    ;has button been on for 3 seconds

IF gate_state.1=1 THEN     ;is the gate in motion
open_led =! open_led     ;flash led while gate moving 
IF   RUN_COUNT THEN    ;should the motion continue ?
RUN_COUNT = RUN_COUNT -1
ELSE
GOSUB STOP_GATE
ENDIF
ENDIF
pause 100
goto mainloop
Check4Button:        ; when  button_count gets to 30 (3seconds ) we act on gate
if btn=0 then
 button_count=button_count+1   ;if button is active add to count
else
 button_count=0    ;reset count
endif
return
 
move_gate:
pause 1000  ; not sure if this is required
gate_state.1=1  ;gate now moving
if  gate_state.0 = 0 then ;its closed so open the gate
    gpio_shadow.0=1     ;WILL SET open_led =  ON 
    gpio_shadow=gpio_shadow | 2 ; high gpio.1   Orange LED 
    ; same as gpio_shadow.1=1  if you prefer
    gate_state.0 = 1
 else       ; close the gate
    gpio_shadow=gpio_shadow | 4      'high gpio.2 Blue LED on
    ;same as gpio_shadow.2=1      if you prefer
    gate_state.0 = 0    ;show closed gate  open_led =  Off 
    gpio_shadow.0=0   ; WILL SET open_led = FF
endif
gpio=gpio_shadow   ;apply to gpio
RUN_COUNT=185;0    ;set 18.5 second timer for movement
return

STOP_GATE:
gpio_shadow=gpio_shadow & ~6   ;kill movement
;same as gpio_shadow.1=0 : gpio_shadow.2=0 if you prefer
gpio=gpio_shadow   ;apply to gpio
'while ! btn  ; wait for button release if needed
'wend
button_count=0  ;reset everything ready for next button press
gate_state.1=0; NOW no moving
return