Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] how to handle multiple interrupt in PIC using Mikro C software

Status
Not open for further replies.

phrbob93

Member level 1
Joined
Mar 28, 2014
Messages
38
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Location
Jalandhar, punjab
Activity points
343
here i am programming PIC16F877a Micro controller for interrupt
i did a program of handling external Interrupt and it is working correct, for the service routine of External interrupt i was instructed to add a ISR function(can be of any name) with interrupt keyword,
for e.g. i use
void interrupt external(void) // interrupt keyword followed by any name for function
{
//ISR code.............
}

now i want to do a program in which there are multiple interrupt lets say i want to program external interrupt and timer interrupt in the same program..
for that i will use
void interrupt timer(void){
//ISR code.............
}

so my question is how compiler will distinguish between timer ISR function and external ISR function ??
 

ernpao

Advanced Member level 4
Joined
Sep 16, 2010
Messages
100
Helped
26
Reputation
52
Reaction score
24
Trophy points
1,298
Activity points
2,043
You usually have only one isr function and you check the interrupt flags individually to see which interrupt was triggered:

void interrupt(){
//An interrupt was triggered

if(INT0IF == 1){//Check if external interrupt event occured
// place code for handling INT0 interrupt here and clear interrupt flag
}

if(T2IF == 1){//check if TMR2 caused the interrupt
// place code for handling TMR2 interrupt here and clear interrupt flag
}

//Exit ISR
}
 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
184
Reputation
368
Reaction score
180
Trophy points
1,323
Activity points
6,138
so my question is how compiler will distinguish between timer ISR function and external ISR function ??

For ISR there is different interrupt vector handler for different interrupts you can check in its header file.
 

ernpao

Advanced Member level 4
Joined
Sep 16, 2010
Messages
100
Helped
26
Reputation
52
Reaction score
24
Trophy points
1,298
Activity points
2,043
For ISR there is different interrupt vector handler for different interrupts you can check in its header file.

Correct me if I am wrong, but I don't think mikroc for pic16 has multiple handlers/identifiers for different interrupts and doesn't pic16 have only one interrupt vector? (He probably won't find isr vector defs in the device's header file)

In mikroC you can proably define multiple interrupt functions using the interrupt keyword, but you will probably have to check the interrupt flags to indentify which interrupt to service.
 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
184
Reputation
368
Reaction score
180
Trophy points
1,323
Activity points
6,138
  • Like
Reactions: ernpao

    ernpao

    Points: 2
    Helpful Answer Positive Rating

andre_teprom

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,236
Helped
1,151
Reputation
2,321
Reaction score
1,127
Trophy points
1,403
Location
Brazil
Activity points
53,763
Although the original question has been already properly answered, a point that deserves some attention when dealing with multiple interrupts is related to the need of routine perform the treatment efficiently, being necessary to get out of the interrupt vector as quick as possible, in order to avoid that other interrupt events goes unnoticed.
 
  • Like
Reactions: ud23

    ud23

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top