Using both hardware int and Timer Int together?


Closed Thread
Results 1 to 4 of 4
  1. #1

    Default Using both hardware int and Timer Int together?

    Howdy

    Is it possible to use both a hardware interrupt (from PORTB.0 and another from Timer0) using the same interrupt service routine?
    I am using a hardware interrupt based on an external event triggering PORTB.0, and also want to use a timer interrupt, within some other un-related code. If I use the same interrupt handler, and on entry check a flag to see which interrupt caused it, then jump to the related routine, and then use the same exit point, will that work? Or does one somehow write two separate interrupt handlers? That does not seem possible - but then I'm just starting to use interrupts.

    I have done some searching but have not found an answer.

    Ken

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    If you use DT_INTS you can have a label name for each interrupt source. If you do it on
    your own, just check interrupt flag bits in the interrupt service routine, and then jump to
    the appropriate interrupt handler with a RETFIE at the end.

    If you're using ON INTERRUPT, I recommend you do everything in a single interrupt handler.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Thanks Bruce

    I am using PBP ON INTERRUPT for the PORTB.0 interrupt

    Would this work?



    ON INTERRUPT GOTO myint ' Define interrupt handler

    INTCON = %10110000 ' enable both RB0 and Timer 0 INTS

    loop:
    Goto loop ' Normal program would be here


    DISABLE ' No interrupts past this point

    myint:

    IF INTCON.1 = 1 THEN RB0_INT 'Go to the PORTB.0 Int Routine


    '********************
    '''' THE TIMER INTERRUPT ROUTINE WOULD BE HERE
    '''''''''''''''''''''

    GOTO INTDONE
    '*****************************


    RB0_INT:
    ''''' NORMAL PORTB.0 ROUTINE
    ''''

    INTDONE:

    INTCON.1 = 0 ' Clear interrupt flag
    INTCON.2 = 0 'Clear Timer 0 overflow

    RESUME ' Return to main program
    ENABLE

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Ken,

    Looks fine to me.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Understanding timer issues
    By boroko in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th April 2009, 03:56
  2. help: TMR0 interrupts disabling PORTAchange interrupts???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2008, 16:10
  3. Newb timer problems
    By George in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 7th November 2007, 02:48
  4. Interrupt/timer not really interrupting...
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd May 2005, 23:05
  5. Timer Accuracy
    By GEEZER in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 31st March 2005, 06:26

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