Professional Documents
Culture Documents
Tutorial
By Adam Bailin
ECE 353 Fall 06
ECE 353
Introduction
WinAVR is a set of developing tools for
Atmel AVR RISC microprocessors
ECE 353 3
Programmers Notepad
Programmers Notepad is the main tool
you will be using to write your C code
Just like any other compiler
syntax highlighting
Support for different programming languages
Ability to compile your code (using gcc
compiler)
ECE 353 4
Adding external tools
In Programmers Notepad, select Tools->Options,
and select Tools on the left side of screen
ECE 353 5
Adding external tools (continued)
Select a Scheme (C/C++)
Click on Add
Name is an identifier for this
tool
Command is the command
used
Folder should be %d (Path of
file)
This tool will call make
extcoff, and is now available
under Tools menu
We will need this later for
debugging in AVR Studio
ECE 353 6
Example C Program
// blinky.c
#include <avr/io.h> // Standard AVR header
#include <avr/delay.h> // Delay loop functions
int main(void)
{
DDRA = 0xFF; // PORTA is output
while (1) {
for (int i=1; i<=128; i*=2) {
PORTA = i;
_delay_loop_2(30000);
}
for (int i=128; i>1; i/=2) {
PORTA = i;
_delay_loop_2(30000);
}
} // end while
}
ECE 353 7
Building your source
Write your C source, save as blinky.c
Open up MFile
Makefile -> Main File Name = blinky (no .c)
Makefile -> MCU Type = atmega32
Other values should be fine at default
File -> Save As to blinky.c directory
In Programmers Notepad: Select Tools
->Make All
ECE 353 8
MFile
Simple program to make Makefiles for
compiling your C code
A Makefile is a configuration file that tells
the compiler how to compile your code
What chip youre using (atmega32)
Target filename (blinky.c)
ECE 353 9
GNU Make
WinAVR uses Makefiles when building
projects, with GNU Make
ECE 353 10
Makefiles (continued)
Makefiles are tab-sensitive: tab != space
ECE 353 11
Example Makefile
## all and clean targets must be defined!
# make or make all will build dependencies in the order they are given
begin:
@echo Starting build
project2:
avr-gcc project2.c
end:
@echo Build complete
clean:
rm project2.o
ECE 353 12
Programming your ATmega32
To program your chip with the C code you
wrote:
Go to AVR Studio
Connect to your chip using JTAG ICE
Go to Fuses tab, make sure Ext Clock is set
In Program tab, flash your chip with the .hex
file you compiled in Programmers Notepad
Thats it!
ECE 353 13
C Debugging in AVR Studio
AVR Studio provides a way to debug both the C
source code and the assembly code.
To do that you just need to change the type of
the COF file generated by the compiler.
winavr.sourceforge.net
ECE 353 20