Author(s): Richard H. Barnett; Sarah Cox; Larry O'Cull
Edition: 2
Year: 2006
Cover
Title Page
Copyright
CONTENTS
PREFACE
INTRODUCTION
CHAPTER 1 EMBEDDED C LANGUAGE TUTORIAL
1.1 OBJECTIVES
1.2 INTRODUCTION
1.3 BEGINNING CONCEPTS
1.4 VARIABLES AND CONSTANTS
1.4.1 Variable Types
1.4.2 Variable Scope
1.4.3 Constants
1.4.4 Enumerations and Definitions
1.4.5 Storage Classes
1.4.6 Type Casting
1.5 I/O OPERATIONS
1.6 OPERATORS AND EXPRESSIONS
1.6.1 Assignment and Arithmetic Operators
1.6.2 Logical and Relational Operators
1.6.3 Increment, Decrement, and Compound Assignment
1.6.4 The Conditional Expression
1.6.5 Operator Precedence
1.7 CONTROL STATEMENTS
1.7.1 While Loop
1.7.2 Do/While Loop
1.7.3 For Loop
1.7.4 If/Else
1.7.5 Switch/Case
1.7.6 Break, Continue, and Goto
1.8 FUNCTIONS
1.8.1 Prototyping and Function Organization
1.8.2 Functions that Return Values
1.8.3 Recursion
1.9 POINTERS AND ARRAYS
1.9.1 Pointers
1.9.2 Arrays
1.9.3 Multidimensional Arrays
1.9.4 Pointers to Functions
1.10 STRUCTURES AND UNIONS
1.10.1 Structures
1.10.2 Arrays of Structures
1.10.3 Pointers to Structures
1.10.4 Unions
1.10.5 Typedef Operator
1.10.6 Bits and Bitfields
1.10.7 Sizeof Operator
1.11 MEMORY TYPES
1.11.1 Constants and Variables
1.11.2 Pointers
1.11.3 Register Variables
1.12 REAL-TIME METHODS
1.12.1 Using Interrupts
1.12.2 Real-Time Executives
1.12.3 State Machines
1.13 PROGRAMMING STYLE, STANDARDS, AND GUIDELINES
1.14 CHAPTER SUMMARY
1.15 EXERCISES
1.16 LABORATORY ACTIVITIES
CHAPTER 2 THE ATMEL RISC PROCESSORS
2.1 OBJECTIVES
2.2 INTRODUCTION
2.3 ARCHITECTURAL OVERVIEW
2.4 MEMORY
2.4.1 FLASH Code Memory
2.4.2 Data Memory
2.4.3 EEPROM Memory
2.5 RESET AND INTERRUPT FUNCTIONS
2.5.1 Interrupts
2.5.2 Reset
2.6 PARALLEL I/O PORTS
2.7 TIMER/COUNTERS
2.7.1 Timer/Counter Prescalers and Input Selectors
2.7.2 Timer 0
2.7.3 Timer 1
2.7.4 Timer 2
One–second recording interval using Timer 0
Engine rpm measurement using Timer 1
Drive shaft rpm measurement using Timer 1
2.8 SERIAL COMMUNICATION USING THE USART
2.9 ANALOG INTERFACES
2.9.1 Analog-to-Digital Background
2.9.2 Analog-to-Digital Converter Peripheral
2.9.3 Analog Comparator Peripheral
Measuring engine temperature using the analog-to-digital converter (ADC)
Sending collected data to the PC
2.10 SERIAL COMMUNICATION USING THE SPI
2.11 SERIAL COMMUNICATION USING I[sup(2)]C
2.12 THE AVR RISC ASSEMBLY LANGUAGE INSTRUCTION SET
2.13 CHAPTER SUMMARY
2.14 EXERCISES
2.15 LABORATORY ACTIVITIES
CHAPTER 3 STANDARD I/O AND PREPROCESSOR FUNCTIONS
3.1 OBJECTIVES
3.2 INTRODUCTION
3.3 CHARACTER INPUT/OUTPUT FUNCTIONS – getchar() AND putchar()
3.4 STANDARD OUTPUT FUNCTIONS
3.4.1 Put String—puts()
3.4.2 Put String FLASH—putsf()
3.4.3 Print Formatted—printf()
3.4.4 String Print Formatted—sprintf()
3.5 STANDARD INPUT FUNCTIONS
3.5.1 Get String—gets()
3.5.2 Scan Formatted—scanf()
3.5.3 Scan String Formatted—sscanf()
3.6 PREPROCESSOR DIRECTIVES
3.6.1 The #include Directive
3.6.2 The #define Directive
3.6.3 The #ifdef, #ifndef, #else, and #endif Directives
3.6.4 The #pragma Directive
3.6.5 Other Macros and Directives
3.7 CHAPTER SUMMARY
3.8 EXERCISES
3.9 LABORATORY ACTIVITIES
CHAPTER 4 THE CODEVISIONAVR C COMPILER AND IDE
4.1 OBJECTIVES
4.2 INTRODUCTION
4.3 IDE OPERATION
4.3.1 Projects
4.3.2 Source Files
4.3.3 Edit Files
4.3.4 Print Files
4.3.5 The File Navigator
4.4 C COMPILER OPTIONS
4.4.1 Memory Model
4.4.2 Optimize For
4.4.3 Optimization Level
4.4.4 Program Type
4.4.5 (s)printf Features and (s)scanf Features
4.4.6 SRAM
4.4.7 Compilation
4.4.8 Messages Tab
4.5 COMPILE AND MAKE PROJECTS
4.5.1 Compile a Project
4.5.2 Make a Project
4.6 PROGRAM THE TARGET DEVICE
4.6.1 Chip
4.6.2 FLASH and EEPROM
4.6.3 FLASH Lock Bits
4.6.4 Fuse Bits
4.6.5 Boot Lock Bit 0 and Boot Lock Bit 1
4.6.6 Signature
4.6.7 Chip Erase
4.6.8 Programming Speed
4.6.9 Program All
4.6.10 Other Programmers
4.7 CODEWIZARDAVR CODE GENERATOR
4.7.1 Chip Tab
4.7.2 Ports Tab
4.7.3 External IRQ Tab
4.7.4 Timers Tab
4.7.5 USART Tab
4.7.6 ADC Tab
4.7.7 Project Information Tab
4.7.8 Generate Source Code
4.8 TERMINAL TOOL
4.9 THE ATMEL AVR STUDIO DEBUGGER
4.9.1 Create a COFF File for AVR Studio
4.9.2 Launch AVR Studio from CodeVisionAVR
4.9.3 Open a File for Debug
4.9.4 Start, Stop, and Step
4.9.5 Set and Clear Breakpoints
4.9.6 View and Modify Registers and Variables
4.9.7 View and Modify the Machine State
4.10 CHAPTER SUMMARY
4.11 EXERCISES
4.12 LABORATORY ACTIVITIES
CHAPTER 5 PROJECT DEVELOPMENT
5.1 OBJECTIVES
5.2 INTRODUCTION
5.3 CONCEPT DEVELOPMENT PHASE
5.4 PROJECT DEVELOPMENT PROCESS STEPS
5.4.1 Definition Phase
5.4.2 Design Phase
5.4.3 Test Definition Phase
5.4.4 Build and Test the Prototype Hardware Phase
5.4.5 System Integration and Software Development Phase
5.4.6 System Test Phase
5.4.7 Celebration Phase
5.5 PROJECT DEVELOPMENT PROCESS SUMMARY
5.6 EXAMPLE PROJECT: A WEATHER MONITOR
5.6.1 Concept Phase
5.6.2 Definition Phase
5.6.3 Measurement Considerations for the Design
5.6.4 Hardware Design, Outdoor Unit
5.6.5 Software Design, Outdoor Unit
5.6.6 Hardware Design, Indoor Unit
5.6.7 Software Design, Indoor Unit
5.6.8 Test Definition Phase
5.6.9 Build and Test Prototype Hardware Phase
5.6.10 System Integration and Software Development Phase, Outdoor Unit
5.6.11 System Integration and Software Development Phase, Indoor Unit
Converting from Counts to Real Units
5.6.12 System Test Phase
5.6.13 Changing It Up
5.7 CHALLENGES
5.8 CHAPTER SUMMARY
5.9 EXERCISES
5.10 LABORATORY ACTIVITY
APPENDIX A: LIBRARY FUNCTIONS REFERENCE
APPENDIX B: GETTING STARTED WITH CODEVISIONAVR AND THE STK500
APPENDIX C: PROGRAMMING THE AVR MICROCONTROLLERS
APPENDIX D: INSTALLING AND USING THECABLEAVR
APPENDIX E: THE MEGAAVR-DEV DEVELOPMENT BOARD
APPENDIX F: ASCII TABLE
APPENDIX G: AVR INSTRUCTION SET SUMMARY
APPENDIX H: ANSWERS TO SELECTED EXERCISES
APPENDIX I: A “FAST START” TO EMBEDDED C PROGRAMMING AND THE AVR
INDEX