fbpx

Interrupt Using AVR

Introduction

Interrupt is one of the powerful concept 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.

External Interrupt

  • In AVR external interrupt are available
    1.Pin9-Reset ,
    2.Pin16-INT0 ,
    3.Pin17-INT1 ,
    4.Pin3-INT2 .
  • To access the external interrupt some registers to be configured they are
    1. MCUCR : MCU Control register.
    2. MCUCSR : MCU Control and Status Register.
    3. GICR : General Interrupt Control Register.
    4. I-bit : Global Interrupt Enable.

MCUCR: MCU Control Register

  • The Bit[0:3] of the MCUCR register is to identify the type of signal in the interrupt 0 (INT0) and interrupt1 (INT1).

MCUCSR: MCU Control & Status Register

  • The Bit6 of the MCUCSR register is to identify the type of signal at external interrupt 2 (INT2).
  • INT2 is edge-triggered, it cannot be used for level triggering.

GICR: General Interrupt Control Register

  • The GICR register Bit[5:7] called the interrupt masks is used to disable/enable the respective interrupt.
  • Interrupt is Disabled – when the bit value is 0, Enabled – when the bit value is 1.
  • By default all the interrupts are disabled.

I-bit: Bit7, Global Interrupt Enable

  • SREG register must also be set to 1.
  • When Global Interrupt enable bit is set to 0, all interrupt will disable.
  • The Enable and Disable of I-bit are done by SEI and CLI instructions.

Steps To Program timer

  • Clear Global Interrupt enable bit.
  • Initialize the interrupt by configuring the MCUCR, MCUCSR and GICR registers.
  • Set a Global Interrupt Enable bit.
  • Define the Interrupt service routine (ISR) for the interrupt.

1 comment on “Interrupt Using AVR

Leave a Reply

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