Tải bản đầy đủ (.pdf) (925 trang)

Tài liệu PIC Microcontrollers - Vi điều khiển PIC pptx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (21.92 MB, 925 trang )

About the Authors
Martin P. Bates (Chapters 6, 7, 8, Appendices C, J) is the author of PIC Microcontrollers, 2E.
He is currently lecturing on electronics and electrical engineering at Hastings College, UK.
His interests include microcontroller applications and embedded system design.
Lucio Di Jasio (Chapters 24, 25, 26, 27, 28, 29) is the author of Programming 16-bit
Microcontrollers in C. He joined Microchip Technology in 1995 as a Field Application
Engineer. Since 2005, he has been in charge of the Application Segment Group, a cross-
divisional team of engineers that develops and promotes Microchip’s solutions across a wide
range of application segments, including: utility metering, intelligent power conversion, motor
control and lighting applications.
Chuck Hellebuyck (Chapters 15, 16, 17) is the author of Programming PIC Microcontrollers
using PIC Basic. He is founder and president of Elproducts, Inc., a fi rm specializing in devices
and project kits based on the PIC microcontroller. He writes a monthly column on the PIC
microcontroller for “Nuts and Volts” magazine.
Dogan Ibrahim (Chapters 1, 14) is the author of PICBasic Projects. He works for the
Transport for London in UK. He was formerly a lecturer at South Bank University and Head
of Department of Computer Engineering at Near East University, Cyprus.
John Morton (Chapters 9, 10, Appendices D, E, F, G, H, I) is the author of The PIC
Microcontroller. He is a Junior Research Fellow at St. John’s College, Oxford, investigating
experimental quantum computation using electron spins. He works in the Oxford University
Materials Department and Clarendon Laboratory and in collaboration with the Quantum
Information Processing IRC. His interests include PIC Microcontrollers.
D.W. Smith (Chapters 11, 12, 13) is the author of PIC in Practice. He has 30 years experience
in the Electronics Industry. Before arriving at MMU he worked as an Electronics Design
Engineer for ICL and Marconi. His teaching interests are focused on enabling Design and
Technology students to implement microcontroller designs into their projects.
Jack Smith (Chapters 18, 19, 20, 21, 22, 23) is the author of Programming the PIC
Microcontroller with MBasic. He is currently with Clifton Laboratories in Virginia. He was
www.newnespress.com
Prelims-H8615.indd xiiiPrelims-H8615.indd xiii 7/11/07 10:41:35 AM7/11/07 10:41:35 AM


PIC Microcontrollers
Prelims-H8615.indd iPrelims-H8615.indd i 7/11/07 10:41:29 AM7/11/07 10:41:29 AM
Newnes Know It All Series
PIC Microcontrollers: Know It All
Lucio Di Jasio, Tim Wilmshurst, Dogan Ibrahim, John Morton,
Martin Bates, Jack Smith, D.W. Smith, and Chuck Hellebuyck
ISBN: 978-0-7506-8615-0
Embedded Software: Know It All
Jean Labrosse, Jack Ganssle, Tammy Noergaard, Robert Oshana, Colin Walls, Keith Curtis,
Jason Andrews, David J. Katz, Rick Gentile, Kamal Hyder, and Bob Perrin
ISBN: 978-0-7506-8583-2
Embedded Hardware: Know It All
Jack Ganssle, Tammy Noergaard, Fred Eady, Lewin A.R.W. Edwards,
David J. Katz, Rick Gentile, Ken Arnold, Kamal Hyder, and Bob Perrin
ISBN: 978-0-7506-8584-9
Wireless Networking: Know It All
Praphul Chandra, Daniel M. Dobkin, Alan Bensky, Ron Olexa,
David Lide, and Farid Dowla
ISBN: 978-0-7506-8582-5
RF & Wireless Technologies: Know It All
Bruce Fette, Roberto Aiello, Praphul Chandra, Daniel Dobkin,
Alan Bensky, Douglas Miron, David Lide, Farid Dowla, and Ron Olexa
ISBN: 978-0-7506-8581-8
For more information on these and other Newnes titles visit: www.newnespress.com
Prelims-H8615.indd iiPrelims-H8615.indd ii 7/11/07 10:41:30 AM7/11/07 10:41:30 AM
PIC Microcontrollers
Lucio Di Jasio
Tim Wilmshurst
Dogan Ibrahim
John Morton

