practical avr microcontrollers.pdf

(18118 KB) Pobierz
Technology in AcTion
Practical AVR
Microcontrollers
Games, Gadgets, and Home
Automation with the Microcontroller
Used in the Arduino
FlAsh, sense, sPin, And Roll with
the AVR MicRocontRolleR
Alan Trevennor
www.it-ebooks.info
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
www.it-ebooks.info
Contents at a Glance
Foreword ......................................................................................................................
xv
About the Author ........................................................................................................
xvii
About the Technical Reviewer .....................................................................................
xix
Acknowledgments .......................................................................................................
xxi
Introduction ...............................................................................................................
xxiii
Part 1: The Basics....................................................................................
1
Chapter 1: A Brief History of Microcontrollers ............................................................3
Chapter 2: Building Our AVR Test Bed .......................................................................13
Chapter 3: Arduino and the Naked AVR .....................................................................49
Chapter 4: Moving On! ...............................................................................................85
Chapter 5: Smarten Up! ...........................................................................................155
Chapter 6: Digitally Speaking ..................................................................................167
Part 2: The Projects .............................................................................
189
Chapter 7: Introduction to the Projects Section ......................................................191
Chapter 8: Project 1: Good Evening, Mr. Bond: Your Secret Panel ...........................195
Chapter 9: Project 2: Crazy Beams—Exercise Your Pet! .........................................213
Chapter 10: Project 3: WordDune ............................................................................229
Chapter 11: Project 4: The Lighting Waterfall..........................................................249
Chapter 12: Moving to Mesmerize...........................................................................277
Chapter 13: Smart Home Enablers ..........................................................................305
v
www.it-ebooks.info
Contents at a GlanCe
Appendix A: Common Components..........................................................................333
Appendix B: A Digital Electronics Primer ................................................................347
Appendix C: Breadboards ........................................................................................359
Appendix D: Serial Communications .......................................................................365
Index ...........................................................................................................................377
vi
www.it-ebooks.info
Introduction
The microcontroller unit (MCU) is the ultimate electronics tinker-toy, and in this book you’re going to see
how to tinker away with it to your heart’s delight! My intended audience for this book is those who like to learn
hands-on. Learning by doing and seeing has always been my preferred way to learn: If it’s yours too, let’s take the
ride together. For those who like to understand the “why” first of all, the book also includes some background
material that explains why using microcontrollers in everyday situations can be such a powerful concept.
My only assumption is that you have some very basic knowledge of digital electronics. But, if that’s
not
you,
don’t worry! There are some appendixes that will give you the start that you need—and the book’s web site
(and various references through the text of the book) also point you to some valuable AVR MCU-related
online resources.
MCU Basics
I’ll start with a summary of the absolute basics, just in case you’re new in MCU town, if you’re not, feel free to skip
to the next section. A microcontroller is truly a “computer on a chip.”
For straightforward applications such as making LEDs flash, or driving a simple clock display, it’s likely that
you would only need just one MCU (Microcontroller Unit) chip. For more complex applications (such as those
in some of the project chapters of this book) you often need to add helper chips, but the MCU still does all the
brainwork.
There are dozens of different microcontroller types on the market (PIC/PICAXE, Intel, ARM, Philips/NXP,
Toshiba, Panasonic, and many more) and they all have strengths and weaknesses.
The AVR
1
family of MCUs from Atmel Corporation has become one of the most available and capable
general-purpose MCU product sets—and via platforms like the Arduino (more of which later on) has reached a
market prominence in the low-cost MCU world. AVR also compares favorably on cost with other low or mid-
range microcontroller families.
Microcontrollers evolved partially from the digital memory chips industry and partly from the simpler
microprocessors that they have now largely displaced for new designs. We’ll be looking at the evolution of the
microcontroller in more detail in the first section of this book.
Every AVR MCU consists of a processor core, some programmable flash memory, and some RAM. It will
also have on-chip extras, such as input/output (I/O) ports, timers, serial communications ports, analog to digital
convertors, and maybe even a USB port.
All chips in the AVR range have the basic processor core and memory, but as you go up the range of products
they include more and more of the extras (and bigger and bigger on-chip memory capacities). Using the simplest
of AVR MCU chips (a small eight-pin device costing no more than a dollar; see the photo) you can easily make an
LED flasher or other simple circuits.
1
Weirdly, nobody at Atmel wants to tell what the initials AVR stand for. In fact, the guys who invented AVR, Alf Egil Bogen
and Vegard Wollan, tease anyone who asks the question! Was it a combination of their initials? No, they say. They even
made a teasing video. Search for “The Story of AVR” on youtube to see it.
xxiii
www.it-ebooks.info
Zgłoś jeśli naruszono regulamin