How to Blink LED Using Atmel Studio and ATMEGA32 Microcontroller

How to Blink LED Using Avr Microcontroller?

Blink LED using Atmel Studio is the initial step in programming a microcontroller, much as printing “Hello World” in C or C++. An extremely well-liked high-performance 8-bit AVR microcontroller is the Atmega32.

Video:

Moreover, If you want to perform this Project Blink LED Using Atmel Studio then please watch this Video given below

In this article, I will explain how to build and debug code in Atmel Studio 7.0 and how to Blink LED Using Atmel Studio and AVR Atmega32 Microcontroller.

This article is for beginners, who have just started learning or experimenting with embedded systems and AVR Atmega32 Microcontroller chip. In this mini project, I demonstrate how to write a simple code of blink LED using Atmega32 Microcontroller in Atmel Studio and test it in Proteus. I will use the Assembly language in the Atmel Studio.Moreover, you will also learn how to determine the direction of I/O pins and how to make the status of output pins high or low.

I will make you understand step by step.So, Let’s get started.

Getting Start with Atmel Studio 7.0- Developing the Code

1st Step:

If you have not yet downloaded Atmel Studio, download, and install it from https://atmel-studio.software.informer.com/7.0/.

2nd Step:

Now, Open Atmel Studio.

open Atmel

3rd Step:

Click on File option,then go to New and open Project.

You will see different options, C/C++ and Assembler.

Moreover, if you want to code in C language, you will choose the option shown below.atmel assembly

And, if you want to code in Assembly language, you will select the Assembler option.

As I am coding in assembly language, so selecting Assembler.

Furthermore, give the name of a project, the solution name, and the location in which the project is to be saved and click OK.Atmel location

4th Step:

After pressing the “Ok” button, you will have a pop-up window, in which you must select your Microcontroller, I will choose here Atmega32 Microcontroller and click OK.

Atmega Microcontroller

5th Step:

Write a program, you will see already few lines of code written in the window, remove these lines and start writing your own code.

atmel code

Explaining Code of Blink LED using Atmel Studio

LDI R16, 0XFF, Here X is representing Hexa, FF is Hexa value, if we convert it into Decimal, it’s 255, and if we convert it into binary, it becomes 11111111.

Here LDI is a command, which is used to load any immediate value.

R16 is a register, in which we are loading an immediate value a Hexa value.

Registers we are using in this project:

DDR and PORTC are the two registers we must employ. Data Direction Register, often known as a DDR or special function register, controls the input/output (In/Out) direction of each pin on a microcontroller.

When the DDR register is HIGH, the corresponding pin is output, and when it is LOW (0), the corresponding pin is input. The output register that determines the condition of each pin on a certain port is called a PORT register. Moreover, when the PORT register is HIGH, the corresponding pin becomes Logic HIGH (5V), and when it is LOW, the corresponding pin becomes Logic LOW (0V).

Moving further in understanding the code, we will write a loop, and write code.

6th Step:

After completing the code, execute your code.

For this purpose, go to Debug option, then click on Start Debugging and Break.

debug the code in atmel

Further, you will select debugging tool, in which you will select the Simulator.

We will select Proteus as a simulator.

atmel simulator

Again Debug, go to Windows then select Processor Status.

atmel processor status

Our focus is on the R16 register, then select step-over, and we will see the R16 value is loaded.

atmel register

Now, we want to see a special function register.

For this purpose, again go to the window then debug, and after that click on the I/O option.

Atmel input output of code

Select I/O PORTC.

You can see PORTC has three ports, PNC, DDRC, and PORTC. Our focus is on DDRC which is special function register.

Function register

Red pins are showing that the values are configured for output.

register value

Repeat this procedure by clicking on step-over and seeing the results for each line of code.

The loop is infinite, it will keep running and LED will keep blinking.

7th Step:

Now, the next step is building a solution, for that go on the Build option or click F7.

Build code in Atmel f7

Testing in Proteus:

Go to the File option and click on a project.

Proteus

Give any name to the project and name the location where you want to save your project.

How to save project in proteus

After clicking on Next and completing all requirements, a window will open.

Right-click on a window, go to Place, then components, and then Library.

how to add components in proteus

In keywords, write LED, and you will see different LED colors, you can select any color.

Atmega has four ports, and each port has 8 bits, as Atmega is of 8 bits.

proteus components

As we did choose PORTC as an output, we can connect our LED with any one of the ports of PORTC.

To complete our circuit, we need ground.

For that purpose, click on Place, then terminal, and then click on the ground option.

Proteus Ground

Last Step of Blink Led using Atmel Studio:

In the last step, we will burn (run) the code, double-click on the circuit window, and go to the program file option. And then go to the location where you have saved your Atmel Studio. You will see your file, click on that file, and go to debug option, then open the hex file. Then go back to Atmel Studio and run the window. You will see your LED is blinking and operating correctly.

led blinking in proteus

Code:

.INCLUDE "M32DEF.INC"
LDI R16 ,0XFF // R16=255= 11111111
OUT DDRC,R16 // DDRC=11111111 //CONFIGURED AS OUTPUT
LOOP1:
      OUT PORTC,R16 // PORTC=11111111 LED=ONN
	  COM R16    //R16=00000000
	  OUT PORTC,R16 // PORTC=R16=00000000 // LED OFF
	  JMP LOOP1

Additionally, If you want to see Our Latest Posts then Visit Our website

1 thought on “How to Blink LED Using Avr Microcontroller?”

Leave a Comment

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