Martin P. Bates
Jack Smith
D. W. Smith
Chuck Hellebuyck
AMSTERDAM • BOSTON • HEIDELBERG • LONDON
NEW YORK • OXFORD • PARIS • SAN DIEGO
SAN FRANCISCO • SINGAPORE • SYDNEY • TOKYO
Newnes is an imprint of Elsevier
Prelims-H8615.indd iiiPrelims-H8615.indd iii 7/11/07 10:41:31 AM7/11/07 10:41:31 AM
Newnes is an imprint of Elsevier
30 Corporate Drive, Suite 400, Burlington, MA 01803, USA
Linacre House, Jordan Hill, Oxford OX2 8DP, UK
Copyright © 2008, Elsevier Inc. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, electronic, mechanical, photocopying,
recording, or otherwise, without the prior written permission of the publisher.
Permissions may be sought directly from Elsevier’s Science & Technology Rights
Department in Oxford, UK: phone: (ϩ44) 1865 843830, fax: (ϩ44) 1865 853333,
E-mail: You may also complete your request online via
the Elsevier homepage (), by selecting “Support & Contact” then
“Copyright and Permission” and then “Obtaining Permissions.”
Recognizing the importance of preserving what has been written, Elsevier prints
its books on acid-free paper whenever possible.
Library of Congress Cataloging-in-Publication Data
PIC microcontrollers : know it all / Lucio Di Jasio … [et al.].
p. cm. – (The Newnes know it all series)
ISBN-13: 978-0-7506-8615-0
1. Programmable controllers. 2. Microcomputers. 3. Microprocessors.
I. Di Jasio, Lucio.
TJ223. P76P52 2007

629.8Ј95416–dc22
2007025364
British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library.
ISBN: 978-0-7506-8615-0
07 08 09 10 10 9 8 7 6 5 4 3 2 1
Printed in the United States of America
For information on all Newnes publications
visit our Web site at www.books.elsevier.com
Prelims-H8615.indd ivPrelims-H8615.indd iv 7/11/07 10:41:31 AM7/11/07 10:41:31 AM
Contents
About the Authors xiii
Section I. An Introduction to PIC Microcontrollers 1
Chapter 1. The PIC Microcontroller Family 3
1.1 12-bit Instruction Word 6
1.2 14-bit Instruction Word 7
1.3 16-bit Instruction Word 11
1.4 Inside a PIC Microcontroller 12
Chapter 2. Introducing the PIC
®
16 Series and the 16F84A 39
2.1 The Main Idea—the PIC 16 Series Family 39
2.2 An Architecture Overview of the 16F84A 42
2.3 A Review of Memory Technologies 44
2.4 The 16F84A Memory 46
2.5 Some Issues of Timing 51
2.6 Power-Up and Reset 54
2.7 What Others Do—the Atmel AT89C2051 55
2.8 Taking Things Further—the 16F84A On-Chip Reset Circuit 56
2.9 Summary 59

References 59
Chapter 3. Parallel Ports, Power Supply and the Clock Oscillator 61
3.1 The Main Idea—Parallel Input/Output 62
3.2 The Technical Challenge of Parallel Input/Output 62
3.3 Connecting to the Parallel Port 68
3.4 The PIC 16F84A Parallel Ports 71
3.5 The Clock Oscillator 74
3.6 Power Supply 78
3.7 The Hardware Design of the Electronic Ping-Pong 80
3.8 Summary 82
References 82
Prelims-H8615.indd vPrelims-H8615.indd v 7/11/07 10:41:32 AM7/11/07 10:41:32 AM
Section II. Programming PIC Microcontrollers Using Assembly Language 83
Chapter 4. Starting to Program—An Introduction to Assembler 85
4.1 The Main Idea—What Programs Do and How We Develop Them 86
4.2 The PIC 16 Series Instruction Set, with a Little More on the ALU 89
4.3 Assemblers and Assembler Format 92
4.4 Creating Simple Programs 94
4.5 Adopting a Development Environment 97
4.6 An Introductory MPLAB Tutorial 99
4.7 An Introduction to Simulation 103
4.8 Downloading the Program to a Microcontroller 106
4.9 What Others Do—A Brief Comparison of CISC and RISC Instruction Sets 108
4.10 Taking Things Further—The 16 Series Instruction Set Format 109
4.11 Summary 110
References 110
Chapter 5. Building Assembler Programs 111
5.1 The Main Idea—Building Structured Programs 111
5.2 Flow Control—Branching and Subroutines 114
5.3 Generating Time Delays and Intervals 118

