Login

Lost your password?
Don't have an account? Sign Up

Configuring Interrupt of PIC18F4550

Interrupts are one of the most powerful features of microcontrollers – they allow your system to respond immediately to important events like a button press, timer overflow, or received data, without continuously polling for changes. In this post, you’ll learn how to configure and handle an interrupt in PIC18F4550 microcontroller using MPLAB X IDE and the XC8 compiler through a simple LED blinking on an external interrupt example.

Goal: By the end, you’ll know how to enable, configure, and write ISR (Interrupt Service Routine) functions that make your embedded systems more responsive and efficient.

An interrupt is a signal that temporarily stops the normal execution of your main program to run a special function called the Interrupt Service Routine (ISR).

For example, if your PIC is busy running code and a button connected to an external interrupt pin is pressed — the microcontroller pauses the main loop, executes the ISR, and then resumes normal operation.

The PIC18F4550 supports:

  • External Interrupts (INT0, INT1, INT2)
  • Peripheral Interrupts (like UART, ADC, Timer, CCP, etc.)
  • Timer Interrupts
  • USB and Special Event Triggers

Each interrupt has:

  • Enable bit – turns it ON/OFF
  • Flag bit – indicates if it occurred
  • Priority bit – decides high or low priority
  • Connect a push button to RB0 (INT0) pin.
  • Connect an LED to PORTD (RD0) with a 330Ī© resistor.
  • When the button is pressed → the LED toggles using an interrupt.
#include <xc.h>
#define _XTAL_FREQ 8000000

void __interrupt() ISR(void) {
    if (INT0IF) {          // Check if INT0 caused interrupt
        LATDbits.LATD0 = !LATDbits.LATD0;  // Toggle LED
        INT0IF = 0;        // Clear interrupt flag
    }
}

void main(void) {
    TRISBbits.TRISB0 = 1;  // RB0 as input (button)
    TRISDbits.TRISD0 = 0;  // RD0 as output (LED)
    LATDbits.LATD0 = 0;

    INT0IF = 0;   // Clear flag
    INT0IE = 1;   // Enable external interrupt INT0
    GIE = 1;      // Global interrupt enable

    while(1) {
        // Main loop can do other tasks
    }
}
C

Circuit Diagram Description

VCC (5V) and GND → common reference.

Button → connected to RB0 (INT0) with a pull-down resistor.

LED → connected to RD0 via 330Ī© resistor.

  • When the button is pressed, RB0 changes state → INT0 flag is set.
  • MCU automatically jumps to the ISR.
  • LED toggles and flag clears.
  • MCU returns to the main loop — all automatically handled by hardware.
Interrupt TypePin/ModuleTypical Use
INT0 / INT1 / INT2RB0 / RB1 / RB2External triggers
TMR0 / TMR1 / TMR2Timer modulesDelays, periodic tasks
ADCAnalog Conversion CompleteSensor reading
USARTSerial Receive/TransmitUART communication
CCPCapture/Compare/PWMSignal control
  • Detect button presses or sensor triggers
  • Implement real-time event handling
  • Perform multitasking without RTOS
  • Efficient energy management in low-power devices

If you enjoyed this tutorial and want to learn the complete practical side of PIC18F4550, including:

  • Timers, Interrupts, and UART Communication
  • PWM for Motor Control
  • USB Interface & Sensors Integration
  • Real-world Project Building

šŸ‘‰ Then don’t miss our Premium Course: ā€œMastering PIC18F4550 Microcontrollerā€
šŸŽ“ A complete hands-on training designed for students, hobbyists, and engineers.

Learn, Code, and Build Real Embedded Systems Projects!

dsdas

Q1. What happens if two interrupts occur simultaneously?

PIC18F4550 supports interrupt priorities — the high-priority ISR executes first.

Q2. Do interrupts affect the main program execution?

They temporarily pause it, execute ISR, and then resume — without losing data.

Q3. How many external interrupts are available in PIC18F4550?

Three: INT0 (RB0), INT1 (RB1), and INT2 (RB2).

Q4. Can I disable interrupts temporarily?

Yes, by clearing the GIE (Global Interrupt Enable) bit.

šŸ”Ÿ What tools do I need to try this experiment?

You can start with:
PIC18F4550 Development Board (available at Bitziga Store)
10kΩ Potentiometer or LM35 Sensor
MPLAB X IDE + XC8 Compiler
Proteus Simulation (optional)

11ļøāƒ£ Where can I learn all the modules of PIC18F4550 in depth?

You can join our premium hands-on course:
šŸŽ“ ā€œMastering PIC18F4550 Microcontrollerā€ – A complete practical training covering ADC, Timers, Interrupts, UART, PWM, and real-world projects.
šŸ‘‰Mastering PIC18F4550 Microcontroller

12ļøāƒ£ Will this blog series cover other PIC modules too?

Yes! This is part of our ā€œDesign to Learnā€ campaign.
Upcoming posts will include:
Timer Configuration and Delay Generation
UART Communication and Serial Data Display
PWM Generation and Motor Control Projects
Stay tuned and subscribe for updates šŸš€

Home Ā» Recent posts Ā» Home › Blog › Configuring ADC Module of PIC18F4550

https://bitziga.com

Leave a Comment

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

*
*