how to use INTERRUPT?


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: how to use INTERRUPT?

    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

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: how to use INTERRUPT?

    Quote Originally Posted by EarlyBird2 View Post
    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.
    Thanks! That does solve my immediate problem, but I'm planning on doing more complex stuff with the "length" var. Ultimately, I want the LED to continue blinking uninterrupted while the button is being pressed. I'm doing it one piece at a time, but ultimately the blinking LED will be in sync with a PWM, and the button will be a tap tempo to control the frequency of the PWM. The DT Instant Interrupts looks to be exactly what I need for this project. It's got the button. It's got the LED. ANd it's got the timer.
    Last edited by keithv; - 8th August 2014 at 18:14.

Similar Threads

  1. Interrupt
    By gunayburak in forum General
    Replies: 1
    Last Post: - 26th December 2012, 06:19
  2. Need help with interrupt
    By mbox in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 24th August 2010, 16:48
  3. RX interrupt
    By Arciure in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 5th March 2010, 17:23
  4. I need help with Interrupt
    By wildbilly in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st September 2007, 19:16
  5. Replies: 0
    Last Post: - 27th August 2004, 07:20

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts