Simple Interrupt Program


Closed Thread
Results 1 to 6 of 6
  1. #1
    eoasap's Avatar
    eoasap Guest

    Default Simple Interrupt Program

    hi everyone. I wrote a program that displays text to an LCD screen (lets say print the screen, wait a second, repeat about 10 times).

    On portB.0 (int) on PIC16F84 i have a pushbutton that counts the # of button presses (continued from a different question i had earlier). The hardware is setup properly because i have used it to count & display the results in the MAIN code.

    What i'm trying to do is setup an interrupt where when a button is pressed, i'll go to my interrupt code, increment the counter (# of button presses), display the # of button presses to the LCD and then resume the rest of the program.

    Here is mthe relevant code so far.


    __________________________________________________ ____________
    'Definitions
    symbol LED = PORTB.1
    PushButton var PORTB.0

    OPTION_REG = $7f 'enable PORTB pullups
    INTCON = %10010000 'enable RB0 interrupt
    TRISB=%00000001
    CounterA=0 'set count value to zero
    on interrupt goto myint 'define interrupt handle

    {
    main code
    }


    'interrupt handling
    disable 'disable interrupts while in interrupt
    myint: 'counts & displays a message if there's a button pressed

    CounterA=CounterA+1
    Lcdout $fe, 1, "Button Presses =" ' Clear LCD screen
    Lcdout $FE, $c0, #CounterA
    While Pushbutton=0:Wend

    INTCON.1 = 0 'clear interrupt flag
    resume 'return to main program
    Enable 'enables the interrupt after handler
    __________________________________________________ ___________

    As of right now this is what happens. if i leave the pushbutton alone, it'll run the program normally. if i press the button, it just restarts the entire sequence of code. kind of like it acknowledges the interrupt, but then doesn't do my interrupt code (or even return to the proper place where i was in the code before the interrupt). I even put END instead of RESUME at the end of the interrupt but all that happens is it starts the program over when i hit the pushbutton.

    Any ideas what i'm doing wrong?
    Glenn

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
    OPTION_REG = $7f 'enable PORTB pullups
    OK you enable the internal Pull-ups, so your interrupt should happen on a Falling Edge right?

    what about
    Code:
    OPTION_REG=%00111111
    maybe also safe to add a PAUSE 20-50 after the WHILE:WEND to debounce the PB contact.
    Last edited by mister_e; - 15th October 2005 at 16:42.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    eoasap's Avatar
    eoasap Guest


    Did you find this post helpful? Yes | No

    Default

    ok, got it working! Thanks Steve. also added the pause and added a capacitor across the pushbutton to create an RC time constant and deal with the debounce.

    You guys are so helpful on here!

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    you're welcome.

    Actually you don't need the capacitor, the debounce is done by software.

    Usually i choose 50mS as debounce delay.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    arthurok's Avatar
    arthurok Guest


    Did you find this post helpful? Yes | No

    Default capacitor

    if you are scanning switches the capacitor dosent slow down your program "pauses and "button" command debouncing does.

    some engineer told me many years ago the computer does as its told you are its master and superior

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    sure! but we talk about <50msec... even <20mSec. it's also depend what else your program is doing and how your program is done. Interrupt can happen really fast on some software.. slower on other. Always case by case.

    PushButtons aren't 0-1 signal... still present some odd result when releasing them.

    By software: We just check and insert a safe delay prior to return to the main program.

    By using capacitor: it just smooth the signal when releasing the switch... the old CMOS-TTL-...-.... to do it. I prefer the software method in many case. No additional parts and even if you have the most crapy switch in the world, you just need to modify 1 code line OR constant variable. Handy with some tact switches brand...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  2. USART interrupt in PIC16F877A
    By amindzo in forum General
    Replies: 7
    Last Post: - 26th August 2006, 18:51
  3. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59
  4. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 1

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