three things
1. these two pieces don't have proper labels ,relying on the good nature of the compiler is probably not a good idea
open
pause 1000 'Orange LED on
high gpio.1
pause 18500
low gpio.1
goto InputButton
close
pause 1000 'Blue LED on
high gpio.2
pause 19000
low gpio.2
goto InputButton
2 spaghetti code like that is very difficult to debug or follow the logic of
3 rmw issue possibilities abound
for what its worth try it this way .it may look more complicated but it compiles to smaller code that's more predictable imo
ps not sure what you are doing with gpio.0 , if it is a sensor indicating gate open/closed or moving state you need to add it back in to the code
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= %111001
btn var gpio.3 ; assume low is active
gate_state var byte ; 0=closed ,1= open , 2=moving
open_gate var gpio.1
close_gate var gpio.2
button_count var byte ;counter to bebounce btn and ensure hold time
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
mainloop:
gosub Check4Button
if (button_count > 30) and (gate_state.1 != 1) then gosub move_gate
pause 100
goto mainloop
Check4Button:
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=gpio_shadow | 2 ; high gpio.1 Orange LED on
; 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
endif
gpio=gpio_shadow
pause 18500
gpio_shadow=gpio_shadow & !6
;same as gpio_shadow.1=0 : gpio_shadow.2=0 if you prefer
gpio=gpio_shadow
'while ! btn ; wait for button release if needed
'wend
button_count=0
gate_state.1=0
return
Bookmarks