Interrupt in AVR Atmega32A Microcontroller

This tutorial is about how to use interrupt in AVR Atmega32A microcontroller. Interrupt enhances a use of microcontroller in many different ways. Interrupt is exactly the same as it means in English. Normally we expect a program to keep on executing sequentially in the way we have defined. When interrupt occurs the normal flow of instruction is temporarily suspended and interrupts service routine (ISR) related function or event is executed by program so basically whenever interrupt occurs in our program, we stop current task and handle the event then resume program flow back where we left off.

Interrupt in AVR Atmega32A Microcontroller is either software or hardware. There are in total 21 different interrupt vectors available (for more detail about their address and definition please follow datasheet page no: 43). External interrupts are triggered by INT0, INT1, INT2 pins. In this tutorial will be covering software interrupt. As in our previous post, we have seen timer and counter so let’s write interrupt driven program. In which we will be using 16-bit Timer/Counter1 register.

learn-embedded-system

This is one of classic example to keep tutorial short and simple. Let’s hook up green LED and a current limiting resistor of 330Ω to PB0 pin of microcontroller. In this example, we will generate interrupt to toggle LED after every second. Please follow video for more detail about code.

Circuit Connections: Interrupt in AVR Atmega32A

Interrupt in AVR Atmega32A Microcontroller
Circuit Diagram (Schematic)
interrupt-with-ATmega32A-tutorial
Interrupt with ATmega32A Tutorial

Source Code: Interrupt in AVR Atmega32A Microcontroller

/*
 * Example Project: InteruptTest
 * Created: 17-08-2013 13:30:30
 * Author: UMESH LOKHANDE
 */ 

#include <avr/io.h>
#include <avr/interrupt.h>

int main(void)
{
  sei();

  DDRB |= 1<<PINB0;

  TCCR1B |= 1<<CS10 | 1<<CS11 | 1<<WGM12;
  TIMSK |= 1<<OCIE1A;

  OCR1A =  15624;

  while(1)
  {
  }
}

ISR(TIMER1_COMPA_vect)
{
  PORTB ^= 1<<PINB0;
}

This is how we can use internal interrupt in AVR ATmega32A Microcontroller. In future, we will learn how to use external in our projects. If you have any question or suggestions then feel free to leave a comment. Thank You.

Get Free Courses & Webinars
You'll receive only high quality learning material, tips & tricks
I agree to have my personal information transfered to MailChimp ( more information )
We respect your privacy

About Umesh Lokhande

Umesh Lokhande holds a Master degree in Scientific Instrumentation from University of Applied Sciences Jena, Germany. and has previously worked at Orbotech, Alere Technologies etc. Umesh is also a founder and first author of BINARYUPDATES.COM

Login

Register | Lost your password?