Preface |
|
xv | |
Chapter 1 Basic Electronics |
|
1 | |
|
|
1 | |
|
|
2 | |
|
|
3 | |
|
|
4 | |
|
|
4 | |
|
|
4 | |
|
|
5 | |
|
|
5 | |
|
|
6 | |
|
|
6 | |
|
|
8 | |
|
|
9 | |
|
1.5.2 Revisiting Ohm's Law |
|
|
9 | |
|
1.5.3 Resistors in Series and Parallel |
|
|
10 | |
|
|
12 | |
|
1.5.5 Capacitors in Series and in Parallel |
|
|
13 | |
|
|
14 | |
|
|
15 | |
|
|
15 | |
|
1.6.1 Integrated Circuits |
|
|
16 | |
|
1.6.2 Semiconductor Electronics |
|
|
16 | |
|
1.6.3 P-Type and N-Type Silicon |
|
|
17 | |
|
|
17 | |
Chapter 2 Number Systems |
|
19 | |
|
|
19 | |
|
|
19 | |
|
|
20 | |
|
2.1 The Origins of the Decimal System |
|
|
20 | |
|
2.1.1 Number Systems for Digital-Electronics |
|
|
22 | |
|
2.1.2 Positional Characteristics |
|
|
22 | |
|
2.1.3 Radix or Base of a Number System |
|
|
23 | |
|
|
23 | |
|
|
24 | |
|
|
24 | |
|
2.2.3 Rational, Irrational, and Imaginary Numbers |
|
|
24 | |
|
2.3 Radix Representations |
|
|
25 | |
|
2.3.1 Decimal versus Binary Numbers |
|
|
25 | |
|
2.3.2 Hexadecimal and Octal |
|
|
26 | |
|
2.4 Number System Conversions |
|
|
27 | |
|
2.4.1 Binary-to-ASCII-Decimal |
|
|
28 | |
|
2.4.2 Binary-to-Hexadecimal Conversion |
|
|
29 | |
|
2.4.3 Decimal-to-Binary Conversion |
|
|
29 | |
Chapter 3 Data Types and Data Storage |
|
33 | |
|
3.0 Electronic-Digital Machines |
|
|
33 | |
|
3.1 Character Representations |
|
|
33 | |
|
|
34 | |
|
|
36 | |
|
|
36 | |
|
3.2 Storage and Encoding of Integers |
|
|
37 | |
|
3.2.1 Signed and Unsigned Representations |
|
|
37 | |
|
|
38 | |
|
|
39 | |
|
3.2.4 Sign-Magnitude Representation |
|
|
40 | |
|
3.2.5 Radix Complement Representation |
|
|
41 | |
|
3.3 Encoding of Fractional Numbers |
|
|
44 | |
|
3.3.1 Fixed-Point Representations |
|
|
45 | |
|
3.3.2 Floating-Point Representations |
|
|
46 | |
|
3.3.3 Standardized Floating-Point Representations |
|
|
47 | |
|
3.3.4 IEEE 754 Single Format |
|
|
48 | |
|
3.3.5 Encoding and Decoding Floating-Point Numbers |
|
|
50 | |
|
3.4 Binary-Coded Decimals (BCD) |
|
|
51 | |
|
|
52 | |
Chapter 4 Digital Logic, Arithmetic, and Conversions |
|
55 | |
|
4.0 Microcontroller Logic and Arithmetic |
|
|
55 | |
|
|
55 | |
|
|
56 | |
|
|
56 | |
|
|
57 | |
|
|
57 | |
|
|
57 | |
|
|
58 | |
|
4.2 Microcontroller Arithmetic |
|
|
58 | |
|
4.2.1 Unsigned and Two's Complement Arithmetic |
|
|
58 | |
|
4.2.2 Operations on Decimal Numbers |
|
|
60 | |
|
4.3 Bit Manipulations and Auxiliary Operations |
|
|
62 | |
|
4.3.1 Bit Shift and Rotate |
|
|
62 | |
|
4.3.2 Comparison Operations |
|
|
63 | |
|
4.3.3 Other Support Operations |
|
|
63 | |
|
4.4 Unsigned Binary Arithmetic |
|
|
64 | |
|
4.4.1 Multi-byte Unsigned Addition |
|
|
64 | |
|
4.4.2 Unsigned Multiplication |
|
|
65 | |
|
|
67 | |
|
4.5 Signed Binary Arithmetic |
|
|
67 | |
|
4.5.1 Overflow Detection in Signed Arithmetic |
|
|
69 | |
|
4.5.2 Sign Extension Operations |
|
|
70 | |
|
4.5.3 Multi-byte Signed Operations |
|
|
71 | |
|
4.6 Data Format Conversions |
|
|
72 | |
|
4.6.1 BCD Digits to ASCII Decimal |
|
|
72 | |
|
4.6.2 Unsigned Binary to ASCII Decimal Digits |
|
|
73 | |
|
4.6.3 ASCII Decimal String to Unsigned Binary |
|
|
73 | |
|
4.6.4 Unsigned Binary to ASCII Hexadecimal Digits |
|
|
75 | |
|
4.6.6 Signed Numerical Conversions |
|
|
76 | |
Chapter 5 Circuits and Logic Gates |
|
77 | |
|
|
77 | |
|
|
78 | |
|
5.1.1 The Light-Emitting Diode (LED) |
|
|
79 | |
|
|
81 | |
|
|
81 | |
|
|
83 | |
|
|
84 | |
|
5.4 Transistor-Transistor Logic |
|
|
85 | |
|
|
86 | |
|
|
87 | |
|
|
87 | |
|
|
88 | |
|
|
88 | |
|
5.4.6 Positive and Negative Logic |
|
|
89 | |
|
|
90 | |
|
5.4.8 Schmitt Trigger Inverter |
|
|
91 | |
|
5.5 Other TTL Logic Families |
|
|
93 | |
|
|
93 | |
Chapter 6 Circuit Components |
|
95 | |
|
|
95 | |
|
6.1 Clocked Logic and Flip-flops |
|
|
96 | |
|
|
96 | |
|
6.1.2 Clocked RS Flip-flop |
|
|
98 | |
|
|
99 | |
|
6.1.4 The Edge-triggered D Flip-flop |
|
|
100 | |
|
6.1.5 Preset and Clear Signals |
|
|
101 | |
|
6.1.6 D Flip-flop Waveform Action |
|
|
102 | |
|
6.1.7 Flip-flop Applications |
|
|
103 | |
|
|
103 | |
|
|
104 | |
|
|
105 | |
|
|
106 | |
|
6.2.4 Microcontroller Clocks |
|
|
106 | |
|
6.3 Frequency Dividers and Counters |
|
|
107 | |
|
|
107 | |
|
6.3.2 The JK Flip-flop Counter |
|
|
107 | |
|
|
108 | |
|
|
110 | |
|
6.3.5 Synchronous Counters |
|
|
110 | |
|
|
112 | |
|
|
113 | |
|
6.4 Multiplexers and Demultiplexers |
|
|
115 | |
|
|
115 | |
|
|
118 | |
|
6.4.3 Multiplexer and Demultiplexer ICs |
|
|
118 | |
|
|
118 | |
|
|
118 | |
|
6.5.2 Switch Contact Bounce |
|
|
120 | |
|
|
121 | |
|
|
122 | |
|
|
122 | |
|
6.6.2 Liquid Crystal Displays |
|
|
124 | |
|
|
125 | |
Chapter 7 The Microchip PIC |
|
129 | |
|
7.0 The PICMicro Microcontroller |
|
|
129 | |
|
7.0.1 Programming the PIC |
|
|
130 | |
|
|
131 | |
|
|
131 | |
|
7.0.2 Prototyping the PIC Circuit |
|
|
132 | |
|
|
134 | |
|
7.1.1 Baseline PIC Family |
|
|
134 | |
|
|
135 | |
|
|
135 | |
|
|
138 | |
|
7.1.2 Mid-range PIC Family |
|
|
138 | |
|
|
139 | |
|
7.1.3 High-Performance PIC Family |
|
|
139 | |
|
|
139 | |
Chapter 8 Mid-range PIC Architecture |
|
141 | |
|
8.0 Processor Architecture and Design |
|
|
142 | |
|
8.0.1 Harvard Architecture |
|
|
142 | |
|
|
143 | |
|
8.0.3 Single-word Instructions |
|
|
143 | |
|
|
144 | |
|
8.0.5 Mid-Range Device Versions |
|
|
145 | |
|
8.1 The Mid-range Core Features |
|
|
145 | |
|
|
145 | |
|
|
147 | |
|
|
148 | |
|
8.2 Mid-Range CPU and Instruction Set |
|
|
149 | |
|
8.2.1 Mid-Range Instruction Set |
|
|
149 | |
|
8.2.2 STATUS and OPTION Registers |
|
|
151 | |
|
|
153 | |
|
8.3.1 EEPROM in Mid-Range PICs |
|
|
153 | |
|
8.4 Data Memory Organization |
|
|
154 | |
|
|
154 | |
|
|
154 | |
|
|
154 | |
|
|
155 | |
|
|
157 | |
|
8.4.3 Indirect Addressing |
|
|
158 | |
|
8.5 Mid-range I/O and Peripheral Modules |
|
|
158 | |
|
|
159 | |
|
|
160 | |
|
8.5.3 Capture-and-Compare Module |
|
|
160 | |
|
8.5.4 Master Synchronous Serial Port (MSSP) Module |
|
|
161 | |
|
|
161 | |
|
|
161 | |
Chapter 9 PIC Programming: Tools and Techniques |
|
163 | |
|
|
163 | |
|
|
164 | |
|
9.1 Integrated Development Environment |
|
|
165 | |
|
|
165 | |
|
9.1.2 Creating the Project |
|
|
167 | |
|
9.1.3 Project Build Options |
|
|
169 | |
|
9.1.4 Building the Project |
|
|
169 | |
|
9.2 Simulators and Debuggers |
|
|
170 | |
|
|
171 | |
|
9.2.2 MPLAB Hardware Debuggers |
|
|
172 | |
|
9.2.3 A "Quick-and-Dirty" Debugger |
|
|
174 | |
|
|
174 | |
|
9.4 Engineering PIC Software |
|
|
175 | |
|
9.4.1 Using Program Comments |
|
|
176 | |
|
|
176 | |
|
|
177 | |
|
|
178 | |
|
9.4.2 Defining Data Elements |
|
|
179 | |
|
|
179 | |
|
|
180 | |
|
|
180 | |
|
|
180 | |
|
Deprecated Banking Instructions |
|
|
181 | |
|
9.4.4 Processor and Configuration Controls |
|
|
182 | |
|
|
182 | |
|
|
184 | |
|
9.4.6 Errorlevel Directive |
|
|
186 | |
|
|
186 | |
Chapter 10 Programming Essentials: Input and Output |
|
189 | |
|
10.0 16F84A Programming Template |
|
|
189 | |
|
10.1 Introducing the 16F84A |
|
|
191 | |
|
10.1.1 Template Circuit for 16F84A |
|
|
191 | |
|
|
191 | |
|
|
192 | |
|
10.1.3 Comparisons in PIC Programming |
|
|
193 | |
|
The Infamous PIC Carry Flag |
|
|
194 | |
|
10.2 Simple Circuits and Programs |
|
|
194 | |
|
10.2.1 A Single LED Circuit |
|
|
194 | |
|
|
196 | |
|
10.2.2 LED/Pushbutton Circuit |
|
|
199 | |
|
10.2.3 Multiple LED Circuit |
|
|
202 | |
|
10.3 Programming the Seven-segment LED |
|
|
204 | |
|
10.4 A Demonstration Board |
|
|
206 | |
|
10.4.1 PCB Images for Demo Board |
|
|
206 | |
|
|
208 | |
Chapter 11 Interrupts |
|
211 | |
|
11.0 Interrupts on the 16F84 |
|
|
211 | |
|
11.0.1 The Interrupt Control Register |
|
|
211 | |
|
11.0.2 The OPTION Register |
|
|
212 | |
|
|
213 | |
|
11.1.1 Port-B External Interrupt |
|
|
214 | |
|
|
214 | |
|
11.1.3 Port-B Line Change Interrupt |
|
|
215 | |
|
Multiple External Interrupts |
|
|
217 | |
|
11.1.4 EEPROM Data Write Interrupt |
|
|
217 | |
|
|
217 | |
|
11.2.1 Context Saving Operations |
|
|
218 | |
|
Saving w and STATUS Registers |
|
|
218 | |
|
11.3 Interrupt Programming |
|
|
218 | |
|
11.3.1 Programming the External Interrupt |
|
|
219 | |
|
RB0 Interrupt Initialization |
|
|
220 | |
|
RB0 Interrupt Service Routine |
|
|
221 | |
|
11.3.2 Wakeup from SLEEP Using the RBO Interrupt |
|
|
222 | |
|
|
223 | |
|
11.3.3 Port-B Bits 4-7 Status Change Interrupt |
|
|
224 | |
|
RB4-7 Interrupt Initialization |
|
|
225 | |
|
RB4-7 Change Interrupt Service Routine |
|
|
227 | |
|
|
229 | |
|
11.4.1 The RB0Int Program |
|
|
229 | |
|
11.4.2 The SleepDemo Program |
|
|
232 | |
|
11.4.3 The RB4to7Int Program |
|
|
235 | |
Chapter 12 Timers and Counters |
|
241 | |
|
12.0 The 16F84 Timer0 Module |
|
|
241 | |
|
|
241 | |
|
|
242 | |
|
|
242 | |
|
|
243 | |
|
|
244 | |
|
|
245 | |
|
The Black-Ammerman Method |
|
|
245 | |
|
|
246 | |
|
|
247 | |
|
12.3.1 Programming a Counter |
|
|
247 | |
|
A Timer/Counter Test Circuit |
|
|
248 | |
|
|
248 | |
|
12.3.2 Timer0 as a Simple Delay Timer |
|
|
250 | |
|
12.3.3 Measured Time Lapse |
|
|
252 | |
|
|
255 | |
|
|
259 | |
|
12.4.1 Watchdog Timer Programming |
|
|
260 | |
|
|
260 | |
|
12.5.1 The Tmr0Counter program |
|
|
260 | |
|
12.5.2 The Timer0 Program |
|
|
263 | |
|
12.5.3 The LapseTimer Program |
|
|
265 | |
|
12.5.4 The LapseTmrint Program |
|
|
269 | |
Chapter 13 LCD Interfacing and Programming |
|
275 | |
|
13.0 LCD Features and Architecture |
|
|
275 | |
|
13.0.1 LCD Functions and Components |
|
|
276 | |
|
|
276 | |
|
|
276 | |
|
|
276 | |
|
|
276 | |
|
Character Generator ROM (CGROM) |
|
|
276 | |
|
Character Generator RAM (CGRAM) |
|
|
277 | |
|
Timing Generation Circuit |
|
|
277 | |
|
Liquid Crystal Display Driver Circuit |
|
|
278 | |
|
Cursor/Blink Control Circuit |
|
|
278 | |
|
13.0.2 Connectivity and Pin-Out |
|
|
278 | |
|
13.1 Interfacing with the HD44780 |
|
|
279 | |
|
13.1.1 Busy Flag or Timed Delay Options |
|
|
280 | |
|
|
281 | |
|
|
281 | |
|
13.1.4 Display Memory Mapping |
|
|
281 | |
|
13.2 HD44780 Instruction Set |
|
|
283 | |
|
13.2.1 Instruction Set Overview |
|
|
283 | |
|
|
283 | |
|
|
284 | |
|
|
284 | |
|
Display and Cursor ON/OFF |
|
|
284 | |
|
|
284 | |
|
|
285 | |
|
|
285 | |
|
|
285 | |
|
Read busy flag and Address register |
|
|
285 | |
|
|
285 | |
|
|
286 | |
|
13.2.2 A 16F84 8-bit Data Mode Circuit |
|
|
286 | |
|
|
287 | |
|
13.3.1 Defining Constants and Variables |
|
|
287 | |
|
Using MPLAB Data Directives |
|
|
289 | |
|
13.3.2 LCD Initialization |
|
|
290 | |
|
|
290 | |
|
|
291 | |
|
|
291 | |
|
|
292 | |
|
|
292 | |
|
|
293 | |
|
13.3.3 Auxiliary Operations |
|
|
293 | |
|
|
293 | |
|
|
295 | |
|
|
295 | |
|
|
296 | |
|
13.3.4 Text Data Storage and Display |
|
|
298 | |
|
Generating and Storing a Text String |
|
|
299 | |
|
Displaying the Text String |
|
|
301 | |
|
13.3.5 Data Compression Techniques |
|
|
302 | |
|
|
302 | |
|
|
304 | |
|
|
306 | |
|
|
306 | |
|
|
316 | |
|
|
327 | |
Chapter 14 Communications |
|
339 | |
|
14.0 PIC Communications Overview |
|
|
339 | |
|
14.1 Serial Data Transmission |
|
|
340 | |
|
14.1.1 Asynchronous Serial Transmission |
|
|
340 | |
|
14.1.2 Synchronous Serial Transmission |
|
|
342 | |
|
14.1.3 PIC Serial Communications |
|
|
342 | |
|
14.1.4 The RS-232-C Standard |
|
|
343 | |
|
|
344 | |
|
|
344 | |
|
|
345 | |
|
|
345 | |
|
|
346 | |
|
|
347 | |
|
14.1.5 The EIA-485 Standard |
|
|
349 | |
|
EIA-485 in PIC-based Systems |
|
|
350 | |
|
14.2 Parallel Data Transmission |
|
|
350 | |
|
14.2.1 PIC Parallel Slave Port (PSP) |
|
|
351 | |
|
14.3 PIC "Free-style" Serial Programming |
|
|
351 | |
|
14.3.1 PIC-to-PIC Serial Communications |
|
|
352 | |
|
PIC-to-PIC Serial Communications Circuits |
|
|
352 | |
|
PIC-to-PIC Serial Communications Programs |
|
|
354 | |
|
14.3.2 Program Using Shift Register ICs |
|
|
360 | |
|
The 74HC165 Parallel-to-Serial Shift Register |
|
|
361 | |
|
74HC164 Serial-to-Parallel Shift Register |
|
|
364 | |
|
14.4 PIC Protocol-based Serial Programming |
|
|
366 | |
|
14.4.1 RS-232-C Communications on the 16F84 |
|
|
366 | |
|
The RS-232-C Transceiver IC |
|
|
367 | |
|
|
368 | |
|
|
368 | |
|
|
369 | |
|
|
371 | |
|
14.4.2 RS-232-C Communications on the 16F87x |
|
|
375 | |
|
|
376 | |
|
The USART Baud Rate Generator |
|
|
376 | |
|
16F87x USART Asynchronous Transmitter |
|
|
379 | |
|
16F87x USART Asynchronous Receiver |
|
|
380 | |
|
PIC-to-PC RS-232-C Communications Circuit |
|
|
381 | |
|
16F877 PIC Initialization Code |
|
|
381 | |
|
USART Receive and Transmit Routines |
|
|
384 | |
|
The USART Receive Interrupt |
|
|
386 | |
|
|
389 | |
|
|
389 | |
|
|
394 | |
|
14.5.3 Seria16465 Program |
|
|
400 | |
|
|
404 | |
|
|
420 | |
|
|
438 | |
Chapter 15 Data EEPROM Programming |
|
459 | |
|
15.0 PIC Internal EEPROM Memory |
|
|
460 | |
|
15.0.1 EEPROM Programming on the 16F84 |
|
|
460 | |
|
Reading EEPROM Data Memory on the 16F84 |
|
|
460 | |
|
16F84 EEPROM Data Memory Write |
|
|
461 | |
|
16F84 EEPROM Demonstration Program |
|
|
462 | |
|
15.0.2 EEPROM Programming on the 16F87x |
|
|
465 | |
|
Reading EEPROM Data Memory on the 16F87x |
|
|
467 | |
|
Writing to EEPROM Data Memory in the 16F87x |
|
|
467 | |
|
GFR Access Issue in the 16F87x |
|
|
469 | |
|
15.0.3 16F87x EEPROM Circuit and Program |
|
|
469 | |
|
15.1 EEPROM Devices and Interfaces |
|
|
475 | |
|
15.1.1 The 12C Serial Interface |
|
|
476 | |
|
15.1.2 12C Communications |
|
|
476 | |
|
15.1.3 EEPROM Communications Conditions |
|
|
477 | |
|
15.1.4 EEPROM Write Operation |
|
|
478 | |
|
15.1.5 EEPROM Read Operation |
|
|
478 | |
|
15.1.6 12C EEPROM Devices |
|
|
479 | |
|
15.1.7 PIC Master Synchronous Serial Port (MSSP) |
|
|
480 | |
|
|
482 | |
|
15.1.8 I2C Serial EEPROM Programming on the 16F877 |
|
|
486 | |
|
IC2 Initialization Procedure |
|
|
486 | |
|
|
488 | |
|
|
490 | |
|
|
492 | |
|
|
492 | |
|
|
504 | |
|
|
521 | |
Chapter 16 Analog to Digital and Realtime Clocks |
|
543 | |
|
|
544 | |
|
16.0.1 Converter Resolution |
|
|
544 | |
|
16.0.2 ADC Implementation |
|
|
545 | |
|
16.1 A/D Integrated Circuits |
|
|
546 | |
|
16.1.1 ADCO331 Sample Circuit and Program |
|
|
547 | |
|
16.2 PIC On-Board A/D Hardware |
|
|
549 | |
|
16.2.1 A/D Module on the 16F87x |
|
|
549 | |
|
|
550 | |
|
|
552 | |
|
|
554 | |
|
16.2.2 A/D Module Sample Circuit and Program |
|
|
554 | |
|
|
558 | |
|
16.3.1 The NJU6355 Realtime Clock |
|
|
558 | |
|
16.3.2 RTC Demonstration Circuit and Program |
|
|
560 | |
|
BCD Conversion Procedures |
|
|
565 | |
|
|
568 | |
|
|
568 | |
|
|
580 | |
|
|
595 | |
Appendix A Resistor Color Codes |
|
613 | |
Appendix B Building Your Own Circuit Boards |
|
615 | |
Appendix C Mid-range Instruction Set |
|
621 | |
Appendix D Supplementary Programs |
|
659 | |
Index |
|
795 | |