You are on page 1of 8

378-5 Reese FM

6/27/05

2:26 PM

Page vii

Contents
Acknowledgments
Preface
1

Number System and Digital Logic Review


1.1 Learning Objectives
1.2 Binary Data
1.3 Unsigned Number Conversion
1.4 Binary and Hex Arithmetic
1.5 Combinational Logic Functions
1.6 Combinational Building Blocks
1.7 Sequential Logic
1.8 Sequential Building Blocks
1.9 Encoding Character Data
Summary
Review Exercises

The Stored Program Machine


2.1 Learning Objectives
2.2 Problem Solving the Digital Way
2.3 Finite State Machine Design
2.4 A Stored Program Machine
2.5 Modern Computers
Summary
Review Problems

Introduction to the PIC18Fxx2


3.1
3.2
3.3
3.4

Learning Objectives
Introduction to Microprocessors and Microcontrollers
The PIC18Fxx2 Microcontroller
Data Memory Organization and Data Transfer

xv
xvii
1
1
2
5
6
10
17
21
25
27
29
29

31
31
32
34
39
47
47
47

51
51
52
53
55

vii

378-5 Reese FM

6/27/05

viii

2:26 PM

Page viii

Contents

3.5 Basic Arithmetic and Control Instructions


3.6 A PIC18 Assembly Language Program
3.7 The Clock and Instruction Execution
Summary
Review Problems

Unsigned 8-Bit Arithmetic, Logical, Conditional Operations

77

4.1 Learning Objectives


4.2 Bitwise Logical Operations, Bit Operations
4.3 The STATUS Register
4.4 Unsigned Conditional Tests
4.5 Looping
4.6 Shifts and Rotates
Summary
Review Problems

77
78
83
85
94
97
100
100

Extended Precision and Signed Operations

103

5.1 Learning Objectives


5.2 Extended Precision Integers
5.3 Extended Precision Operations
5.4 Signed Number Representation
5.5 Twos Complement Overflow
5.6 Operations on Signed Data
5.7 Branch Instruction Encoding
Summary
Review Problems

61
64
73
73
74

Subroutines and Pointers


6.1
6.2
6.3
6.4
6.5
6.6
6.7

Learning Objectives
Subroutines
The Stack and Call/Return
Implementing Subroutines in Assembly Language
Arrays and Pointers in C
Arrays and Pointers in Assembly Language
Accessing Table Data from Program Memory

103
104
105
114
119
120
127
129
129

133
133
134
136
141
146
152
160

378-5 Reese FM

6/27/05

2:26 PM

Page ix

Contents

6.8 Subroutines and Stack Frames: Dynamic Allocation


Summary
Review Problems

Advanced Assembly Language: Higher Math


7.1 Learning Objectives
7.2 Multiplication
7.3 Division
7.4 Fixed-Point and Saturating Arithmetic
7.5 Floating-Point Number Representation
7.6 BCD Arithmetic
7.7 ASCII Data Conversion
Summary
Review Problems

The PIC18Fxx2: System Startup and Parallel Port IO


8.1 Learning Objectives
8.2 High-Level Languages versus Assembly Language
8.3 C Compilation for the PIC18F242
8.4 PIC18F242 Startup Schematic
8.5 ledflash.cThe First C Program for PIC18F242 Startup
8.6 Datasheet ReadingA Critical Skill
8.7 PIC18Fxx2 Reset Sources
8.8 Experimenting with RESET, SLEEP, and the Watchdog Timer
8.9 Parallel Port Operation
8.10 LED/Switch IO and State Machine Programming
8.11 Interfacing to an LCD Module
Summary
Review Problems

Asynchronous Serial IO
9.1
9.2
9.3
9.4

Learning Objectives
IO Channel Basics
Synchronous Serial IO
Asynchronous Serial IO

ix
162
169
170

175
175
176
183
188
192
197
199
204
204

207
207
208
210
216
220
223
225
228
231
237
242
249
249

253
253
254
257
259

378-5 Reese FM

6/27/05

2:26 PM

Page x

Contents

9.5 The PIC18Fxx2 USART


9.6 The RS232 Standard
9.7 Serial IO Examples
Summary
Review Problems

10

Interrupts and a First Look at Timers


10.1 Learning Objectives
10.2 Interrupt Basics
10.3 PIC18 Interrupt Details
10.4 Interrupt-Driven Asynchronous Serial Data Input
10.5 Using a Software FIFO with Interrupt-Driven IO
10.6 Other Interrupt Sources, Sleep Mode
10.7 State Machine Programming for Interrupt-Driven IO
10.8 The Timer Subsystem: Timer2
10.9 Switch Debouncing Using a Timer
10.10 A Rotary Encoder Interface
10.11 A Numeric Keypad Interface
10.12 On Writing and Debugging ISRs
Summary
Review Problems

11

Synchronous Serial IO
11.1 Learning Objectives
11.2 The PIC18 and Synchronous Serial IO
11.3 USART Synchronous Mode
11.4 The Serial Peripheral Interface (SPI)
11.5 SPI Examples: A Digital Potentiometer and a Serial EEPROM
11.6 The I2C Bus
11.7 The I2C on the PIC18Fxx2
11.8 The 24LC515 Serial EEPROM
11.9 Double Buffering for Interrupt-Driven Writes
Summary
Review Problems