5.4 Dealing with Data 120
5.5 Introducing Logical Instructions 125
5.6 Introducing Arithmetic Instructions and the Carry Flag 125
5.7 Taming Assembler Complexity 130
5.8 More Use of the MPLAB Simulator 132
5.9 The Ping-Pong Program 136
5.10 Simulating the Ping-Pong Program—Tutorial 140
5.11 What Others Do—Graphical Simulators 143
5.12 Summary 143
References 144
Chapter 6. Further Programming Techniques 145
6.1 Program Timing 145
6.2 Hardware Counter/Timer 147
6.3 Interrupts 152
6.4 More Register Operations 158
6.5 Special Features 163
6.6 Program Data Table 167
6.7 Assembler Directives 170
6.8 Special Instructions 173
6.9 Numerical Types 174
6.10 Summary 175
vi Contents
www.newnespress.com
Prelims-H8615.indd viPrelims-H8615.indd vi 7/11/07 10:41:32 AM7/11/07 10:41:32 AM
www.newnespress.com
Chapter 7. Prototype Hardware 177
7.1 Hardware Design 177
7.2 Hardware Construction 178
7.3 Demo Board 183
7.4 Demo Board Applications 186

7.5 Summary 198
Chapter 8. More PIC Applications and Devices 199
8.1 16F877 Application 199
8.2 16F818 Application 219
8.3 12F675 Application 220
8.4 18F452 Application 221
8.5 Summary 226
Chapter 9. The PIC12F50x Series (8-pin PIC Microcontrollers) 227
9.1 Differences from the PIC16F54 227
9.2 Example Project: PIC Dice 231
Chapter 10. Intermediate Operations Using the PIC12F675 237
10.1 The Inner Differences 238
10.2 Interrupts 242
10.3 EEPROM 252
10.4 Analog to Digital Conversion 259
10.5 Comparator Module 264
10.6 Final Project: Intelligent Garden Lights 270
Chapter 11. Using Inputs 275
11.1 Switch Flowchart 277
11.2 Program Development 278
11.3 Scanning (Using Multiple Inputs) 283
11.4 Switch Scanning 283
11.5 Control Application—A Hot Air Blower 287
Chapter 12. Keypad Scanning 291
12.1 Programming Example for the Keypad 291
Chapter 13. Program Examples 307
13.1 Counting Events 307
13.2 Look-Up Table 311
13.3 7-Segment Display 311
13.4 Numbers Larger than 255 321

13.5 Long Time Intervals 327
13.6 One Hour Delay 330
Contents vii
Prelims-H8615.indd viiPrelims-H8615.indd vii 7/11/07 10:41:33 AM7/11/07 10:41:33 AM
www.newnespress.com
Section III. Programming PIC Microcontrollers Using PicBasic 333
Chapter 14. PicBasic and PicBasic Pro Programming 335
14.1 PicBasic Language 335
14.2 PicBasic Pro Language 357
14.3 Liquid Crystal Display (LCD) Interface and Commands 369
14.4 Interrupts 380
14.5 Recommended PicBasic Pro Program Structure 381
14.6 Using Stepping Motors 381
14.7 Using Servomotors 384
Chapter 15. Simple PIC Projects 387
15.1 Project #1—Flashing an LED 387
15.2 Project #2—Scrolling LEDs 391
15.3 Project #3—Driving a 7-Segment LED Display 397
Chapter 16. Moving On with the 16F876 405
16.1 Project #4—Accessing Port A I/O 405
16.2 Project #5—Analog-to-Digital Conversion 412
16.3 Project #6—Driving a Servomotor 421
Chapter 17. Communication 429
17.1 Project #7—Driving an LCD Module 429
17.2 Project #8—Serial Communication 439
17.3 Project #9—Driving an LCD with a Single Serial Connection 447
Section IV. Programming PIC Microcontrollers Using MBasic 463
Chapter 18. MBasic Compiler and Development Boards 465
18.1 The Compiler Package 465
18.2 BASIC and Its Essentials 467

