Atmel AVR Microcontroller Primer Programming and Interfacing

所需积分/C币:9 2016-01-30 23:04:49 9.7MB PDF

This textbook provides practicing scientists and engineers a primer on the Atmel AVR microcontroller. Our approach is to provide the fundamental skills to quickly get up and operating with this internationally popular microcontroller. The Atmel ATmega16 is used as a representative sample of the AVR
Atmel avr Microcontroller Primer: Programming and Interfacing Steven f. barrett University of Wyoming Daniel J Pack United States Air Force academy SYNTHESIS LECTURES ON DIGITAL CIRCUITS AND SYSTEMS #15 MORGAN&CLAYPOOL PUBLISHERS ABSTRACT This textbook provides practicing scientists and engineers a primer on the Atmel avr microcon troller. Our approach is to provide the fundamental skills to quickly get up and operating with this internationally popular microcontroller. The Atmel ATmega16 is used as a representative sample of the AvR line. The knowledge you gain on the ATmega16 can be easily translated to every other microcontroller in the AVR line. We cover the main subsystems aboard the aTmega16, providing a short theory section followed by a description of the related microcontroller subsystem with accompanying hardware and software to exercise the subsytem In all examples, we use the C programming language. We conclude with a detailed chapter describing how to interface the microcontroller to a wide variety of input and output devices KEYWORDS Atmel microcontroller, microcontroller, ATmega16, Atmel AVR, microcontroller interfacing P1 reface In 2006, Morgan Claypool Publishers(M&c)released our textbook Microcontrollers Fundamen tals for Engineers and Scientists. The purpose of this textbook was to provide practicing scientists and engineers a tutorial on the fundamental concepts and the use of microcontrollers. The text book presented the fundamental concepts common to all microcontrollers. Our goals for writing this follow-on book are to present details on a specific microcontroller family-the Atmel avr Microcontroller Why Atmel There arc many excelent international companics that produce microcontrollers As Atmel states, Atmel Corporation is an industry leader in the design and manufacture of advanced semiconductors, with focus on microcontrollers, nonvolatile memory, logic, radio frequency components and sensors. Some of the highlights of the Atmel avr line include high performance coupled with low power consumption outstanding flash memory technology reduced instruction set computer Harvard Architecture single-cycle instruction execution wide variety of operating voltages(1.8-5.5 VDC) architecture designed for the C language one set of devclopment tools for the cntirc AVR linc, and in-system programming, debugging, and verification capability Although all of these features are extremely important, we have chosen to focus on the Atmel AVR line of microcontrollers for this primer for a number of other related reasons The learning curve for Atmel microcontrollers is gentle. If this is your first exposure to microcontrollers, you will quickly come up to speed on microcontroller programming and interfacing. If you already know another line of processors, you can quickly apply your nowledge to this powerful line of 8-bit processors It is relatively inexpensive to get started with the Atmel AVR microcontroller line The microcontrollers themselves are inexpensive, and the compilers and programming hardware and software are relatively inexpensive vi ATMEL AVR MICROCONTROLLER PRIMER: PROGRAMMING AND INTERFACING The AVR line provides a full range of processing power, from small 8-pin processors to complex 100-pin processors. The same compiler and programming ardware may be use with a wide variety of microcontrollers Many of the avr microcontrollers are available in dual inline package, which makes them readily useable on a printed circuit board prototype(e.g,, senior design projects) Many of the microcontrollers in the AVRline are pin-for-pin compatible with one another This allows you to easily move up and down the avr line as your project becomes better defined Atmel has documentation available for every microcontroller at your fingertips. Simply visitwww.atmel.comFurthermore,Atmelcustomersupportisgoodandresponsive There is worldwide interest in the avr microcontroller line. We would be remiss to not ention AVR Freaks. This is a dedicated, international group of avr experts who share their expertise online with other high-power users and novices alike Approach of the book If this is your first exposure to microcontrollers, we highly recommend that you read first our other M&c textbook, Microcontrollers Fundamentals for Engineers and Scientists. It will provide you the ackground information necessary to fully appreciate the contents of this textbook. This textbook picks up where the first one left off. We have received permission from M&c to include some of the background material from the first textbook in this text to allow for a complete stand-alone product Our approach in this textbook is to provide you the fundamental skills to quickly get up and operating with an Atmel microcontroller. We have chosen to use the AVR ATmega16 as a representative sample of the AVR line(more on this processor later). The knowledge you gain on the aTmega16 can be easily translated to every other microcontroller in the AVR line We will usc an ongoing testbench example throughout the textbook. We will start by having you get a simple microcontroller circuit operating with a simple menu program that interacts with external devices. As we move through various microcontroller subsystems, we will continue to add features to the testbench. By the end of the textbook, you will have a complete hardware/software system that demonstrates the features of the ATmega16. You can then use this testbench to adapt to other applications The M&c textbooks are designed to be short tutorials on a given topic. Therefore, our treatment of each topic will provide a short theory section followed by a description of the related microcontroller subsystem with accompanying hardware and software to exercise the subsystem In all examples, we will use the C programming language. There are many excellent C compilers available for the Atmel AvR line. We have chosen the Image Craft ICC AVR compiler for its short learning curve and ease of use Acknowledgments pace does not permit us to thank everyone who has provided encouragement along the way. We thank Joel Claypool and John Enderle for inviting us to participate in their efforts to develop a series of short tutorial textbooks on select engineering topics. We also thank atmel and Image craft for their permission to use their copyrighted material and screenshots throughout the text We especially thank Helen Perlegos of Atmel for her assistance is securing appropriate permission to use Atmel material within the text Most of all, we thank our families. We acknowledge our parents. Thank you, Moms (Eleanore and Jackie), and thank you, Dad (Frank), for always believing in me(S B ) Thank you Moms(Young Shin and Rana),and thank you, Dads(Sung Bock and Chong Kon), for your encouragement and unfailing support(D P ) Finally, our work could not have come to fruition without the sacrifices of our family members: Cindy, Heidi, Heather, Jon R, Christine, Jon B Andrew, and Graham. as always, without you none of this would matter. We love you! Laramie and Colorado springs, November 2007 Steve barrett and daniel pack IX Contents 1. Atmelavr Architecture overview 1.1 ATmega16 Architecture Overview 1.1.1 Reduced Instruction Set Computer 1.1.2 Assembly Language Instruction Set 1.1.3 ATmcga16 Architccturc Ovcrvicw 111233 1.2 Nonvolatile and Data memories 1.2.1 In-System Programmable Flash EEPROM 1.2.2 Byte-Addressable EEprom 1.2.3 Static Random Access memor 1.2. 4 Programmable Lock bits 1. 3 Port System 1.4 Peripheral Features-Internal Subsystems ········:.:··· 8 1.4.1 Time base 8 1.4.2 Timing Subsystem 1.4.3 Pulse Width Modulation Channels 1.4.4 Serial ce nications 1.4.4.1 Serial USaRt 1.4.4.2 Serial Peripheral Interface 1. 4.4.3 Two-Wire Serial Interface 1.4.5 Analog-to-Digital Ce onvcrtcr 1.4.6 Interrupts 1.5 Physical and Operating parameters 1.5.1 Packaging∴… 11 1.5.2 Power Consumption rades 13 1.6 Application: ATmega16 Testbench 1.6.1 Hardware Configuration 1.6.2 Softwarc Configuration 15 x ATMEL AVRMICROCONTROLLER PRIMER: PROGRAMMING AND INTERFACING 1.7 Programming the ATmega16 ,,,,,19 1.7.1 Programming Procedure 20 1.8 Software Portability ....22 1.9 Summary 23 1.10 References and Further reading 23 1.11 Chapter Problems 秦着 ∴.23 2. Serial Communication Subsystem 25 2.1 Serial communications 25 2.2 Serial Communication Terminology 2.2. 1 Asynchronous versus Synchronous Serial transmission 26 2.2.2 Baud Rate .26 2.2.3 Full duplex 2. 2.4 Nonreturn to Zero Coding Format 26 2.2.5 The rs-232 Communication Protocol....,...........27 2.2.6 Parity 2. 2. 7 American Standard Code for Information Interchange .27 2.3 Serial Usart .,27 2.3.1 System Overview ...28 2.3.1.1 usaRT Clock Generator 29 2.3.1.2 USART Transmitter ∴.30 2.3.1.3 USART Receiver 30 2.3.1.4 USART Rcgistcrs 30 2.3.2 System Operation and Programming .32 2.3.3 Serial Peripheral Interface 34 2.3.3.1 SPI Operation ······ 2.3.3.2 Registers .35 2.3.3.3 Programming 2.4 Two-Wire Serial Interface 25 Summary.,,,,,,,,,, 38 2.6 References and Further Reading 38 2.7 Chapter Problems 3. Analog-to-Digital Conversion 41 3. 1 Background Theory 3. 1.1 Analog versus Digital Signal .42 3. 1. 2 Sampling, Quantization, and Encoding .,44 3. 1.3 Resolution and Data Rate 48

...展开详情
img

关注 私信 TA的资源

上传资源赚积分,得勋章
相关内容推荐