5 Interrupts
5 Interrupts
Microcontrollers
1
PIC16 C Interrupts
• Interrupts allow an external event to initiate a control sequence that
takes priority over the current MCU activity. Typically, the interrupt
service routine (ISR) carries out some operation associated with the
port or internal device that requested the interrupt.
• Interrupts are frequently used with hardware timers, which provide
delays, timed intervals, and measurement. A time delay can be
implemented using a simple software counting loop, but this has the
Microcontrollers
3
Table 3.2 CCS C Interrupt Functions
#define INT_TBE 0x8C10 Interrupt fires when the transmit data empty
#define INT_RDA 0x8C20 Interrupt fires when the receive data available
#define INT_TIMER1 0x8C01 Interrupt fires when timer1 overflows
#define INT_TIMER2 0x8C02 Interrupt fires when timer2 overflows
#define INT_CCP1 0x8C04 Interrupt fires when capture or compare on
CCP1
#define INT_CCP2 0x8D01 Interrupt fires when capture or compare on
CCP2
#define INT_SSP 0x8C08 Transaction (read or write) has completed on
the indicated peripheral
#define INT_PSP 0x8C80 Interrupt fires when PSP data is in
#define INT_BUSCOL 0x8D08 Bus collision
#define INT_EEPROM 0x8D10 Interrupt fires when eeprom write is complete
#define INT_TIMER0 0x0B20 Interrupt fires when timer0 overflows
#define INT_COMP 0x8D40 Interrupt fires on comparator detect
6
Figure 3.3 External interrupt test hardware
Microcontrollers
Listing 3.3 External interrupt test program source code
#include "16F877A.h"
#use delay(clock=4000000)
{
int x;