AVR Board
7 segment display AVR Programmer
Atmel AVR Board
AVR  arduino  atmel  board  code  core  data  design  development  device  features  flash  memory  USB  registers  microcontroller  power  program  programming  software 

AVR C Tutorial



Tools needed for any AVR C tutorial


In order to provide and test your own programs for AVR microcontrollers by means of avr gcc/avr libc, the following hardware and software is needed:
  • AVR Kit or AVR development board which is supported by avr GCC compiler (all ATmegas and most AT90). You can also use a patch board. Useful test platform are also the STK500 and the AVR Butterfly by Atmel.
  • The avr GCC compiler and AVR libc. Free of charge, available for almost all platforms and operating systems. Under Windows operating system you can use the package WinAVR - AVR-GCC for Windows.
  • Programming software and hardware e.g. PonyProg or AVRDUDE with STK200-Dongle or hardware and software available from Atmel (STK500, Atmel AVRISP, AVR Studio).
  • AVR Studio: not necessarily, but for the simulation and for debugging under Windows it is quite useful.

Prerequisites

  • Have a working installation of the GNU tools for AVR.
  • Have an AVR programmer (hardware) and a working installation of AVR programming software (such as avrdude).
  • Have a basic, fundamental, understanding of the C language. You should understand the basics of header files, pointers, control structures, and compiling/linking. Check AVR books.
  • A basic knowledge of electronics concepts.
  • Make sure you either have downloaded the avr-libc reference or have the online manual bookmarked.

When no AVR C tutorial can help you

  • Find out whether it is actually an AVR (GCC) specific problem or it only requires the revitalization of your C language knowledge.
  • Check avr libc documentation.
  • The AvrFreaks forum.
  • Archives of the avr GCC mailing list.
  • For problems with control of internal AVR functions: read the datasheet of the microcontroller (completely and at least twice).
  • Ask Google.





AVR C Tutorial List


A Quickstart Tutorial for ATMEL AVR Microcontrollers

Most tutorials skim over a lot of information. Not this one. This tutorial assumes you have some basic knowledge, but tries not to make any other assumptions. This tutorial will demonstrate the following development process:
  • Write C programs in AVR Studio
  • Compile them into a .hex file using the AVR-GCC compiler (which integrates into AVR Studio)
  • Simulate the target AVR chip and debug the code within AVR Studio
  • Program the actual chip using the AVRISP mkII USB device, which is attached to our target chip with a special 6-pin cable
  • Once programmed, the chip runs the program in your circuit.

AVR Tutorial: Introduction and Digital Output

This tutorial Introduces:
  • Basic include files for using the avr-libc with gcc
  • Using a pin on the AVR as a digital output
  • Clearing and setting a bit (ouput pin) using C bitwise operators
  • Compiling and AVR project using a simple Makefile.

AVR C-programming tutorial

This is an in introduction to programming of AVR microcontrollers using C as a language. The avr-gcc was originally developed for Unix systems. Today it is available for almost any system and very widely used. This article will therefore also cover Windows. The setup on a Mac is almost identical to Linux.
  • Hardware becomes software
  • What are Microcontrollers?
  • What are AVR microcontrollers?
  • Let's start with a simple circuit
  • Programming the microcontroller
  • The software
  • How do I compile that code?
  • Help! Give me an IDE
  • Makefiles
  • What are Fuses?
  • Debugging
  • Writing small and efficient code
  • Code examples
  • Code examples: Analog to digital conversion
  • Code examples: Timers
  • Code examples: LCD displays
  • Conclusion
  • References/Download

A Brief Tutorial on Programming the AVR

This document was written give a basic introduction to some of the specifics of AVR programming, assuming you already have a handle on C. It approximates the order I came to understand things while learning to program the AVR. I'm doing a lot of this "the hard way", there are a number of macros in avr-libc or avrlib to do much of this but it's important to understand the underlying principles. If you understand what's going on, moving your code (from a '168 to a '644P for example) is very easy.
  • A blinking LED - Busy Waits and IO ports
  • Two blinking LEDs - Addressing Pins
  • A switched LED - Digital Input and output
  • Serial Output
  • Serial Input
  • Putting it together: printing button presses and controlling LEDs
  • Analog Output
  • avr-libc goodies
  • Analog Input
  • A blinking LED - Interrupts and timers
  • Persistent Storage
  • Input Capture
  • Watchdog
  • I2C/SPI peripherals
  • ATmega644P-specific
  • ATtiny85-specific
  • AT90USB162-specific

AVR GCC Tutorial (WinAVR)

This Tutorial is to facilitate the entrance into the programming of Atmel AVR Microcontroller in theprogramming language C with the free C-compiler avr GCC.This Tutorial presupposes basic knowledge in C. Previous knowledge in the programming of micro-controllearn,neither in assembler nor in another language, are not necessary.

The original version comes from Christian Schifferle, many new sections and current adjustments from MartinThomas. Many of the functions used in the original document are no more contained in of the current versionsof the avr GCC of C-compiler and the run time library avr libc or are not to be used no more. This Tutorial wasadapted to the new functions/methods.

The explanations and examples refer to the versions 3.4.5 of the avr GCC compiler and 1.4.3 avr libc, like thatas them in WinAVR 20060125 are contained. The differences to older versions are described in the main textand appendix is however recommended to beginners to use the current versions.