Interrupts 1
Interrupts 1
MODULE III
CONVERTER
Interrupts in PIC 16F877A - INTCON Register - Option Register - Interrupt
Sources - PIE and PIR registers - Enabling Interrupts - Peripheral Interrupts -
Interrupt Service Routine (ISR). - On-Chip Analog-to-Digital Converter (ADC)
block diagram - PIC16F877A ADC pins - ADC Configuration- ADC PORT
configuration - ADC Channel Selection – ADC voltage reference selection -
Resolution - ADC conversion clock source - Interrupt control - ADC result
format - ADC Registers: ADCON0 and ADCON1 - Sample Interrupt Codes in
MikroC.
INTERRUPTS
1. Interrupt means stop the continuous progress of (an
activity or process).
2. It will stop the process which is running currently and
then execute the process in ISR.
3. So it is a signal which may be disturbed or alter the
sequence of execution of the processor.
4. In other words, An interrupt is a signal to the
processor emitted by hardware or software indicating
an event that needs immediate attention.
5. ISR means Interrupt Service Routine. Whenever
an interrupt occurs, the controller completes the
execution of the current instruction and starts the
execution of an Interrupt Service Routine (ISR)
or Interrupt Handler.
Program Execution With Interrupts
In this method, it will execute the main
function. When an interrupt signal comes, it
will stop the main function execution and
suddenly it will go to the ISR function and
executes that. After execution of ISR and again
it will come to the main function.
Types of Interrupts
Interrupts have the highest priority than other signals, basic
type of interrupts are,
1. Hardware Interrupts
2. Software Interrupts
Hardware Interrupts
If the interrupt is coming from hardware or external
devices, it is called Hardware Interrupt. For example:
from the keyboard we will press the key to do some
action this pressing of a key on the keyboard will
generate a signal which is given to the processor to do
action, such interrupts are called hardware interrupts.
Software Interrupts
The interrupts which are caused by the software
instructions are called software instructions.
Interrupt Latency
When an interrupt occurs, the service of the interrupt
by executing the ISR may not start immediately by
context switching.
The time interval between the occurrence of interrupt
and the start of execution of the ISR is called interrupt
latency.
PIC 16F877A has the following 15 interrupt sources :
External
Timer 0 In this tutorial,
Timer 1 we will see
RB Port Change
USART Interrupts,
Parallel Slave Port Read/Write
A/D Converter Timer Interrupts,
USART Receive External Interrupts.
USART Transmit
Synchronous Serial Port
CCP1 (Capture, Compare, PWM)
CCP2 (Capture, Compare, PWM)
TMR2 to PR2 Match
Comparator
EEPROM Write Operation
Bus Collision
Registers Used for Interrupts
INTCON
OPTION_REG
PIE1
PIR1
PIE2
PIR2
INTCON Register
The INTCON register is a readable and writable register,
which contains various enable and flag bits for the
TMR0 register overflow, RB port change and external
RB0/INT pin interrupt.
bit 7:
GIE: The Global Interrupt Enable bit is like the master
switch for all the different interrupts.
SETTING this bit will enable all the interrupts to function,
CLEARING this bit will disable ALL interrupts.
1 = Enables all un-masked interrupts
0 = Disables all interrupts
PIE2 Register
The PIE2 register contains the individual enable bits for the CCP2
peripheral interrupt, the SSP bus collision interrupts, EEPROM
writes operation interrupt, and the comparator interrupt.
• LED – RD0
Switch – RB0
Whenever anyone of the RB4, RB5, RB6, RB7 state
changes, Interrupt will happen. In ISR, toggling the LED
in PORTD.
A push button switch is connected to the External
Interrupt pin INT of the PIC Microcontroller.
When this button is pressed, the microcontroller is
interrupted and the ISR is executed.
The ISR toggles the status of PORTC for 1 second.