263
270
273
277
278

281
281
282
284
287
291
296
299
304
307
309
315
319
321
322

327
327
328
329
331
334
345
348
356
364
366
367

378-5 Reese FM

6/27/05

2:26 PM

Page xi

Contents

12

Data Conversion
12.1 Learning Objectives
12.2 Data Conversion Basics
12.3 Analog-to-Digital Conversion
12.4 PIC18Fxx2 Analog-to-Digital Converter
12.5 Digital-to-Analog Conversion
12.6 Digital-to-Analog Converter Example: The MAXIM 518
Summary
Review Problems

13

Timers
13.1 Learning Objectives
13.2 The Timer0 Subsystem
13.3 The Timer1 and Timer3 Subsystems
13.4 Pulse Width Measurement Using Capture Mode
13.5 Timer1/Timer3 Compare Mode
13.6 Using Capture Mode for Infrared Decoding
13.7 Timer2 and Pulse Width Modulation
13.8 Using Capture Mode for Frequency Measurement
Summary
Review Problems

14

Capstone: Audio Sampling, Monitoring System,


and Autonomous Robot
14.1 Learning Objectives
14.2 Design of an Audio Record/Playback System
14.3 Implementation of an Audio Record/Playback System
14.4 Design of a Home Monitoring System
14.5 The DS1621 Digital Thermometer
14.6 Using the Nonvolatile Storage on the PIC18Fxx2
14.7 Implementation of a Home Monitoring System
14.8 Design and Implementation of an Autonomous Robot
Summary
Suggested Project Modifications

xi
371
371
372
373
382
391
400
406
407

411
411
412
419
422
428
433
442
447
451
452

455
456
456
459
466
469
475
483
494
504
505

378-5 Reese FM

6/27/05

xii
15

2:26 PM

Page xii

Contents

Beyond the PIC18Fxx2

507

15.1 Learning Objectives


15.2 External Memory Interfacing
15.3 Other PIC Family Members
15.4 Bus Arbitration in I2C
15.5 The Controller Area Network (CAN)
15.6 The Universal Serial Bus (USB)
15.7 A Brief Survey of Non-PIC Microcontrollers
15.8 Real-Time Operating Systems
Summary
Suggested Survey Topics

507
508
513
516
528
523
527
531
533
534

Appendix A PIC18Fxx2 Architecture, Instruction Set, Register Summary

537

Appendix B Microchip MPLAB Quickstart

549

Appendix C HI-TECH PICC-18 C Compiler Demo for the PIC18F242

553

Appendix D Notes on the C Language

557

D.1
D.2
D.3
D.4

Formatted IO (PRINTF, SCANF, SPRINTF,


For C++ Programmers
For New Programmers
For Experienced C Programmers

SSCANF)

Appendix E Suggested Laboratory Exercises


E.1
E.2
E.3
E.4
E.5
E.6
E.7
E.8

Lab Setup
Experiment 1: A Stored Program Machine (Chapters 1, 2)
Experiment 2: PIC18xx2 Introduction (Chapter 3)
Experiment 3: Unsigned 8-Bit Operations (Chapter 4)
Experiment 4: Extended Precision and Signed Operations (Chapter 5)
Experiment 5: Pointers and Subroutines (Chapter 6)
Experiment 6: Hardware Startup (Chapter 8)
Experiment 7: LED/Switch IO and Introduction to Asynchronous
Serial IO (Chapters 8, 9)
E.9 Experiment 8: Interrupts (Chapter 10)

557
559
560
560

563
563
566
567
569
572
573
575
578
580

378-5 Reese FM

6/27/05

2:26 PM

Page xiii

Contents

E.10 Experiment 9: More Interrupts, the I2C Bus, and a Serial EEPROM
(Chapter 11)
E.11 Experiment 10: Introduction to Data Conversion (Chapter 12)
E.12 Experiment 11: Timer Introduction and Waveform Generation
(Chapters 10, 13)
E.13 Experiment 12: Time Measurement and IR Waveform Decoding
(Chapter 13)
E.14 Experiment 13: Audio Record/Playback (Chapter 14)
E.15 Hardware Debugging Checklist
E.16 Instrumentation and Prototyping Hints

Appendix F The Jolt/Colt Serial Bootloaders


F.1
F.2
F.3
F.4

Programming the Jolt/Colt Firmware


Jolt Installation
Running Jolt
Colt Bootloader Installation and Execution

Appendix G Circuits 001


G.1 Voltage, Current, Resistance
G.2 Capacitors

xiii

583
585
587
593
594
595
598

601
601
605
608
610

613
613
618

Appendix H References

621

Appendix I Answers to Review Problems

625

I.1 Chapter 1
I.2 Chapter 2
I.3 Chapter 3
I.4 Chapter 4
I.5 Chapter 5
I.6 Chapter 6
I.7 Chapter 7
I.8 Chapter 8
I.9 Chapter 9
I.10 Chapter 10
I.11 Chapter 11
I.12 Chapter 12

625
627
629
630
631
633
638
639
643
644
646
647

378-5 Reese FM

6/27/05

xiv

2:26 PM

Page xiv

Contents

I.13 Chapter 13

Appendix J About the CD-ROM


J.1 General System Requirements

Index

649

655
655

657

You might also like