18.3 Development Boards 470
18.4 Programming Style 473
18.5 Building the Circuits and Standard Assumptions 475
18.6 Pins, Ports and Input/Output 476
18.7 Pseudo-Code and Planning the Program 485
18.8 Inside the Compiler 487
References 491
Chapter 19. The Basics—Output 493
19.1 Pin Architectures 494
19.2 LED Indicators 498
19.3 Switching Inductive Loads 503
viii Contents
Prelims-H8615.indd viiiPrelims-H8615.indd viii 7/11/07 10:41:33 AM7/11/07 10:41:33 AM
www.newnespress.com
19.4 Low Side Switching 506
19.5 Isolated Switching 524
19.6 Fast Switching—Sound from a PIC 533
References 536
Chapter 20. The Basics—Digital Input 539
20.1 Introduction 539
20.2 Switch Bounce and Sealing Current 548
20.3 Hardware Debouncing 549
20.4 Software Debouncing 551
20.5 Isolated Switching 555
20.6 Reading a Keypad 557
Reference 562
Chapter 21. Introductory Stepper Motors 563
21.1 Stepper Motor Basics 563
21.2 Programs 586
References 613

Chapter 22. Digital Temperature Sensors and Real-Time Clocks 615
22.1 DS18B20 Temperature Sensor 615
22.2 Reading Multiple Sensors on the Same Bus 628
22.3 DS1302 Real-Time Clock 633
22.4 Combination Date, Time and Temperature 647
22.5 Ideas for Modifi cations to Programs and Circuits 653
References 656
Chapter 23. Infrared Remote Controls 657
23.1 Common Encoding Standards 659
23.2 IR Receiver 661
23.3 Characterizing Wide/Narrow Pulse Intervals 664
23.4 Decoding a REC-80 Controller 680
23.5 Ideas for Modifi cations to Programs and Circuits 693
References 694
Section V. Programming PIC Microcontrollers Using C 695
Chapter 24. Getting Started 697
24.1 The Plan 697
24.2 Checklist 697
24.3 Coding 698
24.4 Review 707
Contents ix
Prelims-H8615.indd ixPrelims-H8615.indd ix 7/11/07 10:41:34 AM7/11/07 10:41:34 AM
www.newnespress.com
Books 710
Links 710
Chapter 25. Programming Loops 711
25.1 The Plan 711
25.2 Checklist 711
25.3 Coding 712
25.4 Using the Logic Analyzer 719

25.5 Review 720
Books 723
Links 723
Chapter 26. More Pattern Work, More Loops 725
26.1 The Plan 725
26.2 Checklist 725
26.3 Coding 725
26.4 Testing with the Logic Analyzer 732
26.5 Using the Explorer16 Demonstration Board 734
26.6 Review 734
Books 736
Links 736
Chapter 27. NUMB3RS 737
27.1 The Plan 737
27.2 Checklist 737
27.3 Coding 737
27.4 Notes for C Experts 742
27.5 Measuring Performance 743
27.6 Review 746
Links 749
Chapter 28. Interrupts 751
28.1 The Plan 751
28.2 Checklist 751
28.3 Coding 751
28.4 Managing Multiple Interrupts 764
28.5 Review 765
Books 768
Links 768
Chapter 29. Taking a Look Under the Hood 769
29.1 The Plan 769

29.2 Checklist 769
x Contents
Prelims-H8615.indd xPrelims-H8615.indd x 7/11/07 10:41:34 AM7/11/07 10:41:34 AM
www.newnespress.com
29.3 Coding 769
29.4 Review 783
Books 785
Links 785
Section IV. Appendices 787
Appendix A. The PIC
®
16 Series Instruction Set. 789
Appendix B. The Electronic Ping-Pong. 791
Appendix C. DIZI-2 Board and Lock Application. 797
Appendix D. Program M. 821
Appendix E. Program N 827
Appendix F. Program O 831
Appendix G. Program P 835
Appendix H. Program Q 839
Appendix I. Useful PIC Data 845
Appendix J. PIC 16F84A Data Sheet 859
Index 903
Contents xi
Prelims-H8615.indd xiPrelims-H8615.indd xi 7/11/07 10:41:35 AM7/11/07 10:41:35 AM
This page intentionally left blank
Founder and a Consultant at TeleworX, Virginia, previously. He is currently working on
several PIC Microcontroller amateur radio-related projects.
Tim Wilmshurst (Chapters 2, 3, 4, 5, Appendices A, B) is the author of Designing Embedded
Systems with PIC Microcontrollers. He has been designing embedded systems since the
early days of microcontrollers. For many years this was for Cambridge University, where he

