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
Preface | p. xiii |
Introduction | p. xxi |
Chapter 1 Embedded C Language Tutorial | |
1.1 Objectives | p. 1 |
1.2 Introduction | p. 1 |
1.3 Beginning Concepts | p. 2 |
1.4 Variables and Constants | p. 4 |
1.4.1 Variable Types | p. 4 |
1.4.2 Variable Scope | p. 5 |
Local Variables | p. 5 |
Global Variables | p. 5 |
1.4.3 Constants | p. 6 |
Numeric Constants | p. 7 |
Character Constants | p. 7 |
1.4.4 Enumerations and Definitions | p. 7 |
1.4.5 Storage Classes | p. 9 |
Automatic | p. 9 |
Static | p. 9 |
Register | p. 9 |
1.4.6 Type Casting | p. 9 |
1.5 I/O Operations | p. 11 |
1.6 Operators and Expressions | p. 12 |
1.6.1 Assignment and Arithmetic Operators | p. 12 |
Bitwise Operators | p. 13 |
1.6.2 Logical and Relational Operators | p. 14 |
Logical Operators | p. 15 |
Relational Operators | p. 15 |
1.6.3 Increment, Decrement, and Compound Assignment | p. 16 |
Increment Operators | p. 16 |
Decrement Operators | p. 17 |
Compound Assignment Operators | p. 17 |
1.6.4 The Conditional Expression | p. 17 |
1.6.5 Operator Precedence | p. 18 |
1.7 Control Statements | p. 19 |
1.7.1 While Loop | p. 19 |
1.7.2 Do/While Loop | p. 21 |
1.7.3 For Loop | p. 22 |
1.7.4 If/Else | p. 23 |
If Statement | p. 23 |
If/Else Statement | p. 23 |
Conditional Expression | p. 26 |
1.7.5 Switch/Case | p. 26 |
1.7.6 Break, Continue, and Goto | p. 28 |
Break | p. 28 |
Continue | p. 28 |
Goto | p. 29 |
1.8 Functions | p. 33 |
1.8.1 Prototyping and Function Organization | p. 34 |
1.8.2 Functions that Return Values | p. 36 |
1.8.3 Recursion | p. 37 |
1.9 Pointers and Arrays | p. 41 |
1.9.1 Pointers | p. 41 |
1.9.2 Arrays | p. 45 |
1.9.3 Multidimensional Arrays | p. 47 |
1.9.4 Pointers to Functions | p. 49 |
1.10 Structures and Unions | p. 54 |
1.10.1 Structures | p. 54 |
1.10.2 Arrays of Structures | p. 56 |
1.10.3 Pointers to Structures | p. 57 |
1.10.4 Unions | p. 58 |
1.10.5 Typedef Operator | p. 60 |
1.10.6 Bits and Bitfields | p. 61 |
1.10.7 Sizeof Operator | p. 62 |
1.11 Memory Types | p. 63 |
1.11.1 Constants and Variables | p. 63 |
1.11.2 Pointers | p. 65 |
1.11.3 Register Variables | p. 65 |
sfrb and sfrw | p. 66 |
1.12 Real-Time Methods | p. 69 |
1.12.1 Using Interrupts | p. 69 |
1.12.2 Real-Time Executives | p. 72 |
1.12.3 State Machines | p. 75 |
1.13 Programming Style, Standards, and Guidelines | p. 80 |
1.14 Chapter Summary | p. 81 |
1.15 Exercises | p. 81 |
1.16 Laboratory Activities | p. 83 |
Chapter 2 The Atmel Risc Processors | |
2.1 Objectives | p. 87 |
2.2 Introduction | p. 87 |
2.3 Architectural Overview | p. 88 |
2.4 Memory | p. 89 |
2.4.1 Flash Code Memory | p. 89 |
2.4.2 Data Memory | p. 89 |
Registers | p. 90 |
I/O Registers | p. 90 |
SRAM | p. 92 |
2.4.3 Eeprom Memory | p. 94 |
2.5 Reset and Interrupt Functions | p. 97 |
2.5.1 Interrupts | p. 98 |
2.5.2 Reset | p. 101 |
Watchdog Timer and Reset | p. 102 |
2.6 Parallel I/O Ports | p. 105 |
2.7 Timer/Counters | p. 109 |
2.7.1 Timer/Counter Prescalers and Input Selectors | p. 110 |
2.7.2 Timer 0 | p. 110 |
2.7.3 Timer 1 | p. 114 |
Timer 1 Prescaler and Selector | p. 115 |
Timer 1 Input Capture Mode | p. 115 |
Timer 1 Output Compare Mode | p. 119 |
Timer 1 Pulse Width Modulator Mode | p. 123 |
2.7.4 Timer 2 | p. 128 |
One-second recording interval using Timer 0 | p. 129 |
Engine rpm measurement using Timer 1 | p. 130 |
Drive shaft rpm measurement using Timer 1 | p. 131 |
2.8 Serial Communication Using the Usart | p. 132 |
2.9 Analog Interfaces | p. 141 |
2.9.1 Analog-to-Digital Background | p. 141 |
2.9.2 Analog-to-Digital Converter Peripheral | p. 142 |
2.9.3 Analog Comparator Peripheral | p. 146 |
Measuring engine temperature using the analog-to-digital converter (ADC) | p. 149 |
Sending collected data to the PC | p. 150 |
2.10 Serial Communication Using the SPI | p. 151 |
2.11 Serial Communication Using I[superscript 2]C | p. 158 |
2.12 The Avr Risc Assembly Language Instruction Set | p. 160 |
2.13 Chapter Summary | p. 163 |
2.14 Exercises | p. 167 |
2.15 Laboratory Activities | p. 168 |
Chapter 3 Standard I/O and Preprocessor Functions | |
3.1 Objectives | p. 171 |
3.2 Introduction | p. 171 |
3.3 Character Input/Output Functions - getchar() and putchar() | p. 172 |
3.4 Standard Output Functions | p. 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 Functions | p. 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 Directives | p. 188 |
3.6.1 The #include Directive | p. 188 |
3.6.2 The #define Directive | p. 189 |
3.6.3 The #ifdef, #ifndef, #else, and #endif Directives | p. 191 |
3.6.4 The #pragma Directive | p. 196 |
#pragma warn | p. 197 |
#pragma opt | p. 197 |
#pragma optsize | p. 197 |
#pragma savereg | p. 198 |
#pragma regalloc | p. 199 |
#pragma promotechar | p. 199 |
#pragma uchar | p. 199 |
#pragma library | p. 200 |
3.6.5 Other Macross and Directives | p. 200 |
3.7 Chapter Summary | p. 201 |
3.8 Exercises | p. 202 |
3.9 Laboratory Activities | p. 202 |
Chapter 4 The Codevisionavr C Compiler and IDE | |
4.1 Objectives | p. 205 |
4.2 Introduction | p. 205 |
4.3 IDE Operation | p. 206 |
4.3.1 Projects | p. 206 |
Open Existing Projects | p. 206 |
Create New Projects | p. 207 |
Configure Projects | p. 208 |
Close Project | p. 209 |
4.3.2 Source Files | p. 209 |
Open an Existing Source File | p. 209 |
Create a New Source File | p. 209 |
Add an Existing File to the Project | p. 209 |
4.3.3 Edit Files | p. 211 |
4.3.4 Print Files | p. 214 |
4.3.5 The File Navigator | p. 214 |
4.4 C Compiler Options | p. 216 |
4.4.1 Memory Model | p. 217 |
4.4.2 Optimize For | p. 218 |
4.4.3 Optimization Level | p. 218 |
4.4.4 Program Type | p. 218 |
4.4.5 (s)printf Features and (s)scanf Features | p. 218 |
4.4.6 SRAM | p. 219 |
4.4.7 Compilation | p. 219 |
4.4.8 Messages Tab | p. 220 |
4.5 Compile and Make Projects | p. 220 |
4.5.1 Compile a Project | p. 220 |
4.5.2 Make a Project | p. 221 |
4.6 Program the Target Device | p. 222 |
4.6.1 Chip | p. 223 |
4.6.2 FLASH and EEPROM | p. 224 |
4.6.3 FLASH Lock Bits | p. 226 |
4.6.4 Fuse Bits | p. 226 |
4.6.5 Boot Lock Bit 0 and Boot Lock Bit I | p. 226 |
4.6.6 Signature | p. 226 |
4.6.7 Chip Erase | p. 227 |
4.6.8 Programming Speed | p. 227 |
4.6.9 Program All | p. 227 |
4.6.10 Other Programmers | p. 228 |
4.7 Codewizardavr Code Generator | p. 229 |
4.7.1 Chip Tab | p. 232 |
4.7.2 Ports Tab | p. 233 |
4.7.3 External IRQ Tab | p. 234 |
4.7.4 Timers Tab | p. 235 |
4.7.5 USART Tab | p. 236 |
4.7.6 ADC Tab | p. 237 |
4.7.7 Project Information Tab | p. 238 |
4.7.8 Generate Source Code | p. 239 |
4.8 Terminal Tool | p. 247 |
4.9 The Atmel AVR Studio Debugger | p. 249 |
4.9.1 Create a COFF File for AVR Studio | p. 250 |
4.9.2 Launch AVR Studio from CodeVisionAVR | p. 250 |
4.9.3 Open a File for Debug | p. 250 |
4.9.4 Start, Stop, and Step | p. 250 |
4.9.5 Set and Clear Breakpoints | p. 251 |
4.9.6 View and Modify Registers and Variables | p. 252 |
4.9.7 View and Modify the Machine State | p. 252 |
4.10 Chapter Summary | p. 253 |
4.11 Exercises | p. 253 |
4.12 Laboratory Activities | p. 255 |
Chapter 5 Project Development | |
5.1 Objectives | p. 257 |
5.2 Introduction | p. 257 |
5.3 Concept Development Phase | p. 257 |
5.4 Project Development Process Steps | p. 257 |
5.4.1 Definition Phase | p. 258 |
5.4.2 Design Phase | p. 260 |
5.4.3 Test Definition Phase | p. 261 |
5.4.4 Build and Test the Prototype Hardware Phase | p. 262 |
5.4.5 System Integration and Software Development Phase | p. 262 |
5.4.6 System Test Phase | p. 263 |
5.4.7 Celebration Phase | p. 263 |
5.5 Project Development Process Summary | p. 263 |
5.6 Example Project: A Weather Monitor | p. 263 |
5.6.1 Concept Phase | p. 263 |
5.6.2 Definition Phase | p. 264 |
5.6.2.1 Electrical Specification | p. 266 |
5.6.2.2 Operational Specification | p. 266 |
5.6.2.3 Basic Block Diagrams | p. 267 |
5.6.3 Measurement Considerations for the Design | p. 269 |
5.6.3.1 Temperature | p. 270 |
5.6.3.2 Barometric Pressure | p. 272 |
5.6.3.3 Humidity | p. 273 |
5.6.3.4 Wind Speed | p. 274 |
5.6.3.5 Wind Direction | p. 277 |
5.6.3.6 Rainfall | p. 278 |
5.6.3.7 Dew Point Computation | p. 281 |
5.6.3.8 Wind Chill Computation | p. 282 |
5.6.3.9 Battery Health | p. 283 |
5.6.3.10 Real Time | p. 283 |
5.6.4 Hardware Design, Outdoor Unit | p. 284 |
Wind Speed Input | p. 284 |
Rain Gauge Input | p. 286 |
900 MHz Transmitter | p. 286 |
Power Supply | p. 286 |
5.6.5 Software Design, Outdoor Unit | p. 286 |
5.6.6 Hardware Design, Indoor Unit | p. 287 |
900 MHz Receiver | p. 287 |
Power Supply | p. 290 |
5.6.7 Software Design, Indoor Unit | p. 290 |
5.6.8 Test Definition Phase | p. 292 |
Wind Direction | p. 293 |
Wind Speed | p. 293 |
Rain Gauge | p. 293 |
Air Temperature | p. 293 |
Barometric Pressure | p. 294 |
Relative Humidity | p. 294 |
System Test for Complete Project | p. 294 |
5.6.9 Build and Test Prototype Hardware Phase | p. 294 |
Outdoor Unit Checkout | p. 295 |
Indoor Unit Checkout | p. 297 |
5.6.10 System Integration and Software Development Phase, Outdoor Unit | p. 301 |
Temperature, Humidity, Wind Direction, and Battery Health | p. 305 |
Rainfall | p. 305 |
Wind Speed | p. 306 |
RF Telemetry | p. 306 |
5.6.11 System Integration and Software Development Phase, Indoor Unit | p. 312 |
Keeping Time | p. 312 |
Low-Battery Indication | p. 314 |
The Buttons and the Beeper | p. 316 |
Decoding the RF Telemetry | p. 318 |
Collecting and Protecting Rainfall Data | p. 321 |
Converting from Counts to Real Units | p. 324 |
Routines for Controlling the LCD | p. 325 |
Keeping the Display Up to Date | p. 331 |
Editing the Time and Date | p. 335 |
5.6.12 System Test Phase | p. 339 |
5.6.13 Changing It Up | p. 343 |
Picking a Part for a Better Fit | p. 343 |
Changes to the Schematic | p. 344 |
Changes to I/O Mapping | p. 344 |
Other Considerations | p. 348 |
5.7 Challenges | p. 349 |
5.8 Chapter Summary | p. 350 |
5.9 Exercises | p. 350 |
5.10 Laboratory Activity | p. 351 |
Appendix A Library Functions Reference | p. 353 |
Appendix B Getting Started with Codevisionavr and the STK500 | p. 453 |
Appendix C Programming the AVR Microcontrollers | p. 471 |
Appendix D Installing and Using Thecableavr | p. 475 |
Appendix E The Megaavr-DEV Development Board | p. 489 |
Appendix F Ascii Table | p. 493 |
Appendix G AVR Instruction Set Summary | p. 497 |
Appendix H Answers to Selected Exercises | p. 503 |
Appendix I A "Fast Start" To Embedded C Programming and the AVR | p. 509 |
Index | p. 519 |