PIC16F87X
28/40-Pin 8-Bit CMOS FLASH Microcontrollers
Devices Included in this Data Sheet:
• PIC16F873
• PIC16F874
• PIC16F876
• PIC16F877
Pin Diagram
PDIP
MCLR/V
PP
RA0/AN0
RA1/AN1
RA2/AN2/V
REF
-
RA3/AN3/V
REF
+
RA4/T0CKI
RA5/AN4/SS
RE0/RD/AN5
RE1/WR/AN6
RE2/CS/AN7
V
DD
V
SS
OSC1/CLKIN
OSC2/CLKOUT
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RD0/PSP0
RD1/PSP1
1
2
3
4
5
6
8
9
10
11
12
13
14
15
16
17
18
19
20
40
39
38
37
36
35
RB7/PGD
RB6/PGC
RB5
RB4
RB3/PGM
RB2
RB1
RB0/INT
V
DD
V
SS
RD7/PSP7
RD6/PSP6
RD5/PSP5
RD4/PSP4
RC7/RX/DT
RC6/TX/CK
RC5/SDO
RC4/SDI/SDA
RD3/PSP3
RD2/PSP2
Microcontroller Core Features:
• High performance RISC CPU
• Only 35 single word instructions to learn
• All single cycle instructions except for program
branches which are two cycle
• Operating speed: DC - 20 MHz clock input
DC - 200 ns instruction cycle
• Up to 8K x 14 words of FLASH Program Memory,
Up to 368 x 8 bytes of Data Memory (RAM)
Up to 256 x 8 bytes of EEPROM Data Memory
• Pinout compatible to the PIC16C73B/74B/76/77
• Interrupt capability (up to 14 sources)
• Eight level deep hardware stack
• Direct, indirect and relative addressing modes
• Power-on Reset (POR)
• Power-up Timer (PWRT) and
Oscillator Start-up Timer (OST)
• Watchdog Timer (WDT) with its own on-chip RC
oscillator for reliable operation
• Programmable code protection
• Power saving SLEEP mode
• Selectable oscillator options
• Low power, high speed CMOS FLASH/EEPROM
technology
• Fully static design
• In-Circuit Serial Programming(ICSP)via two
pins
• Single 5V In-Circuit Serial Programming capability
• In-Circuit Debugging via two pins
• Processor read/write access to program memory
• Wide operating voltage range: 2.0V to 5.5V
• High Sink/Source Current: 25 mA
• Commercial, Industrial and Extended temperature
ranges
• Low-power consumption:
- < 0.6 mA typical @ 3V, 4 MHz
- 20
A
typical @ 3V, 32 kHz
- < 1
A
typical standby current
PIC16F877/874
7
34
33
32
31
30
29
28
27
26
25
24
23
22
21
Peripheral Features:
• Timer0: 8-bit timer/counter with 8-bit prescaler
• Timer1: 16-bit timer/counter with prescaler,
can be incremented during SLEEP via external
crystal/clock
• Timer2: 8-bit timer/counter with 8-bit period
register, prescaler and postscaler
• Two Capture, Compare, PWM modules
- Capture is 16-bit, max. resolution is 12.5 ns
- Compare is 16-bit, max. resolution is 200 ns
- PWM max. resolution is 10-bit
• 10-bit multi-channel Analog-to-Digital converter
• Synchronous Serial Port (SSP) with SPI (Master
mode) and I
2
C
(Master/Slave)
• Universal Synchronous Asynchronous Receiver
Transmitter (USART/SCI) with 9-bit address
detection
• Parallel Slave Port (PSP) 8-bits wide, with
external RD, WR and CS controls (40/44-pin only)
• Brown-out detection circuitry for
Brown-out Reset (BOR)
1998-2013 Microchip Technology Inc.
DS30292D-page 1
PIC16F87X
Pin Diagrams
PDIP, SOIC
MCLR/V
PP
RA0/AN0
RA1/AN1
RA2/AN2/V
REF
-
RA3/AN3/V
REF
+
RA4/T0CKI
RA5/AN4/SS
V
SS
OSC1/CLKIN
OSC2/CLKOUT
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
28
27
26
25
24
23
22
21
20
19
18
17
16
15
RB7/PGD
RB6/PGC
RB5
RB4
RB3/PGM
RB2
RB1
RB0/INT
V
DD
V
SS
RC7/RX/DT
RC6/TX/CK
RC5/SDO
RC4/SDI/SDA
RA3/AN3/V
REF
+
RA2/AN2/V
REF
-
RA1/AN1
RA0/AN0
MCLR/V
PP
NC
RB7/PGD
RB6/PGC
RB5
RB4
NC
6
5
4
3
2
1
44
43
42
41
40
39
38
37
36
35
34
33
32
31
30
9
PIC16F876/873
PLCC
RC6/TX/CK
RC5/SDO
RC4/SDI/SDA
RD3/PSP3
RD2/PSP2
RD1/PSP1
RD0/PSP0
RC3/SCK/SCL
RC2/CCP1
RC1/T1OSI/CCP2
NC
QFP
44
43
42
41
40
39
38
37
36
35
34
NC
NC
RB4
RB5
RB6/PGC
RB7/PGD
MCLR/V
PP
RA0/AN0
RA1/AN1
RA2/AN2/V
REF
-
RA3/AN3/V
REF
+
12
13
14
15
16
17
18
19
20
21
22
RC7/RX/DT
RD4/PSP4
RD5/PSP5
RD6/PSP6
RD7/PSP7
V
SS
V
DD
RB0/INT
RB1
RB2
RB3/PGM
1
2
3
4
5
6
7
8
9
10
11
PIC16F877
PIC16F874
33
32
31
30
29
28
27
26
25
24
23
NC
RC0/T1OSO/T1CKI
OSC2/CLKOUT
OSC1/CLKIN
V
SS
V
DD
RE2/AN7/CS
RE1/AN6/WR
RE0/AN5/RD
RA5/AN4/SS
RA4/T0CKI
DS30292D-page 2
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
NC
18
19
20
21
22
23
24
25
26
27
282
RA4/T0CKI
RA5/AN4/SS
RE0/RD/AN5
RE1/WR/AN6
RE2/CS/AN7
V
DD
V
SS
OSC1/CLKIN
OSC2/CLKOUT
RC0/T1OSO/T1CK1
NC
7
8
9
10
11
12
13
14
15
16
17
PIC16F877
PIC16F874
RB3/PGM
RB2
RB1
RB0/INT
V
DD
V
SS
RD7/PSP7
RD6/PSP6
RD5/PSP5
RD4/PSP4
RC7/RX/DT
1998-2013 Microchip Technology Inc.
PIC16F87X
Key Features
PIC MCU Mid-Range Reference
Manual (DS33023)
®
PIC16F873
DC - 20 MHz
POR, BOR
(PWRT, OST)
4K
192
128
13
Ports A,B,C
3
2
MSSP, USART
—
5 input channels
35 instructions
PIC16F874
DC - 20 MHz
POR, BOR
(PWRT, OST)
4K
192
128
14
Ports A,B,C,D,E
3
2
MSSP, USART
PSP
8 input channels
35 instructions
PIC16F876
DC - 20 MHz
POR, BOR
(PWRT, OST)
8K
368
256
13
Ports A,B,C
3
2
MSSP, USART
—
5 input channels
35 instructions
PIC16F877
DC - 20 MHz
POR, BOR
(PWRT, OST)
8K
368
256
14
Ports A,B,C,D,E
3
2
MSSP, USART
PSP
8 input channels
35 instructions
Operating Frequency
RESETS (and Delays)
FLASH Program Memory
(14-bit words)
Data Memory (bytes)
EEPROM Data Memory
Interrupts
I/O Ports
Timers
Capture/Compare/PWM Modules
Serial Communications
Parallel Communications
10-bit Analog-to-Digital Module
Instruction Set
1998-2013 Microchip Technology Inc.
DS30292D-page 3
PIC16F87X
Table of Contents
1.0 Device Overview ................................................................................................................................................... 5
2.0 Memory Organization.......................................................................................................................................... 11
3.0 I/O Ports .............................................................................................................................................................. 29
4.0 Data EEPROM and FLASH Program Memory.................................................................................................... 41
5.0 Timer0 Module .................................................................................................................................................... 47
6.0 Timer1 Module .................................................................................................................................................... 51
7.0 Timer2 Module .................................................................................................................................................... 55
8.0 Capture/Compare/PWM Modules ....................................................................................................................... 57
9.0 Master Synchronous Serial Port (MSSP) Module ............................................................................................... 65
10.0 Addressable Universal Synchronous Asynchronous Receiver Transmitter (USART) ........................................ 95
11.0 Analog-to-Digital Converter (A/D) Module......................................................................................................... 111
12.0 Special Features of the CPU............................................................................................................................. 119
13.0 Instruction Set Summary................................................................................................................................... 135
14.0 Development Support ....................................................................................................................................... 143
15.0 Electrical Characteristics................................................................................................................................... 149
16.0 DC and AC Characteristics Graphs and Tables................................................................................................ 177
17.0 Packaging Information ...................................................................................................................................... 189
Appendix A: Revision History .................................................................................................................................... 197
Appendix B: Device Differences ................................................................................................................................ 197
Appendix C: Conversion Considerations ................................................................................................................... 198
Index .......................................................................................................................................................................... 199
On-Line Support ......................................................................................................................................................... 207
Reader Response ...................................................................................................................................................... 208
PIC16F87X Product Identification System ................................................................................................................. 209
TO OUR VALUED CUSTOMERS
It is our intention to provide our valued customers with the best documentation possible to ensure successful use of your Microchip
products. To this end, we will continue to improve our publications to better suit your needs. Our publications will be refined and
enhanced as new volumes and updates are introduced.
If you have any questions or comments regarding this publication, please contact the Marketing Communications Department via
E-mail at
docerrors@mail.microchip.com
or fax the
Reader Response Form
in the back of this data sheet to (480) 792-4150.
We welcome your feedback.
Most Current Data Sheet
To obtain the most up-to-date version of this data sheet, please register at our Worldwide Web site at:
http://www.microchip.com
You can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page.
The last character of the literature number is the version number, (e.g., DS30000A is version A of document DS30000).
Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for current
devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revision
of silicon and revision of document to which it applies.
To determine if an errata sheet exists for a particular device, please check with one of the following:
• Microchip’s Worldwide Web site; http://www.microchip.com
• Your local Microchip sales office (see last page)
• The Microchip Corporate Literature Center; U.S. FAX: (480) 792-7277
When contacting a sales office or the literature center, please specify which device, revision of silicon and data sheet (include liter-
ature number) you are using.
Customer Notification System
Register on our web site at
www.microchip.com/cn
to receive the most current information on all of our products.
DS30292D-page 4
1998-2013 Microchip Technology Inc.
PIC16F87X
1.0
DEVICE OVERVIEW
This document contains device specific information.
Additional information may be found in the PIC
®
MCU
Mid-Range Reference Manual (DS33023), which may
be obtained from your local Microchip Sales Represen-
tative or downloaded from the Microchip website. The
Reference Manual should be considered a complemen-
tary document to this data sheet, and is highly recom-
mended reading for a better understanding of the device
architecture and operation of the peripheral modules.
There are four devices (PIC16F873, PIC16F874,
PIC16F876 and PIC16F877) covered by this data
sheet. The PIC16F876/873 devices come in 28-pin
packages and the PIC16F877/874 devices come in
40-pin packages. The Parallel Slave Port is not
implemented on the 28-pin devices.
The following device block diagrams are sorted by pin
number; 28-pin for Figure 1-1 and 40-pin for Figure 1-2.
The 28-pin and 40-pin pinouts are listed in Table 1-1
and Table 1-2, respectively.
FIGURE 1-1:
Device
PIC16F873
PIC16F876
PIC16F873 AND PIC16F876 BLOCK DIAGRAM
Program
FLASH
4K
8K
Data Memory
192 Bytes
368 Bytes
13
Program Counter
FLASH
Program
Memory
Data
EEPROM
128 Bytes
256 Bytes
Data Bus
8
PORTA
RA0/AN0
RA1/AN1
RA2/AN2/V
REF
-
RA3/AN3/V
REF
+
RA4/T0CKI
RA5/AN4/SS
PORTB
RB0/INT
RB1
RB2
RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD
PORTC
8 Level Stack
(13-bit)
RAM
File
Registers
RAM Addr
(1)
Program
Bus
14
Instruction reg
Direct Addr
7
9
Addr MUX
8
Indirect
Addr
FSR reg
STATUS reg
8
3
Power-up
Timer
Instruction
Decode &
Control
Timing
Generation
OSC1/CLKIN
OSC2/CLKOUT
Oscillator
Start-up Timer
Power-on
Reset
Watchdog
Timer
Brown-out
Reset
In-Circuit
Debugger
Low Voltage
Programming
8
MUX
ALU
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
W reg
MCLR
V
DD
, V
SS
Timer0
Timer1
Timer2
10-bit A/D
Data EEPROM
CCP1,2
Synchronous
Serial Port
USART
Note 1:
Higher order bits are from the STATUS register.
1998-2013 Microchip Technology Inc.
DS30292D-page 5