led a development team building original systems for research applications—for example in
measurement of bullet speed, wind tunnel control, simulated earthquakes, or seeking a cure to
snoring. Now he is Head of Electronic Systems at the University of Derby, where he aims to
share his love of engineering design with his students.
xiv About the Authors
www.newnespress.com
Prelims-H8615.indd xivPrelims-H8615.indd xiv 7/11/07 10:41:36 AM7/11/07 10:41:36 AM
An Introduction
to PIC
Microcontrollers
SECTION I
Ch01-H8615.indd 1Ch01-H8615.indd 1 6/29/07 4:58:05 PM6/29/07 4:58:05 PM
This page intentionally left blank
The PIC Microcontroller Family
The PIC microcontroller family is manufactured by Microchip Technology Inc. Currently
they are one of the most popular microcontrollers, used in many commercial and industrial
applications. Over 120 million devices are sold each year.
The PIC microcontroller architecture is based on a modifi ed Harvard RISC (Reduced Instruction
Set Computer) instruction set with dual-bus architecture, providing fast and fl exible design
with an easy migration path from only 6 pins to 80 pins, and from 384 bytes to 128 kbytes of
program memory.
PIC microcontrollers are available with many different specifi cations depending on:

Memory Type
– Flash
– OTP (One-time-programmable)
– ROM (Read-only-memory)
– ROMless

Input–Output (I/O) Pin Count

– 4–18 pins
– 20–28 pins
– 32–44 pins
– 45 and above pins

Memory Size
– 0.5–1 K
– 2–4 K
– 8–16 K
– 24–32 K
– 48–64 K
– 96–128 K

Special Features
– CAN
– USB
www.newnespress.com
CHAPTER 1
Ch01-H8615.indd 3Ch01-H8615.indd 3 6/29/07 4:58:06 PM6/29/07 4:58:06 PM
– LCD
– Motor Control
– Radio Frequency
Although there are many models of PIC microcontrollers, the nice thing is that they are
upward compatible with each other and a program developed for one model can very easily, in
many cases with no modifi cations, be run on other models of the family. The basic assembler
instruction set of PIC microcontrollers consists of only 33 instructions and most of the family
members (except the newly developed devices) use the same instruction set. This is why a
program developed for one model can run on another model with similar architecture without
any changes.
All PIC microcontrollers offer the following features:


RISC instruction set with only a handful of instructions to learn

Digital I/O ports

On-chip timer with 8-bit prescaler

Power-on reset

Watchdog timer

Power-saving SLEEP mode

High source and sink current

Direct, indirect, and relative addressing modes

External clock interface

RAM data memory

EPROM or Flash program memory
Some devices offer the following additional features:

Analog input channels

Analog comparators

Additional timer circuits


EEPROM data memory

External and internal interrupts

Internal oscillator
4 Chapter 1
www.newnespress.com
Ch01-H8615.indd 4Ch01-H8615.indd 4 6/29/07 4:58:06 PM6/29/07 4:58:06 PM

Pulse-width modulated (PWM) output

USART serial interface
Some even more complex devices in the family offer the following additional features:

CAN bus interface

I
2
C bus interface

SPI bus interface

Direct LCD interface

USB interface

Motor control
Although there are several hundred models of PIC microcontrollers, choosing a microcontroller
for an application is not a diffi cult task and requires taking into account these factors:


Number of I/O pins required

Required peripherals (e.g., USART, USB)

The minimum size of program memory

The minimum size of RAM

Whether or not EEPROM nonvolatile data memory is required

Speed

Physical size

