Cover image for Embedded C programming and the Atmel AVR
Title:
Embedded C programming and the Atmel AVR
Personal Author:
Edition:
2nd ed.
Publication Information:
Clifton Park, NY : Thomson Delmar Learning, 2007
Physical Description:
1v + 1 CD-ROM
ISBN:
9781418039592
General Note:
Accompanied by compact disc : CP 4404

Available:*

Library
Item Barcode
Call Number
Material Type
Item Category 1
Status
Searching...
30000010121016 QA76.73.C15 B374 2007 Open Access Book Book
Searching...
Searching...
30000010120007 QA76.73.C15 B374 2007 Open Access Book Book
Searching...
Searching...
30000010088563 QA76.73.C15 B374 2007 Book Book
Searching...

On Order

Summary

Summary

Enter the world of embedded programming and microcontroller applications! One of the only books available today that uses the increasingly popular and cost-effective Atmel AVR embedded controller as the platform and application for learning, Embedded C Programming and the Atmel AVR, 2E is the perfect choice for novices. Featuring a host of fully-functional example applications, this highly innovative book enables users to adopt a "learn by doing" approach as they develop the knowledge and skills needed to achieve proficiency. Following an introduction to Atmel AVR RISC processors, readers are launched immediately into an embedded C language tutorial. Here, they'll experiment with variables and constants, operators and expressions, control statements, pointers and arrays, memory types, preprocessor directives, real-time methods, and more! In addition to a comprehensive library functions reference, an entire chapter on the CodeVision AVR C Compiler provides clear, step-by-step instruction in IDE installation and operation, mixing Assembler with C, and using the Code Wizard Code Generator. Use of peripherals - such as keypads, LCD displays, and other common embedded microcontroller-related devices - is also explored fully in this all-inclusive, state-of-the-art programmer's how-to and reference manual.


Table of Contents

