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.

DDRx
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
PINx
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
PORTx
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-atmega32a-tutorial
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

3 comments

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

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

Leave a Reply

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

Login

Register | Lost your password?