Cost
The important point to remember is that there could be many models that satisfy all of
these requirements. You should always try to fi nd the model that satisfi es your minimum
requirements and the one that does not offer more than you may need. For example, if you
require a microcontroller with only 8 I/O pins and if there are two identical microcontrollers,
one with 8 and the other one with 16 I/O pins, you should select the one with 8 I/O pins.
Although there are several hundred models of PIC microcontrollers, the family can be broken
down into three main groups, which are:

12-bit instruction word (e.g., 12C5XX, 16C5X) (also referred to in this book as the 12
Series and the 16C5X Series)
The PIC Microcontroller Family 5
www.newnespress.com
Ch01-H8615.indd 5Ch01-H8615.indd 5 6/29/07 4:58:06 PM6/29/07 4:58:06 PM

14-bit instruction word (e.g., 16F8X, 16F87X) (also referred to in this book as the

16 Series)

16-bit instruction word (e.g., 17C7XX, 18C2XX) (also referred to in this book as the
17 Series and the 18 Series).
All three groups share the same RISC architecture and the same instruction set, with a few
additional instructions available for the 14-bit models, and many more instructions available
for the 16-bit models. Instructions occupy only one word in memory, thus increasing the code
effi ciency and reducing the required program memory. Instructions and data are transferred on
separate buses, so the overall system performance is increased.
The features of some microcontrollers in each group are given in the following sections.
1.1 12-bit Instruction Word
Table 1.1 lists some of the devices in this group. These devices have a very simple architecture;
however, as the prices of 14-bit devices have declined, it is rarely necessary to use a 12-bit
device these days, except for the smaller physical size.
Table 1.1: Some 12-bit PIC Microcontrollers
Microcontroller Program Data Max Speed I/O A/D
Memory RAM (MHz) Ports Converter
12C508 512 ϫ 12 25 4 6 –
16C54 384 ϫ 12 25 20 12 –
16C57 2048 ϫ 12 72 20 20 –
16C505 1024 ϫ 12 41 4 12 –
16C58A 2048 ϫ 12 73 20 12 –
PIC12C508: This is a low-cost, 8-pin device with 512 ϫ 12 EPROM program memory, and
25 bytes of RAM data memory. The device can operate at up to 4-MHz clock input and the
instruction set consists of only 33 instructions. The device features six I/O ports, 8-bit timer,
power-on reset, watchdog timer, and internal 4-MHz oscillator capability. One of the major
disadvantages of this microcontroller is that the program memory is EPROM-based and it
cannot be erased or programmed using the standard programming devices. The program
memory has to be erased using an EPROM eraser device (an ultraviolet light source).
The “F” version of this family (e.g., PIC12F508) is based on fl ash program memory, which

can be erased and reprogrammed using the standard PIC programmer devices. Similarly,
the “CE” version of the family (e.g., PIC12CE518) offers an additional 16-byte nonvolatile
EEPROM data memory.
Figure 1.1 shows the pin confi guration of the PIC12F508 microcontroller.
6 Chapter 1
www.newnespress.com
Ch01-H8615.indd 6Ch01-H8615.indd 6 6/29/07 4:58:07 PM6/29/07 4:58:07 PM
PIC16C5X: This is one of the earliest PIC microcontrollers. The device is 18-pin with a
384 ϫ 12 EPROM program memory, 25 bytes of RAM data memory, 12 I/O ports, a timer,
and a watchdog. Some other members in the family, such as PIC16C56, have the same
architecture but more program memory (1024 ϫ 12). PIC16C58A has more program memory
(2048 ϫ 12) and also more data memory (73 bytes of RAM). Figure 1.2 shows the pin
confi guration of the PIC16C56 microcontroller.
PIC 12F508/509
1
2
3
4
8VDD VSS
7
6
5
GP5/OSC1/CLKIN GP0/ICSPDAT
GP4/OSC2 GP1/ICSPCLK
GP3/MCLR/VPP GP2/T0CKI
Figure 1.1: PIC12F508 Microcontroller
PIC16C54
PIC16CR54
PIC16C56
PIC16CR56

PIC16C58
PIC16CR58
2
3
4
20RA2
RA3
T0CKI
MCLR/VPP
V
SS
VSS
RB0
RB1
RB2
RB3
RA1
RA0
OSC1/CLKIN
OSC2/CLKOUT
V
DD
VDD
RB7
RB6
RB5
RB4
19
18
17

