Jump to content
Sign in to follow this  
fyndor

Multiple interrupt routines?

Recommended Posts

I have a PIC16F877A and I want to be able to setup two or more interrupt service routines (ISRs) for different interrupts.  For example, one for each of the 3 timers in the 16F877A.  Is there some #int_blah or #pragma command to do this.  I know that in a Motorola 6812 there are vectors where you store the pointer to each of the different ISR functions available on the chip.  I assume PICs have the same kind of thing or do all the service routines call the same function.  Were would I find a list of all of the different # commands that the C2C compiler uses?

Share this post


Link to post
Share on other sites

Hi Fyndor,

 

 

When the interrupt occurs, the CPU will always jump to address 0x04, this is fixed by the chip and can't be changed,

you could if you wanted to, jump from there to anywhere in the memory, but interrupts need to happen quickly so this isn't recommended.

 

Once you are in the routine, it's advisable to save at least the STATUS and W registers, and retrieve them when you exit the interrupt service routine - after all, you can't be sure what was happening when the interrupt occurred (usually).

 

When you are in th interrupt service routine, you can check the INTCON register (0x0B from any memory bank) to see what caused the interrupt.

 

The main INTCON bits are:

Bit 2 --- TMR0IF --- Timer 0 has overflowed - you must reset this yourself in the interrupt service routine.

Bit 1 --- INTF   --- RBO/INT external interrupt occurred - you must reset this yourself in the interrupt service routine.

Bit 0 --- RBIF   --- RB Port change interrupt  - one of the portB bit 7.. Bit 4 lines has changed state (1 to 0 or 0 to 1)

 

 

The other timers are set/checked in PIE1, PIR1. PIE2, PIR2, and PCON registers.

 

** NOTE **

Even if you don't have interrupts set, the registers above will have the flags set when something that would cause an interrupt (if they were enabled) happens. You will have to clear all of the interrupt flags before you enable interrupts, otherwise the PIc will think that everything has happened at once...

 

A fully detailed description of the interrupt registers is in the PIC1687XA manual from microchip's website, but if you need more info, drop another message here.

 

Regards

Jim

Share this post


Link to post
Share on other sites

You can not have 2 different ISRs on this chip.  The 18 series chips hava a high priority and low priority interrupt that can have 2 different vectors.

 

With 1 ISR you can do something like this:

 

void interrupt( void )
{
   if ( //check to see if souce was timer 0)
   {
   }
   else if ( //check to se if source was RBIF)
   {
   }
   else if ( //check to see if source was INTF)
   {
   }
   else  //it was a false alarm, or no code implemented

}

 

and you can order your if-else statemtns in the priority that you want to check.

 

-Ryan

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...