PDA

View Full Version : Using both hardware int and Timer Int together?



ozarkshermit
- 5th January 2010, 21:28
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

Bruce
- 5th January 2010, 22:14
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.

ozarkshermit
- 5th January 2010, 23:52
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

Bruce
- 6th January 2010, 01:09
Hi Ken,

Looks fine to me.