From ElectroDragon
Jump to: navigation, search


Flash Tool


  • Winavr WinAVR: Install the programmed, and test the AVRDUDE like below, run the cmd.exe in start menu.
  • AVR-GCC in Linux
  • ProgISP Very Powerful and useful burning tool, same as AVR fight, eXtreme Burner, etc, these tools are also a kind of Avrdude GUI tools, provide a windows interface instead of avrdude command line.Click the RD to read the chip, you can check the wiring by doing so.
  • AVR_fighter


Pin Definition


This is the pins of ATmega168, a powerful chip and not expensive. You can also try to get even more cheaper ATmeaga 8A/8L or ATmega 328 version from us.

ISP Connector


For more information about the AVR ISP standard, please read this doc. This is very important to make sure you find the right pin-1 of the ISP connector, otherwise you will waste a lot of time on testing connection but didn't find why, so just find the pin-1 correct.
Always make the 6 pins conntected, including:MISO, MOSI, Reset, VCC, GND, SCK, normally the programmer will provide power to the IC, so not necessary to provide extra power.

Pin configuration based on package


The General AVR package could be DIP-8, DIP-20, DIP-28, DIP-40

Many but not allof the AVR devices in a given package (e.g., DIP-8) share the same ISP connector pinouts, so these target boards can sometimes (with caution) even be used for different AVR microcontrollers. For example,the ATmega8, ATmega48, ATmega88, and ATmega168 share the same 28-pin pinouts. Note that in the figure above there are more than six connections to the ATmega168. That’s because there are extra power and ground lines running to the analog circuitry of the chip, which should be wired up even when the analog section is not in use.

Fuse Set

