The code below blinks an LED on and off at two different rates. It switches between the two rates when a button is pressed. The button is connected to GPIO.1 of a PIC12F609.
The code works fine, or I should say, it works exactly as I expect it to. The problem is that I would like the program to jump to the "buttonpress" subroutine as soon as the as the button makes GPIO.1 go low. As it is now, it needs to wait for the LED to finish its blink loop before it will recognize the button.
Is an ON INTERRUPT statement what I want to use here? I've tried using it, but I don't think I'm setting it up correctly.
Code:
length var word
LED var GPIO.0
pushbutton var GPIO.1
ANSEL = 0 ' Set all digital
CMCON0 = 0 ' Analog comparators off
TRISIO = %00000010
length = 100
main:
do
LED = 1
pause length
LED = 0
pause length
if pushbutton = 0 then
goto buttonpress
endif
loop
goto main
end
buttonpress:
pause 10 'debounce switch press
if length = 100 then
length = 500
elseif length = 500 then
length = 100
endif
do while pushbutton = 0 'wait for switch to be released
pause 5
loop
pause 10 'debounce switch release
goto main
Bookmarks