Tuesday , December 18 2018

Blink LED using AVR Atmega32A Microcontroller

This tutorial is about accessing IO (Input/Output) ports of AVR ATmega32A Microcontroller.This tutorial also covers how to blink LED using AVR Atmega32A Microcontroller. From previous tutorial, we know that our chip has 40 physical pins and these pins are categorises into four ports so each pin perform multiple function, thus before we make use of microcontroller let’s try to understand how microcontroller allows us to access its pins to perform certain task. Basically, functions of microcontroller pins divided into three major categories: ControlSensingCommunication.

There are different ways to program these functions for better understanding and to keep simplicity we are going to control PB0 pin of PORTB. Lets add a green LED to PB0 pin along with current limiting resistor of (360Ω). Now let’s look at how to make it work,

  1. Adjusting port pin of controller as input or output.
  2. Determine their state of output.
  3. Detect their state of input.

To map the physical pins into program code. We need to understand ports and their respective register and also naming convention to instruct microcontroller to perform certain action by accessing those register through C Program.

Data Direction Register for Port x
x- corresponds to port A, B, C or D. Bit is set to 1 for output & bit is set to ‘0’ (cleared) for Input
Input address for Port x
x- corresponds to ports A, B, C or D
Represent state of a port, bit ‘1’ if pin is HIGH and bit ‘0’ if pin is LOW
Data Register for Port x
This register is used to control the output of a port for pin that was connected to the input means DDRx. The internal pull up resistor can be enables(1) or disabled(0).
LED Blinking with ATmega32A

The circuit diagram is shown in the picture (above) and for further details follow a video provided down below. The short description is provided below code snippet.

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


  1. I would like to buy development kit of avr and arm cortex-m3 series.
    Do let me suggest some good buying options

  2. I recommend you to buy AVR kit with either ATmega32/ATmega32A or ATmega8. For Cortex-M3 I think its good to go with NXP LPC1768. Here are some online retails shop where you can buy those extremeElectronics and TINKERSKY ELECTRONICS

    Have a good time with programming

    Good Luck

  3. what to do if flash memory verification fails ?
    spend days looking for proper answer, Please help


Register | Lost your password?