How to work with External (Hardware) Interrupts of PIC18F4550

Interrupts are special events that require immediate attention. They cause the processor to cease the running task to serve a special task for which the interrupt event had occurred. After the special task is over, the processor resumes performing the original task.

Interrupts of PIC

The processor can also serve these events by polling method. But polling is an inefficient technique as compared to interrupts. In the polling method, the processor has to continuously wait for the event signal. Thus it always remains busy using extra resources. To understand the difference between polling and interrupts well, refer introductory paragraphs of 8051 Interrupts.
This article is based on PIC18F4550 microcontroller’s interrupt system. The configuration and implementation of PIC Hardware Interrupts are explained here.

A PIC microcontroller consists of both software and hardware generated interrupts. The hardware interrupts are produced by external hardware at certain pins of the microcontroller. The software interrupts, on the other hand, are generated by internal peripherals of the controller. This software interrupt helps the programmer to use more than one internal peripheral in single application and serve them individually when they respond.

Following is an example to illustrate the interrupts better. Suppose a programmer wants to make a real time watch which shows ambient temperature as well. The programmer has to use two internal peripherals of the controller, namely, a Timer and an ADC channel. Consider this project without using interrupt : the programmer has to take care of both peripherals one by one continuously by polling them. This is not an efficient way of programming.
In Interrupt method, the controller serves the Timer when it overflows and the ADC when the A/D (analog to digital) conversion is done. Along with these, the microcontroller can also perform other tasks, like displaying some text on LCD. Therefore use of interrupt makes the program more efficient and logical.
When an Interrupt occurs in a PIC Microcontroller, the program execution gets transferred to a predefined Interrupt Vector Address from where the processor gets what operations to perform in for a particular interrupt occurrence. The detailed working of interrupts can also be studied from 8051 Interrupts or AVR Interrupts.
Interrupts in PIC18F4550:
PIC18F4550 has following internal and external interrupts:

Β·Β Β Β Β Β Β Β Β  Reset, Brown-Out Reset, Watch-dog Reset, Power On Reset

Β·Β Β Β Β Β Β Β Β  External Interrupt 0 (INT0)

Β·Β Β Β Β Β Β Β Β  External Interrupt 1 (INT1)

Β·Β Β Β Β Β Β Β Β  External Interrupt 2 (INT2)

Β·Β Β Β Β Β Β Β Β  Timer 0 Interrupt

Β·Β Β Β Β Β Β Β Β  Timer 1 Interrupt

Β·Β Β Β Β Β Β Β Β  Timer 2 Interrupt

Β·Β Β Β Β Β Β Β Β  Timer 3 Interrupt

Β·Β Β Β Β Β Β Β Β  ADC Interrupt

Β·Β Β Β Β Β Β Β Β  Analog Comparator Interrupt

Β·Β Β Β Β Β Β Β Β  RB Port change Enable Interrupt

Β·Β Β Β Β Β Β Β Β  Streaming Parallel Port Read/Write Interrupt

Β·Β Β Β Β Β Β Β Β  EUSART Receive Interrupt

Β·Β Β Β Β Β Β Β Β  EUSART Transmit Interrupt

Β·Β Β Β Β Β Β Β Β  Master Synchronous Serial Port Interrupt

Β·Β Β Β Β Β Β Β Β  CCP1 Interrupt (Capture, Compare, PWM)

Β·Β Β Β Β Β Β Β Β  Oscillator Fail Interrupt

Β·Β Β Β Β Β Β Β Β  USB Interrupt

Β·Β Β Β Β Β Β Β Β  Data EEPROM/Flash Write Operation Interrupt

Β·Β Β Β Β Β Β Β Β  Bus Collision Interrupt

Β·Β Β Β Β Β Β Β Β  High/Low-Voltage Detect Interrupt

Β·Β Β Β Β Β Β Β Β  CCP2 Interrupt

A total of 10 registers are used to control the interrupt operation in PIC18F4550 which are as follows:

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.