0% found this document useful (0 votes)
54 views

5 Interrupts

The document discusses PIC16 C interrupts. It describes how interrupts allow an external event to initiate a control sequence that takes priority over the current microcontroller activity. Interrupts are frequently used with hardware timers to implement timed delays and intervals. The interrupt has to be initialized at the top of the program. The PIC16F87XA family has up to 15 sources of interrupt. It also provides functions for enabling, disabling, and clearing interrupts.

Uploaded by

Tam Pham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

5 Interrupts

The document discusses PIC16 C interrupts. It describes how interrupts allow an external event to initiate a control sequence that takes priority over the current microcontroller activity. Interrupts are frequently used with hardware timers to implement timed delays and intervals. The interrupt has to be initialized at the top of the program. The PIC16F87XA family has up to 15 sources of interrupt. It also provides functions for enabling, disabling, and clearing interrupts.

Uploaded by

Tam Pham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

PIC16 C 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

disadvantage of tying up the processor while the delay executes. A


more efficient technique is to use a hardware timer running
independently from the MCU clock. This allows accurate timing to be
more easily achieved, and the timer can run concurrently with some
other task. A time-out interrupt informs the MCU that the timer interval
has expired and the ISR can implement the required action.
• The interrupt has to be initialized for use at the top of the program
• The PIC16F87XA family has up to 15 sources of interrupt.
2
INTERRUPT LOGIC
GIE: Global Interrupt Enable bit,
PEIE: Peripheral Interrupt Enable bit,

1) RBIE: RB Port Change Interrupt Enable bit,


2) INTE: RB0/INT External Interrupt Enable bit,
3) TMR0IE: TMR0 Overflow Interrupt Enable bit,
Microcontrollers

4) EEIE: EEPROM Write Operation Interrupt Enable bit,


5) PSPIE: Parallel Slave Port Read/Write Interrupt Enable bit,
6) ADIE: A/D Converter Interrupt Enable bit,
7) RCIE: USART Receive Interrupt Enable bit,
8) TXIE: USART Transmit Interrupt Enable bit,
9) SSPIE: Synchronous Serial Port Interrupt Enable bit,
10) CCP1IE: CCP1 Interrupt Enable bit,
11) TMR2IE: TMR2 to PR2 Match Interrupt Enable bit,
12) TMR1IE: TMR1 Overflow Interrupt Enable bit,
13) BCLIE: Bus Collision Interrupt Enable bit,
14) CCP2IE: CCP2 Interrupt Enable bit
15) CMIE: Comparator Interrupt Enable bit.

3
Table 3.2 CCS C Interrupt Functions

Label Operation Syntax Example

INTERRUPT CLEAR Clears peripheral interrupt clear_interrupt(int_timer0);

INTERRUPT DISABLE Disables peripheral interrupt disable_interrupts(int_timer0);


Microcontrollers

INTERRUPT ENABLE Enables peripheral interrupt enable_interrupts(int_timer0);

INTERRUPT ACTIVE Checks if interrupt flag set interrupt_active(int_timer0);

INTERRUPT EDGE Selects interrupt trigger edge ext_int_edge(H_TO_L);

INTERRUPT JUMP Jump to address of ISR jump_to_isr(isr_loc);


Tables 3.3 & 3.4 PIC 16F877 Interrupt Sources

INTERUPT REGISTER INTERRUPT


LABEL CODE SOURCE
INT_EXT 0x0B10 External interrupt has been detected

INT_RB 0x0B08 Change on Port B has been detected

INT_RTCC 0x0B20 Timer 0 has overflowed (same as TIMER0

INT_TIMER0 0x0B20 Timer 0 has overflowed (same as RTCC)

INT_TIMER1 0x8C10 Timer 1 has overflowed


Microcontrollers

INT_CCP1 0x8C04 Timer 1 matches preset value?

INT_TIMER2 0x8C02 Timer 2 has overflowed

INT_CCP2 0x8D01 Timer 2 matches preset value?

INT_AD 0x8C40 Analogue to digital converter has finished

INT_SSP 0x8C08 Serial data has been received

INT_PSP 0x8C80 Data ready at parallel serial port

INT_EEPROM 0x8D10 Data EEPROM write completed


Tables 3.3 & 3.4 PIC 16F877A Interrupt Sources
// Constants used in EXT_INT_EDGE() are:
#define L_TO_H 0x40
#define H_TO_L 0
// Constants used in ENABLE/DISABLE_INTERRUPTS() are:

#define GLOBAL 0x0BC0 enable_interrupts(GLOBAL); //enables global


interrupts
enable_interrupts(INT_COMP); //enables the
comparator interrupt
#define INT_RTCC 0x0B20 Timer 0 (RTCC) overflow
#define INT_RB 0xFF0B08 Port B any change on B4-B7
#define INT_EXT 0x0B10 External interrupt
#define INT_AD 0x8C40 Interrupt fires when a/d conversion is complete
Microcontrollers

#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

// INTEXT.C MPB 10-4-07


// Demo external interrupt RB0 low interrupts foreground output count

#include "16F877A.h"
#use delay(clock=4000000)

#int_ext // Interrupt name


void isrext() // Interrupt service routine name
{ output_D(255); // ISR action
delay_ms(1000);
}

void main() //**************************************************************


Microcontrollers

{
int x;

enable_interrupts(int_ext); // Enable named interrupt


enable_interrupts(global); // Enable all interrupts
ext_int_edge(H_TO_L); // Interrupt signal polarity

while(1) // Foreground loop


{
output_D(x); x++;
delay_ms(100);
}
}
Microcontrollers

You might also like