MY EXPERIENCE IN PROGRAMMING AVR MICROCONTROLLER USING
WINAVR/AVRGCC
by
BIBIN JOHN
Bibin
John
Digitally
signed by
Bibin John
DN: cn=Bibin
John, c=IN
Date:
2006.04.28
11:08:52 Z
Reason: I am
the author of
this document
Location:
Ernakulam
Signatu
re Not
Verified
NOTICE
This book is for newbies for programming AVR
microcontroller using WinAVR. This is mainly for those who want to make robots
using Atmel's AVR.Here i am writing this because I want to include troubleshooting
tips and simple working examples for newbies. The main reason for choosing AVR
microcontroller is because of its facilities and support from Linux compilers and cheap
cost programmers. Here i am using WinAVR and BSD AVRDUDE programmer. All
the codes in this book are tested with WinAVR2006. Before starting this you should
read my other books(it will be good) because I refer to that books for some parts.All
books are available on yahoo group-booksbybibin
I thank my teachers of MNNIT and my
colleagues Anil K.M,O.Praveen Kumar Reddy, M. Satish,Vigith Maurice, J
Rajashekhar Reddy,Athul Sona,Sanjo Sebastin . So i feel this book can guide you
through troubleshooting AVR microcontrollers. I thank my teachers of THSS Muttom,
Thodupuzha from where i learned the very basics of electronics.If you find any
problems put a post in yahoo groupbooksbybibin.
I am providing this book free of cost. You can use this
book as a study material. I don't want my book to be used as a material for business
without my permission. You are not allowed to upload this book in any other sites.
BIBIN JOHN
e-mail:njbibin@yahoo.co.in
website:www.geocities.com/njbibin
forums for AVR microcontrollers:
www.avrfreaks.net
www.avrbeginners.net
Www.roboticsindia.net
www.edaboard.com
Yahoo group:
avrclub
avrbooks
magazine:Circuit Cellar
INDEX
Why AVR???..................................................................................................5
As a beginner what i need to know???....................................................5
Softwares Required.....................................................................................5
Hardwares Required...................................................................................5
Difference between atmega32 and atmega32L.......................................5
GETTING STARTED.................................................................................6
LET'S START...............................................................................................6
Makefile.........................................................................................................9
What you had done in first program??...................................................15
PROGRAMMER HARDWARE...............................................................15
COMMON ERRORS IN AVR PROGRAMMING..............................20
TROUBLESHOOTING.............................................................................21
MOST IMPORTANT TIP.........................................................................22
FUSE BITS..................................................................................................24
SETTINGS FOR EXTERNAL CRYSTAL AND JTAG DISABLE.....26
IMPORTANT NOTES ON FUSE BITS..................................................27
DISABLING JTAG................................................................................27
DISABLING JTAG AND USING INTERNAL 8Mhz CLOCK..........29
INTERFACING LCD WITH AVR...........................................................30
SOME IMPORTANT COMMANDS USED
FOR PROGRAMMING.............................................................................34
L293D INTERFACING WITH AVR........................................................35
BIPOLAR STEPPER MOTOR DRIVING USING AVR.....................38
UNIPOLAR STEPPER MOTOR INTERFACING................................41
KEY ENCODER INTERFACING(74922)................................................43
7-SEGMENT DISPLAY INTERFACING WITH AVR.........................46
MULTIPLEXED 7-SEGMENT DISPLAYS.............................................48
IC TESTER....................................................................................................49
UART of AVR..............................................................................................51
Troubleshooting...............................................................................51
SERIAL PORT OF COMPUTER..............................................................52
BIOS SETTINGS.........................................................................................53
SERIAL PORT INTERFACING WITH COMPUTER..........................54
HYPER TERMINAL................................................................................58
Device Manage COM Properties..........................................................60
Testing your computer Serial Port................................................61
SERIAL PORT TROUBLESHOOTING AND ERRORS..................62
SERIAL PORT with LCD DISPLAY....................................................65
INTERNAL ADC OF AVR....................................................................69
ADC with SERIAL PORT and LCD.....................................................71
TROUBLESHOOTING................................................................73
TIMERS......................................................................................................74
which one should I choose Atmega32 or Atmega32l.........................74
IMPORTANT THINGS FOR TROUBLESHOOTING.....................75
links.............................................................................................................76
Why AVR??????
AVR microcontrollers are popular because of their Linux support and their softwares
like AVRGCC and AVRDUDE. If you start learning with any microcontroller the cost
you have to pay is the microcontroller cost+software+programmer. If you compute
this then AVR is the best. Atmega8 is available with Rs.75 and programmer cost is just
a printer cable costs Rs.40 with some wires and AVRGCC for Linux and WinaVR2006
for Windows.It has facilities like inbuilt ADC which is not there in 8051, which will be
advantageous for robotics. Software are easily available for other microcontrollers but
they have a limit of maximum 2K program memory. The project 'embedded ethernet'
have around 10K program memory usage while WinAVR have no such limitations.
The programmer cost of 8051 and pic are above Rs.400(as far as I know). See
http://www.electricstuff.co.uk/picvsavr.html
As a beginner what i need to know???
Here I am going to talk about microcontroller just like a computer running on parallel
port and a C program. I am using the same examples. Basic thing you have to know
how to program the chip and writing programms for the chip. If you know 8085 then
it will be easy to understand. Anyway I am writing codes in C so that it will be easy to
understand.
Softwares Required:
WinAVR2006,AVRDUDE(if you are using AVRStudio)
www.winavr.sourceforge.net
atmega32,atmega8 datasheet(see in atmel.com)
You better make logins in www.avrfreaks.net so that when you have doubt, you can
put it there.
Hardwares Required:
atmega32 or atmega 8 (atmega32 costs from Rs.200 to Rs.350 and atmega8 from Rs.75
to Rs.120)
Breadboard
Printer Port cable
Serial port cable
Crystal(3.6864Mhz)
Difference between atmega32 and atmega32L:
Both are same only difference in frequency and voltage limitations. I prefer atmega32L
because of its low cost and easy availability. Atmega16 also serve same purpose except
its Flash is 16KB(sufficient) and difference in memory capacities. The remaining
hardware portion are same for both.
5