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
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. 15 |
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. 24 |
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. 29 |
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. 42 |
1.9.2 Arrays | p. 46 |
1.9.3 Multidimensional Arrays | p. 48 |
1.9.4 Pointers to Functions | p. 50 |
1.10 Structures and Unions | p. 55 |
1.10.1 Structures | p. 55 |
1.10.2 Arrays of Structures | p. 57 |
1.10.3 Pointers to Structures | p. 58 |
1.10.4 Unions | p. 59 |
1.10.5 Typedef Operator | p. 61 |
1.10.6 Bits and Bitfields | p. 62 |
1.10.7 Sizeof Operator | p. 63 |
1.11 Memory Types | p. 64 |
1.11.1 Constants and Variables | p. 64 |
1.11.2 Pointers | p. 66 |
1.11.3 Register Variables | p. 66 |
sfrb and sfrw | p. 67 |
1.12 Real-Time Methods | p. 70 |
1.12.1 Using Interrupts | p. 70 |
1.12.2 State Machines | p. 73 |
1.13 Chapter Summary | p. 79 |
1.14 Exercises | p. 79012 |
Chapter 2 The Atmel Risc Processors | |
2.1 Objectives | p. 83 |
2.2 Introduction | p. 83 |
2.3 Architectural Overview | p. 84 |
2.4 Memory | p. 85 |
2.4.1 Flash Code Memory | p. 85 |
2.4.2 Data Memory | p. 85 |
Registers | p. 86 |
I/O Registers | p. 86 |
Sram | p. 88 |
2.4.3 Eepfrom Memory | p. 90 |
2.5 Reset and Interrupt Functions | p. 92 |
2.5.1 Interrupts | p. 93 |
2.5.2 Reset | p. 97 |
Watchdog Timer and Reset | p. 98 |
2.6 Parallel I/O Ports | p. 100 |
2.7 Timer/Counters | p. 104 |
2.7.1 Timer/Counter Prescalers and Input Selectors | p. 105 |
2.7.2 Timer 0 | p. 105 |
2.7.3 Timer 1 | p. 109 |
Timer 1 Prescaler and Selector | p. 110 |
Timer 1 Input Capture Mode | p. 110 |
Timer 1 Output Compare Mode | p. 114 |
Timer 1 Pulse Width Modulator Mode | p. 118 |
2.7.4 Timer 2 | p. 123 |
Chapter 2 Example Project: Part C | p. 125 |
One-second recording interval using Timer 0 | p. 125 |
Engine rpm measurement using Timer 1 | p. 126 |
Drive shaft rpm measurement using Timer 1 | p. 127 |
2.8 Serial Communication Using the UART | p. 128 |
2.9 Analog Interfaces | p. 136 |
2.9.1 Analog to Digital Background | p. 137 |
2.9.2 Analog-to-Digital Converter Peripheral | p. 138 |
2.9.3 Analog Comparator Peripheral | p. 142 |
Measuring engine temperature using the analog-to-digitalconverter (ADC) | p. 144 |
Sending collected data to the PC | p. 145 |
2.10 Serial Communication Using the SPI | p. 146 |
2.11 The AVR Risc Assembly Languageinstruction Set | p. 150 |
2.12 Chapter Summary | p. 154 |
2.13 Exercises | p. 158 |
2.14 Laboratory Activities | p. 159 |
Chapter 3 Standard I/O and Preprocessor Functions | |
3.1 Objectives | p. 161 |
3.2 Introduction | p. 161 |
3.3 Character Input/Output Functions--Getchar() and Putchar() | p. 162 |
3.4 Standard Output Functions | p. 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 Functions | p. 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 Directives | p. 177 |
3.6.1 The #include Directive | p. 177 |
3.6.2 The #define Directive | p. 178 |
3.6.3 The #ifdef, #ifndef, #else and #endif Directives | p. 180 |
3.6.4 The #pragma Directive | p. 181 |
#pragma warn | p. 181 |
#pragma opt | p. 186 |
#pragma optsize | p. 186 |
#pragma savereg | p. 187 |
#pragma regalloc | p. 188 |
#pragma promotechar | p. 188 |
#pragma uchar | p. 189 |
#pragma library | p. 189 |
3.6.5 Other Macros and Directives | p. 189 |
3.7 Chapter Summary | p. 190 |
3.8 Exercises | p. 191 |
3.9 Laboratory Activities | p. 191 |
Chapter 4 The CodeVisionAVR c Compiler and Ide | |
4.1 Objectives | p. 193 |
4.2 Introduction | p. 193 |
4.3 Ide Operation | p. 194 |
4.3.1 Projects | p. 194 |
Open Existing Projects | p. 194 |
Create New Projects | p. 195 |
Configure Projects | p. 196 |
Close Project | p. 197 |
4.3.2 Source Files | p. 197 |
Open an Existing Source File | p. 197 |
Create a New Source File | p. 197 |
Add an Existing File to the Project | p. 197 |
4.3.3 Edit Files | p. 199 |
4.3.4 Print Files | p. 202 |
4.3.5 The File Navigator | p. 202 |
4.4 C Compiler Options | p. 204 |
4.4.1 UART | p. 206 |
4.4.2 Memory Model | p. 206 |
4.4.3 Optimize For | p. 206 |
4.4.4 Program Type | p. 206 |
4.4.5 SRAM | p. 207 |
4.4.6 Compilation | p. 207 |
4.5 Compile and Make Projects | p. 208 |
4.5.1 Compile a Project | p. 208 |
4.5.2 Make a Project | p. 209 |
4.6 Program the Target Device | p. 211 |
4.6.1 Chip | p. 211 |
4.6.2 Flash and EEPROM | p. 211 |
4.6.3 Flash Lock Bits | p. 214 |
4.6.4 Fuse Bits | p. 214 |
4.6.5 Boot Lock Bit 0 and Boot Lock Bit 1 | p. 214 |
4.6.6 Signature | p. 214 |
4.6.7 Chip Erase | p. 215 |
4.6.8 Programming Speed | p. 215 |
4.6.9 Program All | p. 215 |
4.6.10 Other Programmers | p. 215 |
4.7 CodeWizardAVR Code Generator | p. 218 |
4.7.1 Chip Tab | p. 219 |
4.7.2 Ports Tab | p. 220 |
4.7.3 External IRQ Tab | p. 221 |
4.7.4 Timers Tab | p. 222 |
4.7.5 UART Tab | p. 223 |
4.7.6 ADC Tab | p. 225 |
4.7.7 Project Information Tab | p. 225 |
4.7.8 Generate Source Code | p. 227 |
4.8 Terminal Tool | p. 239 |
4.9 The Atmel AVR Studio Debugger | p. 240 |
4.9.1 Create a COFF File for AVR Studio | p. 241 |
4.9.2 Launch AVR Studio from CodeVisionAVR | p. 241 |
4.9.3 Open a File for Debug | p. 241 |
4.9.4 Start, Break, and Step | p. 242 |
4.9.5 Set and Clear Breakpoints | p. 242 |
4.9.6 View and Modify Registers and Variables | p. 242 |
4.9.7 View and Modify the Machine State | p. 243 |
4.10 Chapter Summary | p. 244 |
4.11 Exercises | p. 245 |
4.12 Laboratory Activities | p. 246 |
Chapter 5 Project Development | |
5.1 Objectives | p. 247 |
5.2 Introduction | p. 247 |
5.3 Concept Development Phase | p. 247 |
5.4 Project Development Process Steps | p. 247 |
5.4.1 Definition Phase | p. 248 |
5.4.2 Design Phase | p. 249 |
5.4.3 Test Definition Phase | p. 252 |
5.4.4 Build and Test the Prototype Hardware Phase | p. 252 |
5.4.5 System Integration and Software Development Phase | p. 253 |
5.4.6 System Test Phase | p. 253 |
5.4.7 Celebration Phase | p. 253 |
5.5 Project Development Process Summary | p. 253 |
5.6 Example Project: A Weather Monitor | p. 254 |
5.6.1 Concept Phase | p. 254 |
5.6.2 Definition Phase | p. 255 |
Electrical Specification | p. 256 |
Operational Specification | p. 257 |
Basic Block Diagrams | p. 258 |
5.6.3 Measurement Considerations for the Design | p. 260 |
Temperature | p. 260 |
Barometric Pressure | p. 263 |
Humidity | p. 264 |
Wind Speed | p. 264 |
Wind Direction | p. 267 |
Rainfall | p. 268 |
Dew Point Computation | p. 272 |
Wind Chill Computation | p. 273 |
Battery Health | p. 273 |
Real Time | p. 274 |
5.6.4 Hardware Design, Outdoor Unit | p. 275 |
Wind Speed Input | p. 275 |
Rain Gauge Input | p. 275 |
900 MHz Transmitter | p. 277 |
Power Supply | p. 277 |
5.6.5 Software Design, Outdoor Unit | p. 277 |
5.6.6 Hardware Design, Indoor Unit | p. 278 |
900 MHz Receiver | p. 278 |
Power Supply | p. 281 |
5.6.7 Software Design, Indoor Unit | p. 281 |
5.6.8 Test Definition Phase | p. 283 |
Wind Direction | p. 284 |
Wind Speed | p. 284 |
Rain Gauge | p. 284 |
Air Temperature | p. 284 |
Barometric Pressure | p. 284 |
Relative Humidity | p. 285 |
System Test for Complete Project | p. 285 |
5.6.9 Build and Test Prototype Hardware Phase | p. 285 |
Outdoor Unit Checkout | p. 286 |
Indoor Unit Checkout | p. 287 |
5.6.10 System Integration and Software Development Phase, Outdoor Unit | p. 292 |
Temperature, Humidity, Wind Direction, and Battery Health | p. 293 |
Rainfall | p. 293 |
Wind Speed | p. 296 |
RF Telemetry | p. 297 |
5.6.11 System Integration and Software Development Phase, Indoor Unit | p. 302 |
Keeping Time | p. 302 |
Low Battery Indication | p. 305 |
The Buttons and the Beeper | p. 306 |
Decoding the RF Telemetry | p. 308 |
Collecting and Protecting Rainfall Data | p. 312 |
Converting from Counts to Real Units | p. 315 |
Routines for Controlling the LCD | p. 319 |
Keeping the Display Up to Date | p. 323 |
Editing the Time and Date | p. 327 |
5.6.12 System Test Phase | p. 331 |
5.7 Challenges | p. 335 |
5.8 Chapter Summary | p. 336 |
5.9 Exercises | p. 336 |
5.10 Laboratory Activity | p. 337 |
Appendix A Library Functions Reference | p. 339 |
Appendix B Getting Started with CodeVisionAVR and the STK500 | p. 427 |
Appendix C Programming the AVR Microcontrollers | p. 445 |
Appendix D Installing and using ThecableAVR | p. 449 |
Appendix E The MegaAVR-DEV Development Board | p. 461 |
Appendix F ASCII Character Table | p. 469 |
Appendix G AVR Instruction Set Summary | p. 475 |
Appendix H Answers to Selected Exercises | p. 477 |
Index | p. 483 |