| |
| |
Preface | |
| |
| |
Introduction | |
| |
| |
| |
Embedded C Language Tutorial | |
| |
| |
| |
Objectives | |
| |
| |
| |
Introduction | |
| |
| |
| |
Beginning Concepts | |
| |
| |
| |
Variables and Constants | |
| |
| |
| |
Variable Types | |
| |
| |
| |
Variable Scope | |
| |
| |
Local Variables | |
| |
| |
Global Variables | |
| |
| |
| |
Constants | |
| |
| |
Numeric Constants | |
| |
| |
Character Constants | |
| |
| |
| |
Enumerations and Definitions | |
| |
| |
| |
Storage Classes | |
| |
| |
Automatic | |
| |
| |
Static | |
| |
| |
Register | |
| |
| |
| |
Type Casting | |
| |
| |
| |
I/O Operations | |
| |
| |
| |
Operators and Expressions | |
| |
| |
| |
Assignment and Arithmetic Operators | |
| |
| |
Bitwise Operators | |
| |
| |
| |
Logical and Relational Operators | |
| |
| |
Logical Operators | |
| |
| |
Relational Operators | |
| |
| |
| |
Increment, Decrement, and Compound Assignment | |
| |
| |
Increment Operators | |
| |
| |
Decrement Operators | |
| |
| |
Compound Assignment Operators | |
| |
| |
| |
The Conditional Expression | |
| |
| |
| |
Operator Precedence | |
| |
| |
| |
Control Statements | |
| |
| |
| |
While Loop | |
| |
| |
| |
Do/While Loop | |
| |
| |
| |
For Loop | |
| |
| |
| |
If/Else | |
| |
| |
If Statement | |
| |
| |
If/Else Statement | |
| |
| |
Conditional Expression | |
| |
| |
| |
Switch/Case | |
| |
| |
| |
Break, Continue, and Goto | |
| |
| |
Break | |
| |
| |
Continue | |
| |
| |
Goto | |
| |
| |
| |
Functions | |
| |
| |
| |
Prototyping and Function Organization | |
| |
| |
| |
Functions that Return Values | |
| |
| |
| |
Recursion | |
| |
| |
| |
Pointers and Arrays | |
| |
| |
| |
Pointers | |
| |
| |
| |
Arrays | |
| |
| |
| |
Multidimensional Arrays | |
| |
| |
| |
Pointers to Functions | |
| |
| |
| |
Structures and Unions | |
| |
| |
| |
Structures | |
| |
| |
| |
Arrays of Structures | |
| |
| |
| |
Pointers to Structures | |
| |
| |
| |
Unions | |
| |
| |
| |
Typedef Operator | |
| |
| |
| |
Bits and Bitfields | |
| |
| |
| |
Sizeof Operator | |
| |
| |
| |
Memory Types | |
| |
| |
| |
Constants and Variables | |
| |
| |
| |
Pointers | |
| |
| |
| |
Register Variables | |
| |
| |
sfrb and sfrw | |
| |
| |
| |
Real-Time Methods | |
| |
| |
| |
Using Interrupts | |
| |
| |
| |
Real-Time Executives | |
| |
| |
| |
State Machines | |
| |
| |
| |
Programming Style, Standards, and Guidelines | |
| |
| |
| |
Chapter Summary | |
| |
| |
| |
Exercises | |
| |
| |
| |
Laboratory Activities | |
| |
| |
| |
The Atmel Risc Processors | |
| |
| |
| |
Objectives | |
| |
| |
| |
Introduction | |
| |
| |
| |
Architectural Overview | |
| |
| |
| |
Memory | |
| |
| |
| |
Flash Code Memory | |
| |
| |
| |
Data Memory | |
| |
| |
Registers | |
| |
| |
I/O Registers | |
| |
| |
SRAM | |
| |
| |
| |
Eeprom Memory | |
| |
| |
| |
Reset and Interrupt Functions | |
| |
| |
| |
Interrupts | |
| |
| |
| |
Reset | |
| |
| |
Watchdog Timer and Reset | |
| |
| |
| |
Parallel I/O Ports | |
| |
| |
| |
Timer/Counters | |
| |
| |
| |
Timer/Counter Prescalers and Input Selectors | |
| |
| |
| |
Timer 0 | |
| |
| |
| |
Timer 1 | |
| |
| |
Timer 1 Prescaler and Selector | |
| |
| |
Timer 1 Input Capture Mode | |
| |
| |
Timer 1 Output Compare Mode | |
| |
| |
Timer 1 Pulse Width Modulator Mode | |
| |
| |
| |
Timer 2 | |
| |
| |
One-second recording interval using Timer 0 | |
| |
| |
Engine rpm measurement using Timer 1 | |
| |
| |
Drive shaft rpm measurement using Timer 1 | |
| |
| |
| |
Serial Communication Using the Usart | |
| |
| |
| |
Analog Interfaces | |
| |
| |
| |
Analog-to-Digital Background | |
| |
| |
| |
Analog-to-Digital Converter Peripheral | |
| |
| |
| |
Analog Comparator Peripheral | |
| |
| |
Measuring engine temperature using the analog-to-digital converter (ADC) | |
| |
| |
Sending collected data to the PC | |
| |
| |
| |
Serial Communication Using the SPI | |
| |
| |
| |
Serial Communication Using I[superscript 2]C | |
| |
| |
| |
The Avr Risc Assembly Language Instruction Set | |
| |
| |
| |
Chapter Summary | |
| |
| |
| |
Exercises | |
| |
| |
| |
Laboratory Activities | |
| |
| |
| |
Standard I/O and Preprocessor Functions | |
| |
| |
| |
Objectives | |
| |
| |
| |
Introduction | |
| |
| |
| |
Character Input/Output Functions - getchar() and putchar() | |
| |
| |
| |
Standard Output Functions | |
| |
| |
| |
Put String-puts() | |
| |
| |
| |
Put String FLASH-putsf() | |
| |
| |
| |
Print Formatted-printf() | |
| |
| |
| |
String Print Formatted-sprintf() | |
| |
| |
| |
Standard Input Functions | |
| |
| |
| |
Get String-gets() | |
| |
| |
| |
Scan Formatted-scanf() | |
| |
| |
| |
Scan String Formatted-sscanf() | |
| |
| |
| |
Preprocessor Directives | |
| |
| |
| |
The #include Directive | |
| |
| |
| |
The #define Directive | |
| |
| |
| |
The #ifdef, #ifndef, #else, and #endif Directives | |
| |
| |
| |
The #pragma Directive | |
| |
| |
#pragma warn | |
| |
| |
#pragma opt | |
| |
| |
#pragma optsize | |
| |
| |
#pragma savereg | |
| |
| |
#pragma regalloc | |
| |
| |
#pragma promotechar | |
| |
| |
#pragma uchar | |
| |
| |
#pragma library | |
| |
| |
| |
Other Macross and Directives | |
| |
| |
| |
Chapter Summary | |
| |
| |
| |
Exercises | |
| |
| |
| |
Laboratory Activities | |
| |
| |
| |
The Codevisionavr C Compiler and IDE | |
| |
| |
| |
Objectives | |
| |
| |
| |
Introduction | |
| |
| |
| |
IDE Operation | |
| |
| |
| |
Projects | |
| |
| |
Open Existing Projects | |
| |
| |
Create New Projects | |
| |
| |
Configure Projects | |
| |
| |
Close Project | |
| |
| |
| |
Source Files | |
| |
| |
Open an Existing Source File | |
| |
| |
Create a New Source File | |
| |
| |
Add an Existing File to the Project | |
| |
| |
| |
Edit Files | |
| |
| |
| |
Print Files | |
| |
| |
| |
The File Navigator | |
| |
| |
| |
C Compiler Options | |
| |
| |
| |
Memory Model | |
| |
| |
| |
Optimize For | |
| |
| |
| |
Optimization Level | |
| |
| |
| |
Program Type | |
| |
| |
| |
(s)printf Features and (s)scanf Features | |
| |
| |
| |
SRAM | |
| |
| |
| |
Compilation | |
| |
| |
| |
Messages Tab | |
| |
| |
| |
Compile and Make Projects | |
| |
| |
| |
Compile a Project | |
| |
| |
| |
Make a Project | |
| |
| |
| |
Program the Target Device | |
| |
| |
| |
Chip | |
| |
| |
| |
FLASH and EEPROM | |
| |
| |
| |
FLASH Lock Bits | |
| |
| |
| |
Fuse Bits | |
| |
| |
| |
Boot Lock Bit 0 and Boot Lock Bit I | |
| |
| |
| |
Signature | |
| |
| |
| |
Chip Erase | |
| |
| |
| |
Programming Speed | |
| |
| |
| |
Program All | |
| |
| |
| |
Other Programmers | |
| |
| |
| |
Codewizardavr Code Generator | |
| |
| |
| |
Chip Tab | |
| |
| |
| |
Ports Tab | |
| |
| |
| |
External IRQ Tab | |
| |
| |
| |
Timers Tab | |
| |
| |
| |
USART Tab | |
| |
| |
| |
ADC Tab | |
| |
| |
| |
Project Information Tab | |
| |
| |
| |
Generate Source Code | |
| |
| |
| |
Terminal Tool | |
| |
| |
| |
The Atmel AVR Studio Debugger | |
| |
| |
| |
Create a COFF File for AVR Studio | |
| |
| |
| |
Launch AVR Studio from CodeVisionAVR | |
| |
| |
| |
Open a File for Debug | |
| |
| |
| |
Start, Stop, and Step | |
| |
| |
| |
Set and Clear Breakpoints | |
| |
| |
| |
View and Modify Registers and Variables | |
| |
| |
| |
View and Modify the Machine State | |
| |
| |
| |
Chapter Summary | |
| |
| |
| |
Exercises | |
| |
| |
| |
Laboratory Activities | |
| |
| |
| |
Project Development | |
| |
| |
| |
Objectives | |
| |
| |
| |
Introduction | |
| |
| |
| |
Concept Development Phase | |
| |
| |
| |
Project Development Process Steps | |
| |
| |
| |
Definition Phase | |
| |
| |
| |
Design Phase | |
| |
| |
| |
Test Definition Phase | |
| |
| |
| |
Build and Test the Prototype Hardware Phase | |
| |
| |
| |
System Integration and Software Development Phase | |
| |
| |
| |
System Test Phase | |
| |
| |
| |
Celebration Phase | |
| |
| |
| |
Project Development Process Summary | |
| |
| |
| |
Example Project: A Weather Monitor | |
| |
| |
| |
Concept Phase | |
| |
| |
| |
Definition Phase | |
| |
| |
| |
Electrical Specification | |
| |
| |
| |
Operational Specification | |
| |
| |
| |
Basic Block Diagrams | |
| |
| |
| |
Measurement Considerations for the Design | |
| |
| |
| |
Temperature | |
| |
| |
| |
Barometric Pressure | |
| |
| |
| |
Humidity | |
| |
| |
| |
Wind Speed | |
| |
| |
| |
Wind Direction | |
| |
| |
| |
Rainfall | |
| |
| |
| |
Dew Point Computation | |
| |
| |
| |
Wind Chill Computation | |
| |
| |
| |
Battery Health | |
| |
| |
| |
Real Time | |
| |
| |
| |
Hardware Design, Outdoor Unit | |
| |
| |
Wind Speed Input | |
| |
| |
Rain Gauge Input | |
| |
| |
900 MHz Transmitter | |
| |
| |
Power Supply | |
| |
| |
| |
Software Design, Outdoor Unit | |
| |
| |
| |
Hardware Design, Indoor Unit | |
| |
| |
900 MHz Receiver | |
| |
| |
Power Supply | |
| |
| |
| |
Software Design, Indoor Unit | |
| |
| |
| |
Test Definition Phase | |
| |
| |
Wind Direction | |
| |
| |
Wind Speed | |
| |
| |
Rain Gauge | |
| |
| |
Air Temperature | |
| |
| |
Barometric Pressure | |
| |
| |
Relative Humidity | |
| |
| |
System Test for Complete Project | |
| |
| |
| |
Build and Test Prototype Hardware Phase | |
| |
| |
Outdoor Unit Checkout | |
| |
| |
Indoor Unit Checkout | |
| |
| |
| |
System Integration and Software Development Phase, Outdoor Unit | |
| |
| |
Temperature, Humidity, Wind Direction, and Battery Health | |
| |
| |
Rainfall | |
| |
| |
Wind Speed | |
| |
| |
RF Telemetry | |
| |
| |
| |
System Integration and Software Development Phase, Indoor Unit | |
| |
| |
Keeping Time | |
| |
| |
Low-Battery Indication | |
| |
| |
The Buttons and the Beeper | |
| |
| |
Decoding the RF Telemetry | |
| |
| |
Collecting and Protecting Rainfall Data | |
| |
| |
Converting from Counts to Real Units | |
| |
| |
Routines for Controlling the LCD | |
| |
| |
Keeping the Display Up to Date | |
| |
| |
Editing the Time and Date | |
| |
| |
| |
System Test Phase | |
| |
| |
| |
Changing It Up | |
| |
| |
Picking a Part for a Better Fit | |
| |
| |
Changes to the Schematic | |
| |
| |
Changes to I/O Mapping | |
| |
| |
Other Considerations | |
| |
| |
| |
Challenges | |
| |
| |
| |
Chapter Summary | |
| |
| |
| |
Exercises | |
| |
| |
| |
Laboratory Activity | |
| |
| |
| |
Library Functions Reference | |
| |
| |
| |
Getting Started with Codevisionavr and the STK500 | |
| |
| |
| |
Programming the AVR Microcontrollers | |
| |
| |
| |
Installing and Using Thecableavr | |
| |
| |
| |
The Megaavr-DEV Development Board | |
| |
| |
| |
Ascii Table | |
| |
| |
| |
AVR Instruction Set Summary | |
| |
| |
| |
Answers to Selected Exercises | |
| |
| |
| |
A "Fast Start" To Embedded C Programming and the AVR | |
| |
| |
Index | |