How to Use WinAVR and AVRStudio

 1.       Install WinAVR, check all option that can be installed

2.       Install AVRStudio

3.       After instalation, The first tool that you can use is Programmer’s Notepad. This program is in the directory WinAVR\pn. The executable filename is pn.exe.  You can use this program to create a .c file which will be compiled to hex, coff, etc .  The appearance likes the picture below.

-          Choose C/C++ type
-          On Text Clip, change it to WinAVR, double click application if you want to make program tamplate.
-          Then you can type your program. For example :

#include <avr/io.h>

void main(void) {
  DDRA = 0xff;  //set PORT A as output
  PORTA = 0b00000000;
  PORTA = 0b00000011;
  PORTA = 0b00001111;
  PORTA = 0b00111111;

-          After that, save your .c file.
Note: all WinAVR header files are in directory WinAVR\avr\include. There are many of header files that you can use.

4.       The second tools is MFile. You can open this program in Start -> All Programs -> WinAVR -> MFile [WinAVR]. This program is used to make some files such as file.hex, file.coff, and some others that we want from the file.c that we had made.  The appearance likes the picture below.

 The steps to use:
-          Choose Makefile -> Main file name. Type the name of your file without the extension. For example, if your file is exercise1.c  just  type exercise1 on main file name.
-          Choose Makefile -> MCU type. Choose type of your AVR microcontroller.
-          Ouput format = ihex
-          Choose debug format that suitable with your AVRStudio series.
-          Choose programmer that you use.
-          After you complete all changes, save the makefile file in the same directory where yourfile.c is  saved.
Note: Don’t forget to change the F_CPU by type it manually on the makefile. Scroll the makefile file and find it. Choose makefile -> enable editing, so you can edit the source code of makefile file.

5.       Open again the programmer’s notepad. In Tools tab, there are some instructions:
-          “make all” = yourfile.c  will be compiled to some type of file.
-          “make clean” = delete all product files of compiled .c file.
-          “make program” = used to download  hex file to chip, but it need set some configurations.
You can add some other output files not only .hex, .elf, .coff, etc.
For example, you want make .extcoff file after yourfile.c being compiled. The step:
-          Choose Tool -> Option -> Tools -> Add
-          Fill it
name            : [WinAVR] make extcoff
command    : make.exe
folder            : %d
parameter  : extcoff

After all the process, now, choose Tool  -> Make all

6.       Open AVR Studio -> Choose Open -> Find yourfile.coff or yourfile.elf. -> Save -> Choose AVR Simulator -> Choose your AVR type.

Then you will see :

After debug was started, you can choose PORTA and see the change in microcontroller step by step by press F11.

Note: You see that the change of bit in PORTA occurs in the second step of looping. AVRstudio can give us the real step and step by step. We can learn more about process in microcontroller because of this.

Ok, That is all about basic of using WinAVR and AVRStudio.

by  Luki,

No comments:

Post a Comment