Interrupt using PIC


Interrupt is one of the powerful concepts in microcontroller applications. If an interrupt occurs in the microcontroller, controller completes the execution of the current instruction and starts the execution of an Interrupt Service Routine (ISR).

  • ISR is a piece of code that tells the controller what to do when the interrupt occurs.
  • After the execution of ISR,controller returns back to the instruction.

Types Of Interrupt

  • Two types of interrupt
    1.Hardware interrupt.
    2.Software interrupt.

Hardware interrupt

  • If the interrupts are generated by the interfaced devices like a switch is called hardware interrupt.

Software interrupt

  • Interrupts are generated by a piece of code is called software interrupt.

PIC Interrupt

  • The 5 registers used to control the operation of Interrupts in PIC 16F877A Microcontroller.

INTCON Register

  • INTCON Register is a readable and writeable register which contains various enable and flag bits for External and Internal Interrupts.
  • GIE – Global Interrupt Enable
    1 – Enables all unmasked interrupts
    0 – Disables all interrupts.
  • PEIE – Peripheral Interrupt Enable
    1 – Enables all unmasked peripheral interrupts
    0 – Disables all peripheral interrupts.
  • TMR0IE Timer 0 Overflow Interrupt Enable
    1 – Enables the TMR0 interrupt
    0 -Disables the TMR0 interrupt.
  • INTE-RB0/INT External Interrupt Enable
    1 – Enables the RB0/INT external interrupt
    0 – Disables the RB0/INT external interrupt.
  • RBIE – RB Port Change Interrupt Enable
    1 – Enables the RB port change interrupt
    0 – Disables the RB port change interrupt.
  • TMR0IF – Timer 0 Overflow Interrupt Flag
    1 – TMR0 register has overflowed. It must be cleared in software.
    0 – TMR0 register did not overflow.
  • INTF – RB0/INT External Interrupt Flag
    1 – The RB0/INT external interrupt occurred. It must be cleared in software.
    0 – The RB0/INT external interrupt did not occur.
  • RBIF – RB Port Change Interrupt Flag
    1 – At least one of the RB7 – RB4 pins changed state, a mismatch condition will continue to set the bit. Reading PORTB will end the mismatch condition and allow the bit to be cleared. It must be cleared in software.
    0 – None of the RB7 – RB4 pins have changed state.
  • INTEDG bit of OPTION_REG Register is the Interrupt Edge Select bit.
  • When it is 1 interrupt is on the rising edge of RB0/INT pin.
  • When it is 0 interrupt is on the falling edge of RB0/INT pin.


 void main()
 TRISC = 0;
 PORTD = 0x00;
 void  interrupt() // ISR