Continue to Site

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.

[SOLVED] Multi interrupt function writing in 16F877a ,MPLAB XC

Status
Not open for further replies.

thannara123

Advanced Member level 5
Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,602
Helped
122
Reputation
244
Reaction score
116
Trophy points
1,353
Activity points
10,616
I am writing two interrupt function in MPLAB XC compailer for PIC16f877a as follows

C:
void interrupt timer_isr()      // timer Interrupt 1
{
    if(TMR2IF==1)
    {
      // function content

}



void __interrupt() adc_value(void)  // ADC Interrupt 1
    {
       if(ADIF==1)     
        // function content

    }
void main()
{
}

I tried the above code as interrupt but am getting error as follows
multiple interrupt functions (_adc and _timer_isr) defined at interrupt level 1

How can i set the priority or how to write multiple Interrupt Functions ?
 

16F877A doesn't support interrupt priority in hardware.
What you have done is written two ISRs but the compiler knows the sole interrupt vector on that device is at address 0x0004 so it can't put them both there.

The solution is to write one ISR and check the interrupt flags to find the cause or causes of interrupt. The order you check them in will decide their priority. Once you have dealt with the interrupt, clear it's flag and exit the ISR. If another interrupt is pending, the ISR will immediately be called again and this time the check will find the second cause and so on.

Brian.
 
I suggest that you also check for both the xxIF and xxIE flags.
The reason is that a module can set the xxIF flag but without the xxIE flag being set, it will not trigger the ISR.
However if ANOTHER module does trigger the ISR, then it is possible to see the xxIF flag set and therefore try to execute the code.
Of course if you always have the xxIE bit set for a module then that is not such a problem.
Personally, for the sake of an extra check, I think this is worth it - a good habit to get in to for those odd situations where you to enable and disable the xxIE bit.
Susan
 
void interrupt ISR_rutine () // For all Interrupts
{
if(TMR2IF==1)
{ // function content }

if(ADIF==1)
{// function content }
}

Is it work well
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top