Javatpoint Logo
Javatpoint Logo

External Interrupts in AVR Microcontroller

Microcontrollers can accept inputs from I/O ports, interrupts are used for accepting inputs generated by external events. Interrupt event directs the flow of program execution with a totally independent piece of code, known as "Interrupt Sub-Routine". There are many sources of interrupts that are available for a microcontroller. Most of them are generated by internal modules and are called as internal interrupts.

For running an interrupt subroutine following requirements are necessary:

  • The interrupt source must be activated by setting the corresponding interrupt mask/ Interrupt Enable Bit.
  • The enable bit in AVR status register must be set to 1. For this the instruction named 'sei' (Set Interrupt Enable).
  • The interrupt sub routine must present. If there is no code to b e run, then an empty subroutine must occur at particular memory spaced to that interrupt.
  • Finally the event must occur, so the execution of the routine gets triggered.

Writing an Interrupt Subroutine in AVR Studio:

It is tricky to use an interrupt subroutine into a C code of a microcontroller. Therefore the AVR GCC developers use a few symbols to represent the interrupts and macros that minimized the code size in many programs.

The interrupt subroutine for External Interrupt 0 and External Interrupt 1 is given below:


Registers Associated with External Interrupts:

The table showing microcontroller unit control register is given below:

MCU Control Register- MCUCR
Bit76543210
Bit NameSESM2SM1SM0ISC11ISC10ISC01 ISC00
Initial value00000000
Read/WriteRWRWRWRWRWRWRW RW

The table showing Interrupt Sense Control truth table is:

ISCx1ISCx0Interrupt Generated Upon
00The lower Level of INTx pin
01Any logical change inside INTx pin
10Falling edge of INTx pin
11Rising edge of INTx pin

Circuit Diagram:

ES Circuit Diagram

Source Code:

Next TopicInterView Question




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA