1. Package download and setup
There is nothing wrong with the vendor-provided tools (Atmel, now owned by Microchip), but we want the bare minimum of layers of abstraction and “help” between the text file with code and the actual programs that convert that code into a .hex
file to program to the MCU.
Once you understand the process, then adding layers of tooling on top to automate it is just fine.
WinAVR uses GCC (as does the Arduino platform), but forces allows us to have more control over the compiling process compared to other tools. It is old (2010 version!) … but it works.
The portable version can run from anywhere and does not require installing, which is handy for students and lab computers.
Download the modified Valpo copy from the GDrive docs
folder: [1]
Unzip this archive, then move the folder to a location of your choosing.
Double-click on the file CreateShortcuts.bat
and a black cmd.exe
window will briefly pop up.
You can move the newly-created shortcut files wherever you would like.
2. avr_sim and gavrasm
gavrasm
, the assembler used by avr_sim is also installed.
It is available from the command window started by the AVR-CommandShell
shortcut.
2.1. Colors in avr_sim
This step is not able to be automated or pre-configured, unfortunately. But it only involves editing a text file.
You can find a copy of the avr_sim manual in GDrive docs / AVR / avr_sim-gavrsim
:
avr_sim_Handbook_v25.pdf.
What follows was obtained from reading §4.3.7 Syntax highlighting and some experimentation.
-
Color configuration is stored in two places:
-
Default system settings
c:\Users\YourUsername\AppData\Roaming\avr_sim\avr_sim.cfg
-
Per-project settings
project-name.pro
file next to your.asm
file and the.lst
and.hex
output files.
-
System default colors:
After avr_sim has run at least once on the machine, open the following file in a text editor: (AppData
is a hidden folder)
C:\Users\YourUsername\AppData\Roaming\avr_sim\avr_sim.cfg
Paste the following line into that file and save it:
syhili=i255,,b;d16711680,,;k8421504,12632256,bi;c8421504,,;f128,,;l65280,,;r8388608,,b;z32896,65535,;n0,,;
The configuration file (either the system avr_sim.cfg or the project .pro ) MUST end in a blank line.
Otherwise the program will silently ignore the changed settings.
|
Before testing whether the change works, use a text editor to open up the .pro
file for the project you intend to open for checking the colors.
Delete the line beginning with syhili=…
in the project file.
Those are the colors that apply to that particular project only and are probably not what you wanted anyway.
-
The color settings get saved to the project file when you answer Yes to the Question dialog box asking “Project changed, save changes?”
Now, open a project with avr_sim and see that the coloring is indeed updated.

-
You are encouraged to come up with a better color scheme and share it!
2.2. Assembly with avr_sim / gavrasm
Start avr_sim from this new shortcut. Create a new project.
Paste in the following code:
; Blink pin PB3
; ATtiny85
; Symbols defined for the ATtiny85
.nolist
.include "tn85def.inc"
.list
; what follows is to be placed in program memory
.cseg
; starting at this address
.org 0x0000
Setup:
; set PB3 to output using DDRB
sbi DDRB, 3 ; 2 cycles, same result
Main:
; blink PB3
sbi PORTB, 3
cbi PORTB, 3
rjmp Main
Assemble the code to generate a .hex
file.
Run the simulation to verify that the code operates as you expect.
3. Tour of WinAVR Portable
Inside the extracted folder WinAVR-20100110
:
-
Folder
bin/
:-
avrdude
-
avr_sim
-
All of the AVR-GCC and AVR-binutils programs:
-
`avr-g` C compiler
-
avr-gcc
C compiler and main program -
avr-ld
Linker -
avr-objcopy
Generate.lst
and.hex
files -
avr-as
Assembler -
avr-size
-
-
-
Folder
pn/
— Programmer’s Notepadpn.exe
-
Folder
utils/bin
MINGW programs, to run from a command window.-
make
-
Convert text files.
make
needs Linux-formatMakefile
files-
fromdos
— Convert text file to use\n
(Linux) instead of\r\n
(Windows) line endings -
todos
— Convert text file to use\r\n
(Windows) instead of\n
(Linux) line endings
-
-
4. Documentation
It is somewhat useful to read random documentation found randomly on the Internet. It us much more useful to read the documentation for the specific version of AVR-libc and friends that you are actually using. Versions add features over time, usually the web version is for the latest version unless otherwise specified. |
Most of the specific documentation about the tools is under this folder:
WinAVR-20100110\doc
(→ ${doc}
below)
-
avrdude
- programming tool.
PDF manual:${doc}\avrdude\avrdude.pdf
-
avr-gcc
- C/C++ compiler. There are two major parts of GCC that you should have separate in your mind:-
C preprocessor
cpp
, which handles#define
,#ifdef
, and similar.${doc}\gcc\HTML\gcc-4.3.2\cpp\index.html
-
Compiler GCC
${doc}\gcc\HTML\gcc-4.3.2\gcc\index.html
Search for “attributes” for the documentation for things likeinline
/noinline
,interrupt
, and others which give the compiler specific information to guide the compilation and optimization process.
-
-
avr-libc
- C standard library and extras for AVR:-
HTML version of the manual:
${doc}\avr-libc\avr-libc-user-manual\index.html
-
PDF of the manual:
${doc}\avr-libc\avr-libc-user-manual.pdf
-
-
avr-binutils
- Many companion tools for manipulating compiler output.-
avr-as
- assembler.${doc}\binutils\as.html\index.html
Directives and features of GCC’s version of assembly language. -
avr-ld
- linker.${doc}\binutils\ld.html\index.html
The linker is usually called byavr-gcc
and not directly. It handles combining all of the compiled object files (.o
) into a single executable file (.elf
). -
avr-objdump
- Generates the.lst
listing by taking the binary.elf
and disassembling, yielding assembly language. With extra options and with code compiled with the-g
option, the output also gives the source code that roughly corresponds to the assembly.
${doc}\binutils\binutils.html\objdump.html
-
avr-abjcopy
- Generates the.hex
file for programming from a binary.elf
, and other related outputs.
${doc}\binutils\binutils.html\objcopy.html
-
avr-size
- summarizes code and RAM usage. -
avr-nm
- lists the symbols defined in an object.o
file.
-
5. Program device with avrdude
Open a command window using the AVR-CommandShell
shortcut.
With your "Arduino as ISP" attached to COM6
:
-
avrdude -c stk500v1 -p attiny85 -b 19200 -P COM6 -U flash:w:main.hex
You likely need to change the COMx port and the .hex
file name.
Purpose | Nano | ATtiny85 | Description |
---|---|---|---|
RESET |
D10 |
pin 1 |
reset |
MOSI |
D11 |
pin 5 |
Serial data in |
MISO |
D12 |
pin6 |
Serial data out |
SCK |
D13 |
pin 7 |
Serial clock |
Programming is independent of HOW the .hex file was created — text editor, assembler, C compiler, Arduino IDE (Sketch → Export compiled binary), back alley bartering, etc.
|