Skip to:Content
|
Bottom
Cover image for Embedded C programming and the atmel AVR
Title:
Embedded C programming and the atmel AVR
Personal Author:
Publication Information:
Clifton Park, N.Y. : Thomson/Delmar Learning, 2003
Physical Description:
1v + 1 CD-ROM (CP 2497)
ISBN:
9781401812065

Available:*

Library
Item Barcode
Call Number
Material Type
Item Category 1
Status
Searching...
30000010022619 QA76.73.C15 B374 2003 Open Access 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 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. 15
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. 24
Conditional Expressionp. 26
1.7.5 Switch/Casep. 26
1.7.6 Break, Continue, and Gotop. 28
Breakp. 28
Continuep. 29
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. 42
1.9.2 Arraysp. 46
1.9.3 Multidimensional Arraysp. 48
1.9.4 Pointers to Functionsp. 50
1.10 Structures and Unionsp. 55
1.10.1 Structuresp. 55
1.10.2 Arrays of Structuresp. 57
1.10.3 Pointers to Structuresp. 58
1.10.4 Unionsp. 59
1.10.5 Typedef Operatorp. 61
1.10.6 Bits and Bitfieldsp. 62
1.10.7 Sizeof Operatorp. 63
1.11 Memory Typesp. 64
1.11.1 Constants and Variablesp. 64
1.11.2 Pointersp. 66
1.11.3 Register Variablesp. 66
sfrb and sfrwp. 67
1.12 Real-Time Methodsp. 70
1.12.1 Using Interruptsp. 70
1.12.2 State Machinesp. 73
1.13 Chapter Summaryp. 79
1.14 Exercisesp. 79012
Chapter 2 The Atmel Risc Processors
2.1 Objectivesp. 83
2.2 Introductionp. 83
2.3 Architectural Overviewp. 84
2.4 Memoryp. 85
2.4.1 Flash Code Memoryp. 85
2.4.2 Data Memoryp. 85
Registersp. 86
I/O Registersp. 86
Sramp. 88
2.4.3 Eepfrom Memoryp. 90
2.5 Reset and Interrupt Functionsp. 92
2.5.1 Interruptsp. 93
2.5.2 Resetp. 97
Watchdog Timer and Resetp. 98
2.6 Parallel I/O Portsp. 100
2.7 Timer/Countersp. 104
2.7.1 Timer/Counter Prescalers and Input Selectorsp. 105
2.7.2 Timer 0p. 105
2.7.3 Timer 1p. 109
Timer 1 Prescaler and Selectorp. 110
Timer 1 Input Capture Modep. 110
Timer 1 Output Compare Modep. 114
Timer 1 Pulse Width Modulator Modep. 118
2.7.4 Timer 2p. 123
Chapter 2 Example Project: Part Cp. 125
One-second recording interval using Timer 0p. 125
Engine rpm measurement using Timer 1p. 126
Drive shaft rpm measurement using Timer 1p. 127
2.8 Serial Communication Using the UARTp. 128
2.9 Analog Interfacesp. 136
2.9.1 Analog to Digital Backgroundp. 137
2.9.2 Analog-to-Digital Converter Peripheralp. 138
2.9.3 Analog Comparator Peripheralp. 142
Measuring engine temperature using the analog-to-digitalconverter (ADC)p. 144
Sending collected data to the PCp. 145
2.10 Serial Communication Using the SPIp. 146
2.11 The AVR Risc Assembly Languageinstruction Setp. 150
2.12 Chapter Summaryp. 154
2.13 Exercisesp. 158
2.14 Laboratory Activitiesp. 159
Chapter 3 Standard I/O and Preprocessor Functions
3.1 Objectivesp. 161
3.2 Introductionp. 161
3.3 Character Input/Output Functions--Getchar() and Putchar()p. 162
3.4 Standard Output Functionsp. 168
3.4.1 Put String--puts()p. 168
3.4.2 Put String FLASH--putsf()p. 169
3.4.3 Print Formatted--printf()p. 169
3.4.4 String Print Formatted--sprintf()p. 172
3.5 Standard Input Functionsp. 173
3.5.1 Get String--gets()p. 173
3.5.2 Scan Formatted--scanf()p. 174
3.5.3 Scan String Formatted--sscanf()p. 176
3.6 Preprocessor Directivesp. 177
3.6.1 The #include Directivep. 177
3.6.2 The #define Directivep. 178
3.6.3 The #ifdef, #ifndef, #else and #endif Directivesp. 180
3.6.4 The #pragma Directivep. 181
#pragma warnp. 181
#pragma optp. 186
#pragma optsizep. 186
#pragma saveregp. 187
#pragma regallocp. 188
#pragma promotecharp. 188
#pragma ucharp. 189
#pragma libraryp. 189
3.6.5 Other Macros and Directivesp. 189
3.7 Chapter Summaryp. 190
3.8 Exercisesp. 191
3.9 Laboratory Activitiesp. 191
Chapter 4 The CodeVisionAVR c Compiler and Ide
4.1 Objectivesp. 193
4.2 Introductionp. 193
4.3 Ide Operationp. 194
4.3.1 Projectsp. 194
Open Existing Projectsp. 194
Create New Projectsp. 195
Configure Projectsp. 196
Close Projectp. 197
4.3.2 Source Filesp. 197
Open an Existing Source Filep. 197
Create a New Source Filep. 197
Add an Existing File to the Projectp. 197
4.3.3 Edit Filesp. 199
4.3.4 Print Filesp. 202
4.3.5 The File Navigatorp. 202
4.4 C Compiler Optionsp. 204
4.4.1 UARTp. 206
4.4.2 Memory Modelp. 206
4.4.3 Optimize Forp. 206
4.4.4 Program Typep. 206
4.4.5 SRAMp. 207
4.4.6 Compilationp. 207
4.5 Compile and Make Projectsp. 208
4.5.1 Compile a Projectp. 208
4.5.2 Make a Projectp. 209
4.6 Program the Target Devicep. 211
4.6.1 Chipp. 211
4.6.2 Flash and EEPROMp. 211
4.6.3 Flash Lock Bitsp. 214
4.6.4 Fuse Bitsp. 214
4.6.5 Boot Lock Bit 0 and Boot Lock Bit 1p. 214
4.6.6 Signaturep. 214
4.6.7 Chip Erasep. 215
4.6.8 Programming Speedp. 215
4.6.9 Program Allp. 215
4.6.10 Other Programmersp. 215
4.7 CodeWizardAVR Code Generatorp. 218
4.7.1 Chip Tabp. 219
4.7.2 Ports Tabp. 220
4.7.3 External IRQ Tabp. 221
4.7.4 Timers Tabp. 222
4.7.5 UART Tabp. 223
4.7.6 ADC Tabp. 225
4.7.7 Project Information Tabp. 225
4.7.8 Generate Source Codep. 227
4.8 Terminal Toolp. 239
4.9 The Atmel AVR Studio Debuggerp. 240
4.9.1 Create a COFF File for AVR Studiop. 241
4.9.2 Launch AVR Studio from CodeVisionAVRp. 241
4.9.3 Open a File for Debugp. 241
4.9.4 Start, Break, and Stepp. 242
4.9.5 Set and Clear Breakpointsp. 242
4.9.6 View and Modify Registers and Variablesp. 242
4.9.7 View and Modify the Machine Statep. 243
4.10 Chapter Summaryp. 244
4.11 Exercisesp. 245
4.12 Laboratory Activitiesp. 246
Chapter 5 Project Development
5.1 Objectivesp. 247
5.2 Introductionp. 247
5.3 Concept Development Phasep. 247
5.4 Project Development Process Stepsp. 247
5.4.1 Definition Phasep. 248
5.4.2 Design Phasep. 249
5.4.3 Test Definition Phasep. 252
5.4.4 Build and Test the Prototype Hardware Phasep. 252
5.4.5 System Integration and Software Development Phasep. 253
5.4.6 System Test Phasep. 253
5.4.7 Celebration Phasep. 253
5.5 Project Development Process Summaryp. 253
5.6 Example Project: A Weather Monitorp. 254
5.6.1 Concept Phasep. 254
5.6.2 Definition Phasep. 255
Electrical Specificationp. 256
Operational Specificationp. 257
Basic Block Diagramsp. 258
5.6.3 Measurement Considerations for the Designp. 260
Temperaturep. 260
Barometric Pressurep. 263
Humidityp. 264
Wind Speedp. 264
Wind Directionp. 267
Rainfallp. 268
Dew Point Computationp. 272
Wind Chill Computationp. 273
Battery Healthp. 273
Real Timep. 274
5.6.4 Hardware Design, Outdoor Unitp. 275
Wind Speed Inputp. 275
Rain Gauge Inputp. 275
900 MHz Transmitterp. 277
Power Supplyp. 277
5.6.5 Software Design, Outdoor Unitp. 277
5.6.6 Hardware Design, Indoor Unitp. 278
900 MHz Receiverp. 278
Power Supplyp. 281
5.6.7 Software Design, Indoor Unitp. 281
5.6.8 Test Definition Phasep. 283
Wind Directionp. 284
Wind Speedp. 284
Rain Gaugep. 284
Air Temperaturep. 284
Barometric Pressurep. 284
Relative Humidityp. 285
System Test for Complete Projectp. 285
5.6.9 Build and Test Prototype Hardware Phasep. 285
Outdoor Unit Checkoutp. 286
Indoor Unit Checkoutp. 287
5.6.10 System Integration and Software Development Phase, Outdoor Unitp. 292
Temperature, Humidity, Wind Direction, and Battery Healthp. 293
Rainfallp. 293
Wind Speedp. 296
RF Telemetryp. 297
5.6.11 System Integration and Software Development Phase, Indoor Unitp. 302
Keeping Timep. 302
Low Battery Indicationp. 305
The Buttons and the Beeperp. 306
Decoding the RF Telemetryp. 308
Collecting and Protecting Rainfall Datap. 312
Converting from Counts to Real Unitsp. 315
Routines for Controlling the LCDp. 319
Keeping the Display Up to Datep. 323
Editing the Time and Datep. 327
5.6.12 System Test Phasep. 331
5.7 Challengesp. 335
5.8 Chapter Summaryp. 336
5.9 Exercisesp. 336
5.10 Laboratory Activityp. 337
Appendix A Library Functions Referencep. 339
Appendix B Getting Started with CodeVisionAVR and the STK500p. 427
Appendix C Programming the AVR Microcontrollersp. 445
Appendix D Installing and using ThecableAVRp. 449
Appendix E The MegaAVR-DEV Development Boardp. 461
Appendix F ASCII Character Tablep. 469
Appendix G AVR Instruction Set Summaryp. 475
Appendix H Answers to Selected Exercisesp. 477
Indexp. 483
Go to:Top of Page