You know about flash, eeprom and RAM as parts of the chip. What I did not mention is that there are also 3 bytes of permanent (by permanent I mean that they stick around after power goes out, but that you can change them as many times as you'd like) storage called the fuses. The fuses determine how the chip will act, whether it has a bootloader, what speed and voltage it likes to run at, etc. Note that despite being called 'fuses' they are re-settable and dont have anything to do with protection from overpowering (like the fuses in a home).


You could grab the demo code from File:Had AVRtut, and programming the hex file into your chip. This code is for atmega 168, you should have the postive pin of led to the pin 2 of atmega 168 and negative to a resistor (180 or 330 Ohm), and then go to GND.
You should see the LED blinking once the hex programmed.

Memory Map

The memory map of a microcontroller is a diagram which gives the size, type and layout of the memories that are available in the microcontroller. The information use to construct the memory map is extracted from the datasheet of the microcontroller.

The diagram below gives the memory map for the ATMega8515 AVR 8-bit Microcontroller from Atmel. The ATMega8515 microcontroller contains three(3) blocks of memory: Program Memory, EEPROM Memory and Data Memory.

Data Memory Contains:

  • 32 8-bits General Purpose
  • 64 8-bits Input/Output Registers
  • 512 8-bits SRAM space

Program Memory Contains:

  • 8K byte Flash Memory
  • Organized as 4K-16bits space

EEPROM Memory Contains:

  • 512 8-bits EEPROM space

Memory Map Small.jpg


Name Price Speed / Flash / SRAM / EEPROM Functions I/O Datasheet
ATMEGA 8L $1.5 DIP 8 MHZ / 8 KB / 1 KB / 512 Byte Serial 23 ATMEGA 8L
ATMEGA 8A $1.2 TQFP 16 Mhz / 8 KB / 1 KB / 512 Byte Serial 23 atmega 8a
ATtiny 2313V $1.6 20 Mhz / 2 KB / 128 Byte / 128 Byte Serial 18 ATtiny 2313V
ATMEGA 16L $2.5 16 Mhz / 16 KB / 1 KB / 512 Byte Serial 32 atmega 16L
ATtiny 13 $1.3 20 Mhz / 1 KB / 64 Byte / 64 Byte - 6 ATtiny 13A
ATMEGA 328P $2.2 DIL-28, $1.6-TQFP 20 Mhz / 32 KB / 2KB / 1KB Serial, SPI, IIC 23 ATMEGA 328P

About Model Name

Model name Header text Header text
Example Example Example
Example Example Example
Example Example Example
  • ATmega16L-8AU Key Parameters:
16 - Basic Model 
L - low-voltage version  and V/P - Low voltage consumption (A - New version, combined either with "L" or without "L", P = "picoPower" tech, PA = new version + "picoPower")
8 - maximum operating frequency 
A - package type, TQFP("P": DIP package, "A": TQFP package, "M": MLF package.)
U - environmentally friendly packaging, Industrial Level temperature; ("C": commercial grade, "I": industrial grade (leaded), "U" industrial grade (unleaded).)

Operating voltage 2.7-5.5 V; maximum operating frequency of 8 MHz; Flash16; KBEEPROM512 B; SRAM1024 B; temperature level -40 ℃ ~ 85 ℃

Demo Starting Code

snippet 1

#ifndef F_CPU
#define F_CPU 16000000UL // 16 MHz clock speed
#include <avr/io.h>
#include <util/delay.h>
int main(void)
  DDRC = 0xFF; //Nakes PORTC as Output
  while(1) //infinite loop
    PORTC = 0xFF; //Turns ON All LEDs
    _delay_ms(1000); //1 second delay
    PORTC= 0x00; //Turns OFF All LEDs
    _delay_ms(1000); //1 second delay

snippet 2

#include <avr/io.h>
#include <avr/interrupt.h>
int main(void)
  //Setup the clock
  cli();            //Disable global interrupts
  TCCR1B |= 1<<CS11 | 1<<CS10;  //Divide by 64
  OCR1A = 15624;        //Count 15624 cycles for 1 second interrupt
  TCCR1B |= 1<<WGM12;     //Put Timer/Counter1 in CTC mode
  TIMSK1 |= 1<<OCIE1A;        //enable timer compare interrupt
  sei();            //Enable global interrupts
  //Setup the I/O for the LED
  DDRD |= (1<<0);     //Set PortD Pin0 as an output
  PORTD |= (1<<0);        //Set PortD Pin0 high to turn on LED
  while(1) { }          //Loop forever, interrupts do the rest
ISR(TIMER1_COMPA_vect)      //Interrupt Service Routine
  PORTD ^= (1<<0);        //Use xor to toggle the LED


  1. gcc-avr: complier
  2. avr-libc:library used when compling
  3. gdb-avr :gdb reverse debug tool, against complie
  4. avrdude:flash tool


  • generate o file from c file:
  • -c Compile or assemble the source files, but do not link.
  • -Os Optimize for size, -O1, Optimize.-O2 Optimize even more.
  • -g Generate debugging information that can be used by avr-gdb.

>avr-gcc -g -mmcu=atmega8 -Wall -Os -c ledtest.c
>avr-gcc -g -Os -mmcu=atmega8 -c flash.c
>avr-gcc –mmcu=at90s2313 –c demo1.c

  • output .o .elf file for further use, for elf file, use when have more then one c file:
  • -o put output into output file

>avr-gcc -g -mmcu=atmega8 -o flash.elf flash.o
>avr-gcc -g -mmcu=atmega8 -o ledtest.out -Wl,-Map, ledtest.o

  • combined linked file into MCU read hex file

>avr-objcopy -j .text -j .data -O ihex flash.elf flash.hex
>avr-objcopy -R .eeprom -O ihex ledtest.out ledtest.hex
Above flash.elf and ledtest.out is the input file, and the second is the output file. >avr-size ledtest.out
Complete commands:

  • avr-gcc -Os -DF_CPU=8000000 -mmcu=attiny85 -c led_flash.c
  • avr-gcc -DF_CPU=8000000 -mmcu=attiny85 -o led_flash.elf led_flash.o
  • avr-objcopy -O ihex led_flash.elf led_flash.hex
  • rm led_flash.o
  • rm led_flash.elf


  • DDRC = 0xFF makes all pins on PORTC as output pins
  • PORTC = 0xFF makes all pins on PORTC Logic High (5V)
  • PORTC = 0x00 makes all pins on PORTC Logic Low (0V)
  • _delay_ms(1000) provides 1000 milliseconds delay.
  • while(1) makes an infinite loop

Flash code

  • Use avrdude, command like: sudo avrdude -p m8 -c dragon_isp -P usb -e -U flash:w:flash.hex


Pages in category "AVR"

The following 4 pages are in this category, out of 4 total.