Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how to handle multiple interrupt in PIC using Mikro C software

Status
Not open for further replies.
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 ??
 
I can't help you with Mikro C, but in assembler and XC8 you simply check what caused the interrupt and act accordingly - presumably Mikro C allows the same?.

Like this:

Code:
void interrupt isr(void)
{ 
    if(TMR1IF)                      
    {

    }
    if(TMR2IF)                        
    {

    }
    if (IOCBF4) 
    {
       
    }
}
 
I can't help you with Mikro C, but in assembler and XC8 you simply check what caused the interrupt and act accordingly - presumably Mikro C allows the same?.

Like this:

Code:
void interrupt isr(void)
{
    if(TMR1IF)                    
    {

    }
    if(TMR2IF)                      
    {

    }
    if (IOCBF4)
    {
     
    }
}

this is polling method right??
then how it is called interrupt?
isn't there any vector table or number to call each interrupt routine? like in 8051
 
In the pic you have several registers..... PIR and PIE to name two..

One is Peripheral Interrupt Request and the other Peripheral Interrupt Enable..

If an interrupt is enabled then the interrupt flag is set and vector 0x04 is called.... When you create an interrupt function in C.. The compiler places the address of the function for you... You can then look at each flag to see which has fired the interrupt..

So if you set the timer 1 interrupt..

TMR1IE_bit = 1; and clear the Flag TMR1IF_bit = 0;
Turn on the timer .. TMR1ON_bit = 1;

Then the interrupt code will be executed when the timer spill over
In your interrupt routine do this..

if(TMR1IF_bit == 1)
do stuff;
TMR1IF_bit = 0;
 
this is polling method right??
then how it is called interrupt?
isn't there any vector table or number to call each interrupt routine? like in 8051

There's only a single interrupt vector in low and mid range PIC's, they are RISC processors, and there's no need for separate vectors.

And no, it's not polling, it's merely selecting code based on what caused the interrupt, not really any different to having separate vectors.
 
It is much simpler to look at all the inputs on a regular basis.

Make sure the data on the inputs is present for a period of time so you don't miss it.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top