Prefacep. xiii
Introductionp. xxi
Chapter 1 Embedded C Language Tutorial
1.1 Objectivesp. 1
1.2 Introductionp. 1
1.3 Beginning Conceptsp. 2
1.4 Variables and Constantsp. 4
1.4.1 Variable Typesp. 4
1.4.2 Variable Scopep. 5
Local Variablesp. 5
Global Variablesp. 5
1.4.3 Constantsp. 6
Numeric Constantsp. 7
Character Constantsp. 7
1.4.4 Enumerations and Definitionsp. 7
1.4.5 Storage Classesp. 9
Automaticp. 9
Staticp. 9
Registerp. 9
1.4.6 Type Castingp. 9
1.5 I/O Operationsp. 11
1.6 Operators and Expressionsp. 12
1.6.1 Assignment and Arithmetic Operatorsp. 12
Bitwise Operatorsp. 13
1.6.2 Logical and Relational Operatorsp. 14
Logical Operatorsp. 15
Relational Operatorsp. 15
1.6.3 Increment, Decrement, and Compound Assignmentp. 16
Increment Operatorsp. 16
Decrement Operatorsp. 17
Compound Assignment Operatorsp. 17
1.6.4 The Conditional Expressionp. 17
1.6.5 Operator Precedencep. 18
1.7 Control Statementsp. 19
1.7.1 While Loopp. 19
1.7.2 Do/While Loopp. 21
1.7.3 For Loopp. 22
1.7.4 If/Elsep. 23
If Statementp. 23
If/Else Statementp. 23
Conditional Expressionp. 26
1.7.5 Switch/Casep. 26
1.7.6 Break, Continue, and Gotop. 28
Breakp. 28
Continuep. 28
Gotop. 29
1.8 Functionsp. 33
1.8.1 Prototyping and Function Organizationp. 34
1.8.2 Functions that Return Valuesp. 36
1.8.3 Recursionp. 37
1.9 Pointers and Arraysp. 41
1.9.1 Pointersp. 41
1.9.2 Arraysp. 45
1.9.3 Multidimensional Arraysp. 47
1.9.4 Pointers to Functionsp. 49
1.10 Structures and Unionsp. 54
1.10.1 Structuresp. 54
1.10.2 Arrays of Structuresp. 56
1.10.3 Pointers to Structuresp. 57
1.10.4 Unionsp. 58
1.10.5 Typedef Operatorp. 60
1.10.6 Bits and Bitfieldsp. 61
1.10.7 Sizeof Operatorp. 62
1.11 Memory Typesp. 63
1.11.1 Constants and Variablesp. 63
1.11.2 Pointersp. 65
1.11.3 Register Variablesp. 65
sfrb and sfrwp. 66
1.12 Real-Time Methodsp. 69
1.12.1 Using Interruptsp. 69
1.12.2 Real-Time Executivesp. 72
1.12.3 State Machinesp. 75
1.13 Programming Style, Standards, and Guidelinesp. 80
1.14 Chapter Summaryp. 81
1.15 Exercisesp. 81
1.16 Laboratory Activitiesp. 83
Chapter 2 The Atmel Risc Processors
2.1 Objectivesp. 87
2.2 Introductionp. 87
2.3 Architectural Overviewp. 88
2.4 Memoryp. 89
2.4.1 Flash Code Memoryp. 89
2.4.2 Data Memoryp. 89
Registersp. 90
I/O Registersp. 90
SRAMp. 92
2.4.3 Eeprom Memoryp. 94
2.5 Reset and Interrupt Functionsp. 97
2.5.1 Interruptsp. 98
2.5.2 Resetp. 101
Watchdog Timer and Resetp. 102
2.6 Parallel I/O Portsp. 105
2.7 Timer/Countersp. 109
2.7.1 Timer/Counter Prescalers and Input Selectorsp. 110
2.7.2 Timer 0p. 110
2.7.3 Timer 1p. 114
Timer 1 Prescaler and Selectorp. 115
Timer 1 Input Capture Modep. 115
Timer 1 Output Compare Modep. 119
Timer 1 Pulse Width Modulator Modep. 123
2.7.4 Timer 2p. 128
One-second recording interval using Timer 0p. 129
Engine rpm measurement using Timer 1p. 130
Drive shaft rpm measurement using Timer 1p. 131
2.8 Serial Communication Using the Usartp. 132
2.9 Analog Interfacesp. 141
2.9.1 Analog-to-Digital Backgroundp. 141
2.9.2 Analog-to-Digital Converter Peripheralp. 142
2.9.3 Analog Comparator Peripheralp. 146
Measuring engine temperature using the analog-to-digital converter (ADC)p. 149
Sending collected data to the PCp. 150
2.10 Serial Communication Using the SPIp. 151
2.11 Serial Communication Using I[superscript 2]Cp. 158
2.12 The Avr Risc Assembly Language Instruction Setp. 160
2.13 Chapter Summaryp. 163
2.14 Exercisesp. 167
2.15 Laboratory Activitiesp. 168
Chapter 3 Standard I/O and Preprocessor Functions
3.1 Objectivesp. 171
3.2 Introductionp. 171
3.3 Character Input/Output Functions - getchar() and putchar()p. 172
3.4 Standard Output Functionsp. 178
3.4.1 Put String-puts()p. 178
3.4.2 Put String FLASH-putsf()p. 179
3.4.3 Print Formatted-printf()p. 180
3.4.4 String Print Formatted-sprintf()p. 182
3.5 Standard Input Functionsp. 183
3.5.1 Get String-gets()p. 184
3.5.2 Scan Formatted-scanf()p. 185
3.5.3 Scan String Formatted-sscanf()p. 187
3.6 Preprocessor Directivesp. 188
3.6.1 The #include Directivep. 188
3.6.2 The #define Directivep. 189
3.6.3 The #ifdef, #ifndef, #else, and #endif Directivesp. 191
3.6.4 The #pragma Directivep. 196
#pragma warnp. 197
#pragma optp. 197
#pragma optsizep. 197
#pragma saveregp. 198
#pragma regallocp. 199
#pragma promotecharp. 199
#pragma ucharp. 199
#pragma libraryp. 200
3.6.5 Other Macross and Directivesp. 200
3.7 Chapter Summaryp. 201
3.8 Exercisesp. 202
3.9 Laboratory Activitiesp. 202
Chapter 4 The Codevisionavr C Compiler and IDE
4.1 Objectivesp. 205
4.2 Introductionp. 205
4.3 IDE Operationp. 206
4.3.1 Projectsp. 206
Open Existing Projectsp. 206
Create New Projectsp. 207
Configure Projectsp. 208
Close Projectp. 209
4.3.2 Source Filesp. 209
Open an Existing Source Filep. 209
Create a New Source Filep. 209
Add an Existing File to the Projectp. 209
4.3.3 Edit Filesp. 211
4.3.4 Print Filesp. 214
4.3.5 The File Navigatorp. 214
4.4 C Compiler Optionsp. 216
4.4.1 Memory Modelp. 217
4.4.2 Optimize Forp. 218
4.4.3 Optimization Levelp. 218
4.4.4 Program Typep. 218
4.4.5 (s)printf Features and (s)scanf Featuresp. 218
4.4.6 SRAMp. 219
4.4.7 Compilationp. 219
4.4.8 Messages Tabp. 220
4.5 Compile and Make Projectsp. 220
4.5.1 Compile a Projectp. 220
4.5.2 Make a Projectp. 221
4.6 Program the Target Devicep. 222
4.6.1 Chipp. 223
4.6.2 FLASH and EEPROMp. 224
4.6.3 FLASH Lock Bitsp. 226
4.6.4 Fuse Bitsp. 226
4.6.5 Boot Lock Bit 0 and Boot Lock Bit Ip. 226
4.6.6 Signaturep. 226
4.6.7 Chip Erasep. 227
4.6.8 Programming Speedp. 227
4.6.9 Program Allp. 227
4.6.10 Other Programmersp. 228
4.7 Codewizardavr Code Generatorp. 229
4.7.1 Chip Tabp. 232
4.7.2 Ports Tabp. 233
4.7.3 External IRQ Tabp. 234
4.7.4 Timers Tabp. 235
4.7.5 USART Tabp. 236
4.7.6 ADC Tabp. 237
4.7.7 Project Information Tabp. 238
4.7.8 Generate Source Codep. 239
4.8 Terminal Toolp. 247
4.9 The Atmel AVR Studio Debuggerp. 249
4.9.1 Create a COFF File for AVR Studiop. 250
4.9.2 Launch AVR Studio from CodeVisionAVRp. 250
4.9.3 Open a File for Debugp. 250
4.9.4 Start, Stop, and Stepp. 250
4.9.5 Set and Clear Breakpointsp. 251
4.9.6 View and Modify Registers and Variablesp. 252
4.9.7 View and Modify the Machine Statep. 252
4.10 Chapter Summaryp. 253
4.11 Exercisesp. 253
4.12 Laboratory Activitiesp. 255
Chapter 5 Project Development
5.1 Objectivesp. 257
5.2 Introductionp. 257
5.3 Concept Development Phasep. 257
5.4 Project Development Process Stepsp. 257
5.4.1 Definition Phasep. 258
5.4.2 Design Phasep. 260
5.4.3 Test Definition Phasep. 261
5.4.4 Build and Test the Prototype Hardware Phasep. 262
5.4.5 System Integration and Software Development Phasep. 262
5.4.6 System Test Phasep. 263
5.4.7 Celebration Phasep. 263
5.5 Project Development Process Summaryp. 263
5.6 Example Project: A Weather Monitorp. 263
5.6.1 Concept Phasep. 263
5.6.2 Definition Phasep. 264
5.6.2.1 Electrical Specificationp. 266
5.6.2.2 Operational Specificationp. 266
5.6.2.3 Basic Block Diagramsp. 267
5.6.3 Measurement Considerations for the Designp. 269
5.6.3.1 Temperaturep. 270
5.6.3.2 Barometric Pressurep. 272
5.6.3.3 Humidityp. 273
5.6.3.4 Wind Speedp. 274
5.6.3.5 Wind Directionp. 277
5.6.3.6 Rainfallp. 278
5.6.3.7 Dew Point Computationp. 281
5.6.3.8 Wind Chill Computationp. 282
5.6.3.9 Battery Healthp. 283
5.6.3.10 Real Timep. 283
5.6.4 Hardware Design, Outdoor Unitp. 284
Wind Speed Inputp. 284
Rain Gauge Inputp. 286
900 MHz Transmitterp. 286
Power Supplyp. 286
5.6.5 Software Design, Outdoor Unitp. 286
5.6.6 Hardware Design, Indoor Unitp. 287
900 MHz Receiverp. 287
Power Supplyp. 290
5.6.7 Software Design, Indoor Unitp. 290
5.6.8 Test Definition Phasep. 292
Wind Directionp. 293
Wind Speedp. 293
Rain Gaugep. 293
Air Temperaturep. 293
Barometric Pressurep. 294
Relative Humidityp. 294
System Test for Complete Projectp. 294
5.6.9 Build and Test Prototype Hardware Phasep. 294
Outdoor Unit Checkoutp. 295
Indoor Unit Checkoutp. 297
5.6.10 System Integration and Software Development Phase, Outdoor Unitp. 301
Temperature, Humidity, Wind Direction, and Battery Healthp. 305
Rainfallp. 305
Wind Speedp. 306
RF Telemetryp. 306
5.6.11 System Integration and Software Development Phase, Indoor Unitp. 312
Keeping Timep. 312
Low-Battery Indicationp. 314
The Buttons and the Beeperp. 316
Decoding the RF Telemetryp. 318
Collecting and Protecting Rainfall Datap. 321
Converting from Counts to Real Unitsp. 324
Routines for Controlling the LCDp. 325
Keeping the Display Up to Datep. 331
Editing the Time and Datep. 335
5.6.12 System Test Phasep. 339
5.6.13 Changing It Upp. 343
Picking a Part for a Better Fitp. 343
Changes to the Schematicp. 344
Changes to I/O Mappingp. 344
Other Considerationsp. 348
5.7 Challengesp. 349
5.8 Chapter Summaryp. 350
5.9 Exercisesp. 350
5.10 Laboratory Activityp. 351
Appendix A Library Functions Referencep. 353
Appendix B Getting Started with Codevisionavr and the STK500p. 453
Appendix C Programming the AVR Microcontrollersp. 471
Appendix D Installing and Using Thecableavrp. 475
Appendix E The Megaavr-DEV Development Boardp. 489
Appendix F Ascii Tablep. 493
Appendix G AVR Instruction Set Summaryp. 497
Appendix H Answers to Selected Exercisesp. 503
Appendix I A "Fast Start" To Embedded C Programming and the AVRp. 509
Indexp. 519