Introduction |
|
xv | |
Part I Digital Logic Review And Computer Architecture Fundamentals |
|
1 | (50) |
|
Chapter 1 Number System and Digital Logic Review |
|
|
3 | (30) |
|
|
3 | (1) |
|
|
4 | (3) |
|
Unsigned Number Conversion |
|
|
7 | (5) |
|
Hex to Binary, Binary to Hex |
|
|
7 | (5) |
|
Combinational Logic Functions |
|
|
12 | (7) |
|
Combinational Building Blocks |
|
|
19 | (4) |
|
|
19 | (1) |
|
|
20 | (1) |
|
|
21 | (1) |
|
|
22 | (1) |
|
|
22 | (1) |
|
Understanding Sequential Logic |
|
|
23 | (4) |
|
|
24 | (1) |
|
|
25 | (2) |
|
Sequential Building Blocks |
|
|
27 | (3) |
|
|
27 | (1) |
|
|
28 | (1) |
|
|
28 | (2) |
|
|
30 | (1) |
|
|
31 | (1) |
|
|
32 | (1) |
|
Chapter 2 The Stored Program Machine |
|
|
33 | (18) |
|
|
33 | (1) |
|
Problem Solving the Digital Way |
|
|
34 | (1) |
|
Finite State Machine Design |
|
|
35 | (5) |
|
Finite State Machine Implementation |
|
|
37 | (3) |
|
|
40 | (8) |
|
Instruction Set Design and Assembly Language |
|
|
40 | (4) |
|
|
44 | (4) |
|
|
48 | (1) |
|
|
48 | (1) |
|
|
48 | (3) |
Part II PIC24 μC Assembly Language Programming |
|
51 | (194) |
|
Chapter 3 Introduction to the PIC24 Microcontroller Family |
|
|
53 | (42) |
|
|
53 | (1) |
|
Introduction to Microprocessors and Microcontrollers |
|
|
54 | (1) |
|
The PIC24 Microcontroller Family |
|
|
55 | (7) |
|
Program Memory Organization |
|
|
57 | (1) |
|
|
58 | (2) |
|
Arrangement of Multibyte Values in Data Memory |
|
|
60 | (2) |
|
Data Transfer Instructions and Addressing Modes |
|
|
62 | (3) |
|
Register Direct Addressing |
|
|
62 | (3) |
|
|
65 | (9) |
|
WREG—The Default Working Register |
|
|
67 | (2) |
|
|
69 | (1) |
|
|
70 | (2) |
|
Instruction Set Regularity |
|
|
72 | (2) |
|
Basic Arithmetic and Control Instructions |
|
|
74 | (5) |
|
Three-Operand Addition/Subtraction |
|
|
74 | (2) |
|
Two-Operand Addition/Subtraction |
|
|
76 | (1) |
|
Increment, Decrement Instructions |
|
|
77 | (1) |
|
|
77 | (2) |
|
A PIC24 Assembly Language Program |
|
|
79 | (12) |
|
C-to-PIC24 Assembly Language |
|
|
80 | (8) |
|
|
88 | (3) |
|
The Clock and Instruction Execution |
|
|
91 | (1) |
|
|
92 | (1) |
|
|
92 | (3) |
|
Chapter 4 Unsigned 8/16-Bit Arithmetic, Logical, and Conditional Operations |
|
|
95 | (38) |
|
|
95 | (1) |
|
Bitwise Logical Operations, Bit Operations |
|
|
96 | (4) |
|
Using the Status Register |
|
|
100 | (2) |
|
Using Shift and Rotate Operations |
|
|
102 | (3) |
|
Using Mixed 8-Bit/16-Bit Operations, Compound Operations |
|
|
105 | (4) |
|
|
108 | (1) |
|
|
108 | (1) |
|
Conditional Execution Using Bit Tests |
|
|
109 | (2) |
|
Unsigned Conditional Tests |
|
|
111 | (12) |
|
|
111 | (1) |
|
Zero, Non-Zero Conditional Tests |
|
|
112 | (3) |
|
|
115 | (1) |
|
Equality, Inequality Conditional Tests |
|
|
116 | (1) |
|
Conditional Tests for >=, >, <, and <= |
|
|
116 | (2) |
|
Comparison and Unsigned Branch Instructions |
|
|
118 | (5) |
|
Complex Conditional Expressions |
|
|
123 | (3) |
|
|
126 | (2) |
|
|
128 | (1) |
|
|
129 | (4) |
|
Chapter 5 Extended Precision and Signed Data Operations |
|
|
133 | (34) |
|
|
133 | (1) |
|
Extended Precision Operations |
|
|
134 | (13) |
|
32-Bit Assignment Operations |
|
|
134 | (2) |
|
32-Bit Bitwise Logical Operations |
|
|
136 | (1) |
|
32-Bit Addition/Subtraction |
|
|
137 | (4) |
|
32-Bit Logical Shift Right/Shift Left Operations |
|
|
141 | (1) |
|
Zero, Non-Zero Conditional Tests |
|
|
141 | (3) |
|
|
144 | (1) |
|
Comparisons of >, >=, <, and <= on Unsigned 32-Bit Operands |
|
|
145 | (1) |
|
|
146 | (1) |
|
Signed Number Representation |
|
|
147 | (6) |
|
|
147 | (1) |
|
|
148 | (1) |
|
|
149 | (2) |
|
|
151 | (1) |
|
Two's Complement Overflow |
|
|
152 | (1) |
|
Operations on Signed Data |
|
|
153 | (8) |
|
Shift Operations on Signed Data |
|
|
155 | (2) |
|
Comparisons of >, >=, <, and <= on Signed Operands |
|
|
157 | (2) |
|
Sign Extension for Mixed Precision |
|
|
159 | (2) |
|
Branch Instruction Encoding |
|
|
161 | (2) |
|
|
163 | (1) |
|
|
164 | (3) |
|
Chapter 6 Pointers and Subroutines |
|
|
167 | (46) |
|
|
167 | (1) |
|
PIC24 Indirect Addressing Modes |
|
|
168 | (4) |
|
Register Indirect with Signed Constant Offset |
|
|
170 | (1) |
|
What Instruction Forms Support Indirect Addressing |
|
|
170 | (1) |
|
Instruction Stalls Due to Data Dependencies |
|
|
171 | (1) |
|
|
172 | (2) |
|
The Stack and Call/Return, Push/Pop |
|
|
174 | (5) |
|
|
175 | (3) |
|
Call/Return and the Data Memory Stack |
|
|
178 | (1) |
|
|
179 | (1) |
|
Implementing Subroutines in Assembly Language |
|
|
179 | (7) |
|
Static versus Dynamic Parameter Allocation |
|
|
180 | (2) |
|
Using Working Registers for Subroutine Parameters and Locals |
|
|
182 | (4) |
|
|
186 | (1) |
|
|
186 | (13) |
|
Implementation of C Pointer/Array Operations in Assembly |
|
|
190 | (3) |
|
A Subroutine That Manipulates 32-Bit Data |
|
|
193 | (2) |
|
|
195 | (1) |
|
|
196 | (3) |
|
Stack Frames for Function Parameters and Local Variables |
|
|
199 | (4) |
|
Program Space Visibility and Global Variable Initialization |
|
|
203 | (3) |
|
|
206 | (2) |
|
|
208 | (5) |
|
Chapter 7 Advanced Assembly Language: Higher Math |
|
|
213 | (32) |
|
|
213 | (1) |
|
|
214 | (6) |
|
|
218 | (2) |
|
|
220 | (5) |
|
Fixed-Point and Saturating Arithmetic |
|
|
225 | (5) |
|
Decimal to x.y Binary Format |
|
|
226 | (1) |
|
x.y Binary Format to Decimal Conversion |
|
|
226 | (1) |
|
|
227 | (1) |
|
0.n Fixed-Point Format and Saturating Operations |
|
|
228 | (2) |
|
The dsPIC® Microcontroller Family |
|
|
230 | (1) |
|
Floating-Point Number Representation |
|
|
230 | (5) |
|
IEEE 754 Floating-Point Encoding |
|
|
230 | (3) |
|
Floating-Point Operations |
|
|
233 | (2) |
|
|
235 | (2) |
|
|
237 | (5) |
|
|
237 | (2) |
|
|
239 | (1) |
|
|
240 | (2) |
|
|
242 | (1) |
|
|
242 | (1) |
|
|
243 | (2) |
Part III PIC24 μC Interfacing Using The C Language |
|
245 | (398) |
|
Chapter 8 System Startup and Parallel Port I/O |
|
|
247 | (70) |
|
|
247 | (1) |
|
High-Level Languages versus Assembly Language |
|
|
248 | (2) |
|
C Compilation for the PIC24 μC |
|
|
250 | (8) |
|
Special Function Registers and Bit References |
|
|
251 | (4) |
|
PIC24 Compiler Runtime Code, Variable Qualifiers/Attributes |
|
|
255 | (1) |
|
C Macros, Inline Functions |
|
|
256 | (1) |
|
|
256 | (2) |
|
|
258 | (5) |
|
|
260 | (1) |
|
|
261 | (1) |
|
Startup Schematic: PC Serial Communication Link |
|
|
262 | (1) |
|
Startup Schematic: In-Circuit Serial Programming |
|
|
262 | (1) |
|
Startup Schematic: Application Components |
|
|
263 | (1) |
|
ledflash.c—The First C Program for PIC24 Startup |
|
|
263 | (4) |
|
|
263 | (1) |
|
|
264 | (1) |
|
An Improved LED Flash Program |
|
|
265 | (2) |
|
echo.c—Testing the Serial Link |
|
|
267 | (3) |
|
asm_echo.s—Implementing Echo in Assembly |
|
|
269 | (1) |
|
Datasheet Reading—A Critical Skill |
|
|
270 | (2) |
|
|
272 | (1) |
|
|
273 | (1) |
|
Power-On Reset Behavior and Reset Sources |
|
|
274 | (2) |
|
Watchdog Timer, Sleep, Idle, and Doze |
|
|
276 | (4) |
|
|
280 | (4) |
|
|
284 | (9) |
|
|
287 | (1) |
|
|
288 | (1) |
|
|
288 | (1) |
|
Internal Weak Pull-Ups and Pull-Downs |
|
|
289 | (1) |
|
Digital versus Analog Inputs |
|
|
290 | (1) |
|
|
291 | (1) |
|
PIO Configuration Macros/Functions |
|
|
291 | (2) |
|
LED/Switch I/O and State Machine Programming |
|
|
293 | (9) |
|
State Machine I/O Programming |
|
|
295 | (3) |
|
Extended State in a More Complex LED/Switch I/O Problem |
|
|
298 | (4) |
|
Interfacing to an LCD Module |
|
|
302 | (8) |
|
|
303 | (1) |
|
|
304 | (2) |
|
|
306 | (4) |
|
The PIC24E versus the PIC24F and PIC24H Families |
|
|
310 | (1) |
|
|
311 | (1) |
|
|
312 | (5) |
|
Chapter 9 Interrupts and a First Look at Timers |
|
|
317 | (54) |
|
|
317 | (1) |
|
|
318 | (2) |
|
PIC24 pC Interrupt Details |
|
|
320 | (5) |
|
|
320 | (2) |
|
|
322 | (1) |
|
|
322 | (1) |
|
|
323 | (1) |
|
|
324 | (1) |
|
|
325 | (4) |
|
|
325 | (2) |
|
|
327 | (2) |
|
Change Notification Interrupts |
|
|
329 | (3) |
|
|
330 | (1) |
|
Using a Change Notification Interrupt to Measure Interrupt Latency |
|
|
330 | (2) |
|
INTx External Interrupts and Remappable Pins |
|
|
332 | (4) |
|
Switch Inputs and Change Notification/INTx Interrupts |
|
|
336 | (1) |
|
Periodic Timer Interrupts |
|
|
336 | (7) |
|
Timer Macros and Support Functions |
|
|
339 | (2) |
|
|
341 | (2) |
|
Interrupt-Driven LED/Switch I/O |
|
|
343 | (10) |
|
|
343 | (3) |
|
Change Notification with a Timer |
|
|
346 | (7) |
|
|
353 | (2) |
|
A Rotary Encoder Interface |
|
|
355 | (4) |
|
|
359 | (6) |
|
On Writing and Debugging ISRs |
|
|
365 | (1) |
|
|
366 | (1) |
|
|
366 | (5) |
|
Chapter 10 Asynchronous and Synchronous Serial I/O |
|
|
371 | (78) |
|
|
371 | (1) |
|
|
372 | (2) |
|
Synchronous, Asynchronous Serial I/O |
|
|
374 | (6) |
|
Asynchronous Serial I/O Using NRZ Encoding |
|
|
375 | (5) |
|
|
380 | (6) |
|
|
383 | (1) |
|
|
384 | (1) |
|
|
384 | (2) |
|
Using the PIC24 UART with C |
|
|
386 | (4) |
|
<stdio.h> Library Functions |
|
|
389 | (1) |
|
Interrupt-Driven I/O with the PIC24 UART |
|
|
390 | (9) |
|
Interrupt-Driven UART Receive |
|
|
390 | (4) |
|
Interrupt-Driven UART Transmit |
|
|
394 | (5) |
|
|
399 | (2) |
|
The Serial Peripheral Interface (SPI) |
|
|
401 | (7) |
|
SPI Example: The MCP41xxx Digital Potentiometer |
|
|
408 | (3) |
|
SPI Example: PIC24 μC Master to DS1722 Thermometer |
|
|
411 | (3) |
|
SPI Example: PIC24 μC Master to PIC24 μC Slave |
|
|
414 | (5) |
|
|
419 | (8) |
|
|
421 | (2) |
|
|
423 | (1) |
|
Library Functions for I2C Transactions |
|
|
424 | (3) |
|
|
427 | (5) |
|
12C Example: PIC24 μC Master to D51631 Thermometer |
|
|
432 | (4) |
|
12C Example: PIC24 μC Master to 24LC515 Serial EEPROM |
|
|
436 | (5) |
|
Ping-Pong Buffering for Interrupt-Driven Streaming Data |
|
|
441 | (4) |
|
|
445 | (1) |
|
|
445 | (4) |
|
Chapter 11 Data Conversion |
|
|
449 | (40) |
|
|
449 | (1) |
|
|
450 | (3) |
|
|
450 | (3) |
|
Analog-to-Digital Conversion |
|
|
453 | (7) |
|
Successive Approximation ADC |
|
|
457 | (2) |
|
Sample and Hold Amplifiers |
|
|
459 | (1) |
|
The PIC24 Analog-to-Digital Converter |
|
|
460 | (14) |
|
|
463 | (6) |
|
PIC24 ADC Operation: Manual |
|
|
469 | (5) |
|
PIC24 ADC Operation: Recap |
|
|
474 | (1) |
|
Digital-to-Analog Conversion |
|
|
474 | (8) |
|
|
475 | (1) |
|
R-2R Resistor Ladder Flash DAC |
|
|
475 | (7) |
|
External Digital-to-Analog Converter Examples |
|
|
482 | (4) |
|
DAC Example: The Maxim548A |
|
|
483 | (3) |
|
|
486 | (1) |
|
|
486 | (3) |
|
|
489 | (52) |
|
|
489 | (1) |
|
|
490 | (6) |
|
|
492 | (4) |
|
Pulse Width, Period Measurement Using Input Capture |
|
|
496 | (11) |
|
|
497 | (1) |
|
Pulse Width Measurement Using Input Capture |
|
|
498 | (6) |
|
Using Cascade Mode for 32-Bit Precision Input Capture |
|
|
504 | (1) |
|
Period Measurement Using Input Capture |
|
|
504 | (3) |
|
Application: Using Capture Mode for an Infrared Decoder |
|
|
507 | (9) |
|
The Output Compare Module |
|
|
516 | (4) |
|
|
519 | (1) |
|
|
520 | (3) |
|
|
521 | (2) |
|
PWM Application: DC Motor Speed Control and Servo Control |
|
|
523 | (7) |
|
|
523 | (1) |
|
|
524 | (2) |
|
PWM Control of Multiple Servos |
|
|
526 | (4) |
|
|
530 | (2) |
|
Time Keeping Using Timer1 and RTCC (PIC 24H/F Families) |
|
|
532 | (6) |
|
The Real-Time Clock Calendar Module |
|
|
534 | (4) |
|
|
538 | (1) |
|
|
538 | (3) |
|
Chapter 13 Advanced Hardware Topics |
|
|
541 | (42) |
|
|
541 | (1) |
|
|
542 | (7) |
|
Using the PIC24 μC as an I2C Slave |
|
|
549 | (4) |
|
Bus Arbitration for the I2C Bus |
|
|
553 | (5) |
|
|
556 | (2) |
|
The Controller Area Network (CAN) |
|
|
558 | (4) |
|
|
562 | (10) |
|
|
570 | (1) |
|
Using an Extended Data Frame |
|
|
571 | (1) |
|
Run-Time Self-Programming |
|
|
572 | (8) |
|
A Sample Flash Application |
|
|
576 | (4) |
|
|
580 | (1) |
|
|
581 | (2) |
|
Chapter 14 Operating Systems for Embedded Systems |
|
|
583 | (60) |
|
|
583 | (1) |
|
Operating System Concepts |
|
|
584 | (12) |
|
|
587 | (1) |
|
Multitasking and Schedulers |
|
|
588 | (4) |
|
Inter-Task Coordination: Semaphores |
|
|
592 | (1) |
|
Inter-Task Coordination and Communication: Messaging |
|
|
593 | (1) |
|
|
594 | (2) |
|
Embedded Systems Operating System for the Microchip PIC24 μC |
|
|
596 | (32) |
|
|
597 | (1) |
|
|
598 | (4) |
|
|
602 | (2) |
|
ESOS Communication Services |
|
|
604 | (4) |
|
|
608 | (3) |
|
|
611 | (4) |
|
|
615 | (4) |
|
|
619 | (2) |
|
|
621 | (3) |
|
|
624 | (4) |
|
Design: Adding an ESOS Service for I2C |
|
|
628 | (13) |
|
I2C Operations Under ESOS |
|
|
629 | (3) |
|
I2C Transactions Under ESOS |
|
|
632 | (4) |
|
Application Using the ESOS I2C Service and Semaphores |
|
|
636 | (2) |
|
Application Using the ESOS I2C Service and Messaging |
|
|
638 | (3) |
|
|
641 | (1) |
|
|
642 | (1) |
Part IV Appendixes |
|
643 | (52) |
|
Appendix A PIC24 Architecture and Instruction Set Summary |
|
|
645 | (8) |
|
|
653 | (8) |
|
Voltage, Current, and Resistance |
|
|
653 | (5) |
|
|
654 | (1) |
|
|
655 | (1) |
|
|
656 | (1) |
|
|
657 | (1) |
|
|
657 | (1) |
|
|
658 | (3) |
|
Appendix C Problem Solutions |
|
|
661 | (28) |
|
|
689 | (6) |
Index |
|
695 | |