Multi Interrupt with PIC

Status
Not open for further replies.

blinkstar88

New Member
Dear All,

How to do multi interrupt in Pic? any sample code are welcome. I want using usart, rb0, timer intterrupt in one time. Any idea will be aprreciated.

Thanks
 
You check the various flags of the perifials you have enabled for interrupt. Something like this in your ISR to branch to the appropriate handler:
Code:
BTFSC PIR1, TMR1IF ; Timer1 overflow interrupt?
GOTO T1_INT ; YES
BTFSC PIR1, ADIF ; A/D interrupt?
GOTO AD_INT ; YES, do A/D thing
; NO, do this for all other interrupt sources
 
Last edited:
Well there are differences among PICs here.
In PIC16, all interrupts are the same priority. The processor jumps to the top of your ISR routine any time it's NOT already running the interrupt code and any enabled flag is set. It's up to you to write code to figure out which flag is set and how to handle it and return.
In PIC18, you can do that but there is also 2 interrupt priorities you MAY choose to use. The processor will jump to the higher priority interrupt handler even if the low priority interrupt handler is already running. The opposite is not true.
In dsPIC, there is a different interrupt vector for each interrupt source, so you have to write a separate handler task for each source. Also there are a lot of different interrupt priority levels (0-7 IIRC) you can assign.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…