Quote Originally Posted by keithv View Post
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.
ON INTERRUPT waits for the pause to complete before executing the interrupt routine. To get over this issue use short pauses in a loop. Here is a non interrupt option.

Code:
I var word
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:
   
   TOGGLE    LED 
for I = 1 to length
        pause 1
 if pushbutton = 0 then  gosub buttonpress
next        
goto main
end


buttonpress:
    
    pause 10                            'debounce switch press
    if length = 100 then  length = 500
    if length = 500 then  length = 100
        
    do while pushbutton = 0             'wait for switch to be released
        pause 5
    loop 
    
    pause 10                            'debounce switch release
    
return