Things to Know About Programming the AVR
The Makefile
Basic Commands
Using the Makefile
Interpretting Code
The Makefile
The makefile is a collection of the most commonly used commands. The purpose is to have the commands
along with the flags such thatyou can easily reference and use.
The file should be called
Makefile. If you download a Makefile with a different
name, change the filename to that.
Basic Commands
A good place to look for the most common commands is a Makefile. Here is a link to
hello.45.button makefile.
The top section:
PROJECT=hello.button.45
SOURCES=$(PROJECT).c
MMCU=attiny45
F_CPU = 8000000
Project is the name of the file. After "making" the project, you will compile the C-code into a
hex file.
Source will be the actual file to be compiled.
MMCU is the type of AVR.
F_CPU is the speed. The default on the attiny45 is 800000 but you can change with fuses and external oscillator.
Know look at one of the lines of code to program:
program-usbtiny: $(PROJECT).hex
avrdude -p t45 -P usb -c usbtiny -U flash:w:$(PROJECT).c.hex
There are several options in the makefile that begin program-something.
That something is the programmer. I used a derivative of the usbtiny programmer most of the time.
-p t45 describes the avr type. t45 is processor code for the Attiny45.
-P usb describes the Port(i.e the USB port).
-c usbtiny is the name of the programmer
-U is the command to flash after compiling the hex file.
Using the Makrfile
A Makefile can have more options than the example above. Look at the Makefile from compiling
the FabISP: FabISP Makefile
Before running commands in with Make, check to make sure you have the right processor and speed set up.
Here are common commands to run, in sequence, to get a program on your microcontroller:
make
make clean
make hex
make flash
(sudo) make fuse
(sudo) make program
make - will turn the c-code into an execuetable
make clean - will remove any excecuetables(so that you can re-compile)
make hex - will create the hex file
make flash - will flash the firmware
make fuse - will flash the fuses
make program - wil flash both firmware and fuses
From a new program, a typical process would be:
make
make program
Interpretting The Code
When I first started, understanding the format of the code was difficult because of all of the named pieces.
I did not know where the names were coming from until I looked in the header file.