AVR Studio Software Tutorial - C & Assembly
AVR Studio Software Tutorial - C & Assembly
, KJIT, Savli
LAB Manual
LAB Manual
Introduction
This tutorial will teach you how to write, compile, and trace a simple program in
AVR Studio. For more information, you can see AVR Studios help.
2. Execute the downloaded setup file. The installation of the software is straight
forward, and it can be done by pressing the Next and Install buttons a few times.
Now, the AVR Studio IDE is ready to be used.
LAB Manual
5. In the left list, when you want to write your code in Assembly you should select
Atmel AVR assembler, and when you want to write you code in C, you should
choose AVR GCC. As we want to write the first program in assembly, choose
Atmel AVR assembler. Then choose a name for your project (e.g. firstProgram)
by typing the name in the text field below the Project name. You can change the
location where the files of the project will be saved by clicking on the button,
if you want. Press the Next button.
LAB Manual
6. Choose AVR Simulator from the left list and ATmega32 from the right list and
press Finish.
LAB Manual
Saving
8. Save the program by pressing Ctrl + S or choosing Save from the File menu
Assembling
9. To convert your program to machine language press F7 or select Build from the
Build menu or click the build icon in the toolbar.
10. See the Build window. The window shows if your program has syntax error or
not. By looking at the window, you can see the amount of memory which is used
by your program, as well.
Microcontroller & Interfacing (2151001)
LAB Manual
LAB Manual
Tracing
12. To execute the next instruction press F11 or select the Step Into from the Debug
menu. There are also another tracing tools in the Debug menu, as well:
Step Over: It is executes the next instruction, like Step Into. The only
difference between them is that, if the next instruction is a function call,
the Step into, goes to the function; but Step Over executes the function
completely and goes to the next instruction.
Step Out: If you are in a function, Step Out executes the program up to the
end of the function.
For more information about the Tracing tools you can see the AVR
Studios help.
LAB Manual
Watching
See Figure 11. In this part you learn to use the different tools to watch the program.
LAB Manual
LAB Manual
Disassembler: This window shows the contents of the flash memory. In the
window:
1) The black texts display our program.
2) Below each of the instructions of our program, its assembly equivalent
is mentioned. As our program is in assembly, our instructions and their
equivalent are the same.
3) The gray numbers at the middle of the lines mention the machine code
of each instruction. For example, according to Figure 19, the machine
equivalent of LDI R20,0x00 is E040.
4) The last column describes what the assembly instruction does. For
example as you see in Figure 19, LDI is Load immediate, or RJMP is
Relative Jump.
5) The gray numbers at the beginning of each line, mention at which
location of flash memory each of the instructions are located. For
example, in Figure 19, LDI R20,0x00 is located in address 0000.
6) The yellow arrow, points to the next instruction which will be
executed.
LAB Manual
LAB Manual
LAB Manual
Introduction
This tutorial will teach you how to write, compile, and trace C programs in AVR
Studio. For more information, you can see AVR Studios Help and see the WinAVR site.
LAB Manual
2. Execute the downloaded setup file. The installation of the software is straight
forward, and it can be done by pressing the Next and Install buttons a few times.
Now, the AVR Studio IDE is ready to be used.
LAB Manual
LAB Manual
7. Do the followings:
In the left list, choose AVR GCC.
Choose a name for your project (e.g. firstProgram) by typing the name in
the text field below the Project name.
You can change the location where the files of the project will be saved by
clicking on the button, if you want.
Press the Next button.
LAB Manual
8. Choose AVR Simulator from the left list and ATmega32 from the right list and
press Finish.
LAB Manual
//port A as output
//port B as output
//port C as output
PORTA = 0xAA;
while (1)
{
PORTC = PORTC ^ 0x01; //toggle PORTC.0
PORTB = i;
i++;
}
return 0;
}
LAB Manual
Saving
10. Save the program by pressing Ctrl + S or choosing Save from the File menu
Compiling
11. Press F7 or select Build from the Build menu or click on the build icon in the
toolbar.
12. See the Build window. The window shows if your program has syntax error or
not. By looking at the window, you can see the amount of memory which is used
by your program, as well.
LAB Manual
Debugging
13. Select Start Debugging from the Debug menu. A yellow arrow appears next to
the first instruction of the program and shows the next instruction which will be
executed.
Tracing
14. To execute the next instruction press F10 or select the Step Over from the Debug
menu. There are also another tracing tools in the Debug menu, as well:
Step Into: It is executes the next instruction, like Step Over. The only
difference between them is that, if the next instruction is a function call,
the Step into, goes to the function; but Step Over executes the function
completely and goes to the next instruction.
Step Out: If you are in a function, Step Out executes the program up to the
end of the function.
For more information about the Tracing tools you can see the AVR
Studios help.
LAB Manual
Watching
See Figure 12. In this part you learn to use the different tools to watch the program.
In Figure 12, you saw some icons in the toolbar which are
numbered as 3, 4, and 5 (Figure 16). The use of them is
discussed in this page.
Watch: Click on the tool which
is numbered as 3 in Figure 16.
The watch window appears
(Figure 17); in this window you
can see the value of different
variables at the correct time.
Double click under the Name
title and type i and then press
Enter; the value of the i will be
displayed, and if you continue
tracing by pressing the F10
button (Step Over) the changes
of i will be displayed.
LAB Manual
LAB Manual
2) We can choose which of the memories to be displayed using the comboBox on the
top left corner of the window:
Data: SRAM memory
EEPROM: EEPROM
I/O: I/O registers
Program: Flash Memory
Register: general purpose registers
Figure 21:
Disassembler