5
6
7
8
16
15
14
13
9
10
12
11
1
Figure 1.2: PIC16C56 Microcontroller
1.2 14-bit Instruction Word
This is a big family that includes many models of PIC microcontrollers. Most of the devices
in this family can operate at up to a 20-MHz clock rate. The instruction set consists of 35
instructions. These devices offer advanced features such as internal and external interrupt
sources. Table 1.2 lists some of the microcontrollers in this group.
PIC16C554: This microcontroller has similar architecture to the PIC16C54 but the instructions
are 14 bits wide. The program memory is 512 ϫ 14 and the data memory is 80 bytes of RAM.
There are 13 I/O pins and each pin can source or sink 25 mA of current. Additionally, the
device contains a timer and a watchdog.
The PIC Microcontroller Family 7
www.newnespress.com
Ch01-H8615.indd 7Ch01-H8615.indd 7 6/29/07 4:58:07 PM6/29/07 4:58:07 PM
PIC16F84: This has been one of the most popular PIC microcontrollers for a very long time.
This is an 18-pin device and it offers 1024 ϫ 14 fl ash program memory, 36 bytes of data
RAM, 64 bytes of nonvolatile EEPROM data memory, 13 I/O pins, a timer, a watchdog, and
internal and external interrupt sources. The timer is 8 bits wide but can be programmed to

generate internal interrupts for timing purposes. PIC16F84 can be operated from a crystal or
a resonator for accurate timing. A resistor-capacitor can also be used as a timing device for
applications where accurate timing is not required. Figure 1.3 shows the pin confi guration of
this microcontroller. The pin descriptions are given in Table 1.3.
PIC16F877: This microcontroller is a 40-pin device and is one of the popular microcontrollers
used in complex applications. The device offers 8192 ϫ 14 fl ash program memory,
2
3
4
18RA2
RA3
RA4/T0CKI
MCLR
V
SS
RB0/INT
RB1
RB2
RB3
RA1
RA0
OSC1/CLKIN
OSC2/CLKOUT
V
DD
RB7
RB6
RB5
PIC16F84A
17

16
15
5
6
7
8
14
13
12
11
910
RB4
1
Figure 1.3: PIC16F84 Microcontroller Pin Confi guration
Microcontroller Program Data Max Speed I/O A/D
Memory RAM (MHz) Ports Converter
16C554 512 ϫ 14 80 20 13 –
16C64 2048 ϫ 14 128 20 33 –
16F84 1024 ϫ 14 36 10 13 –
16F627 1024 ϫ 14 224 20 16 –
16F628 2048 ϫ 14 224 20 16 –
16F676 1024 ϫ 14 64 20 12 8
16F73 4096 ϫ 14 192 20 22 5
16F876 8192 ϫ 14 368 20 22 5
16F877 8192 ϫ 14 368 20 33 8
Table 1.2: Some 14-bit Microcontrollers
8 Chapter 1
www.newnespress.com
Ch01-H8615.indd 8Ch01-H8615.indd 8 6/29/07 4:58:08 PM6/29/07 4:58:08 PM
368 bytes of RAM, 256 bytes of nonvolatile EEPROM memory, 33 I/O pins, 8 multiplexed

A/D converters with 10 bits of resolution, PWM generator, three timers, an analog capture and
comparator circuit, USART, and internal and external interrupt facilities. Figure 1.4 shows the
pin confi guration of this microcontroller.
Table 1.3: PIC16F84 Microcontroller Pin Descriptions
Pin Description Pin Description
1 RA2—PORTA bit 2 10 RB4—PORTB bit 4
2 RA3—PORTA bit 3 11 RB5—PORTB bit 5
3 RA4/T0CK1—PORTA bit 4/Counter clk 12 RB6—PORTB bit 6
4 MCLR—Master clear 13 RB7—PORTB bit 7
5 Vss—Gnd 14 Vdd—ϩV supply
6 RB0/INT—PORTB bit 0 15 OSC2
7 RB1—PORTB bit 1 16 OSC1
8 RB2—PORTB bit 2 17 RA0—PORTA bit 0
9 RB3—PORTB bit 3 18 RA1—PORTA bit 1
The PIC Microcontroller Family 9
www.newnespress.com
Figure 1.4: PIC16F877 Microcontroller Pin Confi guration
1
2
3
4
40
MCLR/VPP
RA0/AN0
RA1/AN1
RA2/AN2/VREFϪ/CVREF
RA3/AN3/VREFϩ
RA4/T0CKI/C1OUT
RA5/AN4/SS/C2OUT
RE0/RD/AN5

