Avr Tutorial

Topics: Atmel AVR, Output, Input/output Pages: 13 (1845 words) Published: January 11, 2013
The AVR Microcontroller
Introduction Application and programmer boards WinAVR Basic I/O ADC, timers USART, LCD Mehul Tikekar Chiraag Juvekar Electronics Club September 29, 2009

What is a microcontroller?
 

It is essentially a small computer Compare a typical microcontroller (uC) with a typical desktop ATmega16 Typical desktop

Clock frequency CPU data size RAM ROM

16MHz 8 bits 1KB 16KB
32 pins

3GHz 32 bits 1GB 160GB
Keyboard, monitor 65W

Power consumption 20mW


Why use a micro-controller?
It is programmable.  A code (typically written in C) decides what it does  Easier to write a code than design and make a custom circuit for complex jobs  e.g. In a micromouse, a single uC controls the motors, finds distance from the walls, explores and solves the maze  The same muC can be used in hundreds of applications  http://instruct1.cit.cornell.edu/courses/ee476/Final Projects/ has 407 projects just on AVR microcontrollers as of 2009. 


AVR microcontroller
• •

Lots of micro-controller families
o 8051, PIC, AVR, MSP430, ARM, etc.

http://www.instructables.com/id/How-to-choosea-MicroController/ • AVR: Cheap, easy to use, fast and lots of features • ATmega16: o 16KB flash memory o 1KB SRAM o Up to 16MHz clock o Four 8-bit I/O ports o ADC, timers, serial interface, etc. o 40 pin DIP, VDD = 5V 4

ATmega16 pin diagram

Port B Programming interface

Port A

Port D

Port C


Hardware and Software needed
Application board  Programmer board  WinAVR


Bare bones of the Application Board

On a bread-board


R2 LED1 C1 R1 Programming interface

Complete application board


USBasp – USB Programmer

www.fischl.de/usbasp for more information and usb driver




A complete package for Windows

◦Programmer’s Notepad (user interface) ◦avr-gcc (C/C++ compiler) ◦Mfile (makefile generator) ◦avrdude (programmer software) Totally free! : http://winavr.sourceforge.net/

Programmer’s Notepad


Application board


The hardware setup


Resources and Links
 

The ATmega16 datasheet – a 358 page bible Tutorials and sample codes: 1. 2. 3. http://www.avrtutor.com http://winavr.scienceprog.com http://kartikmohta.com/tech/avr/tutorial

Atmel application notes: projects, tutorials, codeexamples, miscellaneous information http://www.atmel.com/dyn/products/app_notes.asp?family_id=607

 

Forums: http://www.avrfreaks.net Advanced projects:
1. 2. http://instruct1.cit.cornell.edu/courses/ee476/FinalProjects http://www.obdev.at/products/vusb/projects.html 14

Configuring the microcontroller before running it the first time 
  

Fuse bytes : high and low
Program them once before you start using the micro-controller Disable JTAG to free up PORTC for normal use Set the correct clock clock option

With the hardware set up, run in Command Prompt :
For 1MHz internal clock:
avrdude -c usbasp -P usb -p m16 -U hfuse:w:0xd9:m -U lfuse:w:0xe1:m

For 16MHz external crystal:
avrdude -c usbasp -P usb -p m16 -U hfuse:w:0xc9:m -U lfuse:w:0xef:m

 

Refer to datasheet sections on “System clock and clock options” and “Memory programming” for other clock options and their settings. Setting the wrong fuse values may render the uC unusable 15

Hello world
  

Blink an LED Choose a port and a pin In the code
2. 3.

Set pin direction to output
Set pin output to high Wait for 250ms

5. 6.

Set pin output to low
Wait for 250ms Go to 2

Relevant registers : DDR – set pin data direction PORT – set pin output PIN – read pin input


#include // contains definitions for DDRB, PORTB #include // contains the function _delay_ms() int main(void) { DDRB = 0b11111111; // set all pins on PortB to output while(1) { PORTB = 0b00000001; // Set PortB0 output high, others low _delay_ms(250); // Do nothing for 250 ms PORTB = 0b00000000;...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Avr Microcontroller Essay
  • Tutorial Centers Essay
  • Avr Microcontroller and Embedded Systems Essay
  • Avr Programming Methods Essay
  • ACCG399 Tutorial 1 Essay
  • avr controlled usb<>can bus interface Essay
  • Avr Instruction Set Manual Essay
  • Essay about Overview of Lectures and Tutorials at the School of Business and Economics Loughborough University

Become a StudyMode Member

Sign Up - It's Free