PREFACE |
|
xiii | |
INTENDED AUDIENCE |
|
xiii | |
PREREQUISITES |
|
xiv | |
ORGANIZATION |
|
xiv | |
CHAPTER CONTENTS SUMMARY |
|
xiv | |
RATIONALE |
|
xv | |
HARDWARE USED |
|
xvi | |
CD-ROM CONTENTS AND SOFTWARE USED IN THE TEXTBOOK |
|
xvi | |
ACKNOWLEDGMENTS |
|
xvii | |
AUTHOR-SPECIFIC ACKNOWLEDGMENTS |
|
xviii | |
INTRODUCTION |
|
xix | |
CHAPTER 1 EMBEDDED C LANGUAGE TUTORIAL |
|
|
|
|
|
1 | (1) |
|
|
2 | (2) |
|
1.4 VARIABLES AND CONSTANTS |
|
|
4 | (7) |
|
|
4 | (2) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
7 | (1) |
|
|
7 | (1) |
|
|
8 | (1) |
|
1.4.4 Enumerations and Definitions |
|
|
8 | (1) |
|
|
9 | (1) |
|
|
10 | (1) |
|
|
10 | (1) |
|
|
10 | (1) |
|
|
10 | (1) |
|
|
11 | (1) |
|
1.6 OPERATORS AND EXPRESSIONS |
|
|
12 | (8) |
|
1.6.1 Assignment and Arithmetic Operators |
|
|
12 | (4) |
|
|
13 | (3) |
|
1.6.2 Logical and Relational Operators |
|
|
16 | (1) |
|
|
16 | (1) |
|
|
16 | (1) |
|
1.6.3 Increment, Decrement, and Compound Assignment |
|
|
17 | (1) |
|
|
17 | (1) |
|
|
18 | (1) |
|
Compound Assignment Operators |
|
|
18 | (1) |
|
1.6.4 The Conditional Expression |
|
|
18 | (1) |
|
1.6.5 Operator Precedence |
|
|
19 | (1) |
|
|
20 | (15) |
|
|
20 | (2) |
|
|
22 | (1) |
|
|
23 | (2) |
|
|
25 | (3) |
|
|
25 | (1) |
|
|
25 | (3) |
|
|
28 | (1) |
|
|
28 | (2) |
|
1.7.6 Break, Continue, and Goto |
|
|
30 | (5) |
|
|
31 | (4) |
|
|
35 | (8) |
|
1.8.1 Prototyping and Function Organization |
|
|
36 | (2) |
|
1.8.2 Functions that Return Values |
|
|
38 | (2) |
|
|
40 | (3) |
|
|
43 | (14) |
|
|
44 | (3) |
|
|
47 | (3) |
|
1.9.3 Multidimensional Arrays |
|
|
50 | (2) |
|
1.9.4 Pointers to Functions |
|
|
52 | (5) |
|
1.10 STRUCTURES AND UNION |
|
|
57 | (10) |
|
|
57 | (2) |
|
1.10.2 Arrays of Structures |
|
|
59 | (1) |
|
1.10.3 Pointers to Structures |
|
|
60 | (2) |
|
|
62 | (2) |
|
|
64 | (1) |
|
1.10.6 Bits and Bitfields |
|
|
65 | (1) |
|
|
66 | (1) |
|
|
67 | (7) |
|
1.11.1 Constants and Variables |
|
|
67 | (4) |
|
1.11.2 Register Variables |
|
|
71 | (3) |
|
|
72 | (2) |
|
|
74 | (10) |
|
|
75 | (3) |
|
|
78 | (6) |
|
|
84 | (1) |
|
|
85 | (2) |
|
1.15 LABORATORY ACTIVITIES |
|
|
87 | (2) |
CHAPTER 2 PIC MICROCONTROLLER HARDWARE |
|
|
|
89 | (1) |
|
|
89 | (1) |
|
2.3 ARCHITECTURAL OVERVIEW |
|
|
90 | (2) |
|
|
92 | (2) |
|
|
92 | (1) |
|
|
92 | (1) |
|
2.4.3 Return Address Stack |
|
|
93 | (1) |
|
|
94 | (3) |
|
|
97 | (1) |
|
|
97 | (5) |
|
2.6.1 Parallel Slave Port Mode |
|
|
100 | (2) |
|
|
102 | (26) |
|
|
104 | (4) |
|
2.7.1.1 Timers as "Ticks" |
|
|
104 | (1) |
|
2.7.1.2 Timers Measuring Pulse Widths or Frequencies |
|
|
105 | (1) |
|
2.7.1.3 Timers as Output Devices |
|
|
106 | (2) |
|
|
108 | (3) |
|
|
111 | (10) |
|
2.7.3.1 Capture and Compare Modules |
|
|
113 | (8) |
|
|
121 | (6) |
|
|
127 | (1) |
|
|
128 | (21) |
|
2.8.1 Asynchronous Serial Port (USART) |
|
|
129 | (8) |
|
One-Second Recording Interval Using Timer0 |
|
|
134 | (1) |
|
Engine rpm Measurement Using Capture/Compare Module 1 |
|
|
135 | (2) |
|
|
137 | (1) |
|
2.8.3 Synchronous Serial Port (MSSP) |
|
|
138 | (11) |
|
|
138 | (6) |
|
|
144 | (5) |
|
2.9 ANALOG TO DIGITAL I/O |
|
|
149 | |
|
2.9.1 Analog to Digital Background |
|
|
149 | (1) |
|
2.9.2 Analog to Digital Module |
|
|
150 | (24) |
|
Measuring Engine Measurement Using the AID Converter (ADC) |
|
|
154 | |
|
|
57 | (3) |
|
|
60 | (4) |
|
|
64 | (101) |
|
2.14 LABORATORY EXERCISES |
|
|
165 | (2) |
CHAPTER 3 STANDARD I/O AND PREPROCESSOR DIRECTIVES |
|
|
|
167 | (1) |
|
|
167 | (1) |
|
3.3 CHARACTER INPUT/OUTPUT FUNCTIONS - GETCHARO AND PUTCHARO |
|
|
168 | (6) |
|
3.4 STANDARD OUTPUT FUNCTIONS |
|
|
174 | (3) |
|
3.4.1 Put String, puts(), and File Put String, fputs() |
|
|
174 | (1) |
|
3.4.2 Print Formatted, printf(), and File Print Formatted, fprintf() |
|
|
175 | (2) |
|
3.5 STANDARD INPUT FUNCTIONS |
|
|
177 | (3) |
|
3.5.1 Get String Functions - gets() and fgets() |
|
|
178 | (1) |
|
3.5.2 Get String Function - get string() |
|
|
179 | (1) |
|
3.6 STANDARD PREPROCESSOR DIRECTIVES |
|
|
180 | (10) |
|
3.6.1 The #include Directive |
|
|
181 | (1) |
|
3.6.2 The #define Directive |
|
|
181 | (3) |
|
3.6.3 The #ifdef, #ifndef, #else, and #endif Directives |
|
|
184 | (5) |
|
3.6.4 The #error Directive |
|
|
189 | (1) |
|
3.6.5 The #pragma Directive |
|
|
190 | (1) |
|
3.7 CCS-PICC FUNCTION-QUALIFYING DIRECTIVES |
|
|
190 | (2) |
|
3.7.1 The #inline and #separate Directives |
|
|
190 | (1) |
|
3.7.2 The #int default, #intglobal, and #int xxx Directives |
|
|
191 | (1) |
|
3.8 CCS-PICC PREDEFINED IDENTIFIERS |
|
|
192 | (1) |
|
3.9 CCS-PICC DEVICE SPECIFICATION DIRECTIVES |
|
|
193 | (3) |
|
3.9.1 The #device Directive |
|
|
193 | (1) |
|
3.9.2 The #fuse Directive |
|
|
194 | (1) |
|
|
195 | (1) |
|
3.10 CCS-PICC BUILT-IN LIBRARY PREPROCESSOR DIRECTIVES |
|
|
196 | (4) |
|
3.10.1 The #use delay Directive |
|
|
196 | (1) |
|
3.10.2 The #use fast_io, #use fixed_io, and #use standard_io Directives |
|
|
196 | (2) |
|
3.10.3 The #use i2c Directive |
|
|
198 | (1) |
|
3.10.4 The #use rs232 Directive |
|
|
199 | (1) |
|
3.11 CCS-PICC MEMORY CONTROL PREPROCESSOR DIRECTIVES |
|
|
200 | (5) |
|
3.11.1 The #type Directive |
|
|
200 | (1) |
|
3.11.2 The #bit Directive |
|
|
201 | (1) |
|
3.11.3 The #byte Directive |
|
|
201 | (1) |
|
3.11.4 The #locate Directive |
|
|
202 | (1) |
|
3.11.5 The #reserve Directive |
|
|
202 | (1) |
|
3.11.6 The #zero_ram Directive |
|
|
202 | (1) |
|
3.11.7 The #rom Directive |
|
|
203 | (1) |
|
3.11.8 The #org Directive |
|
|
203 | (1) |
|
3.11.9 The #asm and #endasm Directives |
|
|
204 | (1) |
|
3.12 CCS-PICC COMPILER CONTROL PREPROCESSOR DIRECTIVES |
|
|
205 | (1) |
|
3.12.1 The #case Directive |
|
|
205 | (1) |
|
3.12.2 The #opt Directive |
|
|
205 | (1) |
|
3.12.3 The #priority Directive |
|
|
206 | (1) |
|
|
206 | (1) |
|
|
207 | (1) |
|
3.15 LABORATORY ACTIVITIES |
|
|
208 | (1) |
CHAPTER 4 THE CCS-PICC C COMPILERAND IDE |
|
|
|
209 | (1) |
|
|
209 | (1) |
|
4.3 INTEGRATED DEVELOPMENT ENVIRONMENT |
|
|
210 | (1) |
|
|
210 | (4) |
|
4.4.1 Open Existing Projects |
|
|
211 | (1) |
|
4.4.2 Create New Projects |
|
|
211 | (1) |
|
4.4.3 Setting the Include Directories for a Project |
|
|
212 | (1) |
|
|
212 | (2) |
|
|
214 | (1) |
|
4.5 PIC WIZARD CODE GENERATOR |
|
|
214 | (10) |
|
|
216 | (1) |
|
|
217 | (1) |
|
|
218 | (1) |
|
|
218 | (2) |
|
|
220 | (1) |
|
|
220 | (1) |
|
|
220 | (2) |
|
|
222 | (1) |
|
|
222 | (2) |
|
|
224 | (1) |
|
4.6.1 Open an Existing Source File |
|
|
225 | (1) |
|
4.6.2 Create a New Source File |
|
|
225 | (1) |
|
4.6.3 Changing the Main Source File for a Project |
|
|
225 | (1) |
|
|
225 | (2) |
|
|
225 | (1) |
|
4.7.2 Indentation and Tabs |
|
|
226 | (1) |
|
|
227 | (1) |
|
4.7.4 Syntax Highlighting |
|
|
227 | (1) |
|
4.7.5 Other Editor Options |
|
|
227 | (1) |
|
|
227 | (5) |
|
|
228 | (1) |
|
|
228 | (1) |
|
|
229 | (1) |
|
|
230 | (1) |
|
|
230 | (1) |
|
|
230 | (1) |
|
|
230 | (1) |
|
|
230 | (1) |
|
|
230 | (2) |
|
|
232 | (1) |
|
4.9 PROGRAM THE TARGET DEVICE |
|
|
232 | (1) |
|
|
232 | (4) |
|
|
232 | (1) |
|
|
233 | (1) |
|
|
233 | (1) |
|
|
234 | (1) |
|
4.10.5 Serial Port Monitor |
|
|
234 | (2) |
|
|
236 | (6) |
|
4.11.1 Launch MPLAB from CCS-PICC |
|
|
236 | (1) |
|
4.11.2 MPLAB Workspace and Project |
|
|
237 | (1) |
|
4.11.3 Simulator Development Mode |
|
|
238 | (1) |
|
4.11.4 Compiling under MPLAB |
|
|
238 | (1) |
|
4.11.5 Source File and Program Memory Windows |
|
|
238 | (1) |
|
|
239 | (1) |
|
4.11.7 Debugging Commands |
|
|
239 | (1) |
|
4.11.8 Set and Clear Breakpoints |
|
|
239 | (1) |
|
|
240 | (1) |
|
|
240 | (1) |
|
4.11.11 File Registers (RAM)Window |
|
|
241 | (1) |
|
|
241 | (1) |
|
4.11.13 View and Modify the Machine State |
|
|
241 | (1) |
|
|
242 | (1) |
|
|
243 | (1) |
|
4.14 LABORATORY ACTIVITIES |
|
|
244 | (3) |
CHAPTER 5 PROJECT DEVELOPMENT |
|
|
|
247 | (1) |
|
|
247 | (1) |
|
5.3 CONCEPT DEVELOPMENT PHASE |
|
|
247 | (1) |
|
5.4 PROJECT DEVELOPMENT PROCESS STEPS |
|
|
247 | (6) |
|
|
248 | (2) |
|
|
250 | (1) |
|
5.4.3 Test Definition Phase |
|
|
251 | (1) |
|
5.4.4 Build and Test the Prototype Hardware Phase |
|
|
252 | (1) |
|
5.4.5 System Integration and Software Development Phase |
|
|
252 | (1) |
|
|
253 | (1) |
|
|
253 | (1) |
|
5.5 PROJECT DEVELOPMENT PROCESS SUMMARY |
|
|
253 | (1) |
|
5.6 EXAMPLE PROJECT: AN ELECTRONIC SCOOTER |
|
|
253 | (82) |
|
|
253 | (1) |
|
|
254 | (5) |
|
5.6.2.1 Preliminary Product Specification |
|
|
255 | (1) |
|
5.6.2.2 Operational Specification |
|
|
256 | (1) |
|
5.6.2.3 Basic Block Diagrams |
|
|
257 | (2) |
|
5.6.3 System Considerations for the Design |
|
|
259 | (10) |
|
5.6.3.1 Drive Requirements (According to Newton) |
|
|
259 | (4) |
|
|
263 | (2) |
|
5.6.3.3 Vehicle Speed Measurement |
|
|
265 | (1) |
|
5.6.3.4 Battery Health Measurement |
|
|
266 | (1) |
|
5.6.3.5 Motor Current Measurement |
|
|
266 | (1) |
|
5.6.3.6 Brake Control Measurement |
|
|
267 | (1) |
|
5.6.3.7 Electronic Braking |
|
|
268 | (1) |
|
5.6.4 Hardware Design - Drive Unit |
|
|
269 | (6) |
|
|
269 | (2) |
|
|
271 | (1) |
|
|
271 | (1) |
|
|
272 | (1) |
|
|
272 | (1) |
|
|
273 | (1) |
|
|
274 | (1) |
|
|
274 | (1) |
|
5.6.5 Software Design - Drive Unit |
|
|
275 | (3) |
|
5.6.6 Hardware Design - Display Unit |
|
|
278 | (4) |
|
|
278 | (3) |
|
Buttons, Lights, and Sound |
|
|
281 | (1) |
|
5.6.7 Software Design - Display Unit |
|
|
282 | (3) |
|
5.6.8 Test Definition Phase |
|
|
285 | (1) |
|
|
285 | (1) |
|
|
285 | (1) |
|
|
285 | (1) |
|
|
285 | (1) |
|
System Test for the Complete Project |
|
|
285 | (1) |
|
5.6.9 Build and Test Prototype Hardware Phase |
|
|
286 | (6) |
|
|
286 | (3) |
|
|
289 | (3) |
|
5.6.10 System Integration and Software Development Phase, Drive Unit |
|
|
292 | (29) |
|
|
293 | (4) |
|
Battery Health and Motor Current Monitoring |
|
|
297 | (1) |
|
|
298 | (1) |
|
|
298 | (23) |
|
5.6.11 System Integration and Software Development Phase, Display Unit |
|
|
321 | (8) |
|
The Collection and Conversion of the CAN Data |
|
|
321 | (3) |
|
The Buttons, Beeper, and Indicators |
|
|
324 | (5) |
|
|
329 | (1) |
|
|
329 | (6) |
|
|
335 | (1) |
|
|
336 | (1) |
|
|
336 | (1) |
|
|
337 | (2) |
APPENDIX A LIBRARY FUNCTIONS REFERENCE |
|
339 | (98) |
APPENDIX B PROGRAMMING THE PIC MICROCONTROLLERS |
|
437 | (4) |
APPENDIX C CCS ICD-S SERIAL IN-SYSTEM PROGRAMMER/DEBUGGER |
|
441 | (2) |
APPENDIX D MICROCHIP ICD 2 SERIAL IN-SYSTEM PROGRAMMER/DEBUGGER |
|
443 | (4) |
APPENDIX E THE "FLASH PIC-DEV" DEVELOPMENT BOARD |
|
447 | (6) |
APPENDIX F ASCII TABLE |
|
453 | (6) |
APPENDIX G PIC 16F877 INSTRUCTION SET SUMMARY |
|
459 | (10) |
APPENDIX H PIC 18F458 INSTRUCTION SET SUMMARY |
|
469 | (8) |
APPENDIX I ANSWERSTO SELECTED QUESTIONS (BY CHAPTER) |
|
477 | (8) |
INDEX |
|
485 | |