[Return to Home Page]

ECE 445 Wiki : Topics : Interrupts

[Login]


Interrupts:

Interrupt interfacing for PIC16F877A is quite simple. Try to keep interrupts as short as possible and avoid inserting delays in your interrupts.

There are prebuilt functions that generate interrupts. An example of this would be the timer1 interrupt, which occurs every time timer1 overflows. Notice how we did not have to disable interrupts or clear the flag bit in the ISR, this is done for you automatically for some prebuilt ISRs.

This sample code essentially extends the 16 bit timer1 register by whatever type you declare variable (of_count) to be.

Example:

#int_timer1
void timer1_isr(void) 
{
of_count = of_count + 1; // increment overflow counter
set_timer1(0); // clear the timer register
}

Another example is the Int_ext interrupt. This interrupt is generated by a signal into RB0 pin 33. You can specify the trigger type: rising edge, falling edge or level transition in code. Refer to the PIC16F877A header file.

Example:
ext_int_edge(L_TO_H); // this will set the trigger to rising edge

Example:

#int_ext
void ext_isr(void)
{
disable_interrupts(int_ext); // disable ext interrupts 
calc_flag = 1; // set flag
clear_interrupt(int_ext); // clear ext interrupt bit
enable_interrupts(int_ext); // enable ext interrupts
}
// interrupt sub routines are declared at the top of your code
// space represents whatever code you might have between
//
Void main ()
{
If (calc_flag ==1)
{
// perform desired function for interrupt
Calc_flag =0; // clear flag
}


PmWiki can't process your request

Cannot acquire lockfile

We are sorry for any inconvenience.