RE1/WR/AN6
RE2/CS/AN7
VDD
VSS
OSC1/CLKI
OSC2/CLKO
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC3/SCK/SCL
RD0/PSP0
RD1/PSP1
RC2/CCP1
RB7/PGD
RB6/PGC
RB5
RB4
RB3/PGM
RB2
RB1
RB0/INT
V
DD
VSS
RD7/PSP7
RD6/PSP6
RD5/PSP5
RD4/PSP4
RC7/RX/DT
RC6/TX/CK
RC5/SDO

RC4/SDI/SDA
RD3/PSP3
RD2/PSP2
39
38
37
5
6
7
8
36
35
34
33
932
10
11
12
13
31
PIC16F874A/877A
30
29
28
14
15
16
17
27
26

25
24
18 23
19 22
20 21
Ch01-H8615.indd 9Ch01-H8615.indd 9 6/29/07 4:58:08 PM6/29/07 4:58:08 PM
10 Chapter 1
www.newnespress.com
PIC16F627: This is an 18-pin microcontroller with 1024 ϫ 14 fl ash program memory. The
device offers 224 bytes of RAM, 128 bytes of nonvolatile EEPROM memory, 16 I/O pins, two
8-bit timers, one 16-bit timer, a watchdog, and comparator circuits. This microcontroller is
similar to PIC16F84, but offers more I/O pins, more program memory, and a lot more RAM.
In addition, PIC16F627 is more suited to applications that require more than one timer.
Figure 1.5 shows the pin confi guration of this microcontroller.
1
2
3
4
18
RA2/AN2/V
REF
RA3/AN3/CMP1
RA4/TOCKI/CMP2
RA5/MCLR/V
PP
VSS
RB0/INT
RB1/RX/DT
RB2/TX/CK
RB3/CCP1

RA1/AN1
RA0/AN0
RA7/OSC1/CLKIN
RA6/OSC2/CLKOUT
V
DD
RB7/T1OSI/PGD
RB6/T1OSO/T1CKI/PGC
RB5
RB4/PGM
17
16
15
5
6
7
8
14
13
12
11
910
PIC16F627A/628A/648A
Figure 1.5: PIC16F627 Microcontroller Pin Confi guration
PIC16F676: Figure 1.6 shows a 14-pin microcontroller that is becoming very popular. The
device offers 1024 ϫ 14 fl ash program memory, 64 bytes of RAM, 12 I/O pins, 128 bytes of
EEPROM, 8 multiplexed A/D converters, each with 10-bit resolution, one 8-bit timer, one 16-
bit timer, and a watchdog. One of the advantages of this microcontroller is the built-in A/D
converter.
1

2
3
4
14
V
DD
RA5/T1CKI/OSC1/CLKIN
RA4/T1G/OSC2/AN3/CLKOUT
RA3/MCLR/V
PP
RC5
RC4
RC3/AN7
V
SS
RA0/AN0/CINϩ/ICSPDAT
RA1/AN1/CINϪ/V
REF/ICSPCLK
RA2/AN2/COUT/T0CK/INT
RC0/AN4
RC1/AN5
RC2/AN6
13
12
11
5
6
7
10
9

8
PIC16F676
Figure 1.6: PIC16F676 Microcontroller Pin Confi gurationm
PIC16F73: This is a powerful 28-pin microcontroller with 4096 14 fl ash program memory,
192 bytes of RAM, 22 I/O pins, fi ve multiplexed 8-bit A/D converters, two 8-bit timers,
one 16-bit timer, watchdog, USART, and I
2
C bus compatibility. This device combines A/D
Ch01-H8615.indd 10Ch01-H8615.indd 10 6/29/07 4:58:09 PM6/29/07 4:58:09 PM

×