Note the following details of the code protection feature on Microchip devices:
•Microchip products meet the specification contained in their particular Microchip Data Sheet.
•Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip's Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•Microchip is willing to work with the customer who is concerned about the integrity of their code.
•Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously impro ving the cod e protection features of our
products. Attempts to break microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is intended through suggestion only
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
No representation or warranty is given and no liability is
assumed by Microchip Technology Incorporated with respect
to the accuracy or use of such information, or infringement of
patents or other intellectual property rights arising from such
use or otherwise. Use of Microchip’s products as critical
components in life support systems is not authorized except
with express written approval by Microchip. No licenses are
conveyed, implicitly or otherwise, under any intellectual
property rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, K
EELOQ, MPLAB, PIC, PICmic ro, PI C START,
PRO MATE and PowerSmart are registered trademarks of
Microchip Technology Incorporated in the U.S.A. and other
countries.
AmpLab, FilterLab, microID, MXDEV, MXLAB, PICMASTER,
SEEVAL and The Embedded Control Solutions Company are
registered trademarks of Microchip Technology Incorporated
in the U.S.A.
Application Maestro, dsPICDEM, dsPICDEM.net, ECAN,
ECONOMONITOR, FanSense, FlexROM, fuzzyLAB,
In-Circuit Serial Programming, ICSP, ICEPIC, microPort,
Migratable Memory, MPASM, MPLIB, MPLINK, MPSIM,
PICkit, PICDEM, PICDEM.net, PowerCal, PowerInfo,
PowerMate, PowerTool, rfLAB, rfPIC, Select Mode,
SmartSensor, SmartShunt, SmartT el and Total Endurance are
trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
Serialized Quick Turn Programming (SQTP) is a service mark
of Microchip Technology Incorpora ted in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
Microchip received QS-9000 quality system
certification for its worldwide headquarters,
design and wafer fabrication facilities in
Chandler and Tempe, Arizona in July 1999
and Mountain View, California in March 2002.
The Company’s quality system processes and
procedures are QS-9000 compliant for its
PICmicro
devices, Serial EEPROMs, microperipherals,
non-volatile memory and analog products. In
addition, Microchip’s quality system for the
design and manufacture of develop m ent
systems is ISO 9001 certified.
®
8-bit MCUs, KEELOQ
®
code hopping
DS39582B-page ii 2003 Microchip Technology Inc.
PIC16F87XA
28/40/44-Pin Enhanced Flash Microcontrollers
Devices Included in this Data Sheet:
• PIC16F873A
• PIC16F874A
•PIC16F876A
•PIC16F877A
High-Performance RISC CPU:
• Only 35 single-word instructions to learn
• All single- cycle instru ctions 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 other 28-pin or 40/44-pin
PIC16CXXX and PIC16FXXX microcontrollers
Peripheral Features:
• Timer0: 8-bit timer/counter with 8-bit prescaler
• Timer1: 16-bit timer/counter with prescaler,
can be incremented during Sleep via extern al
crystal/clock
• Timer2: 8-bit timer/counter with 8-bit period
register, prescaler and postscaler
• Two Capture, Compare, PWM module s
- 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
• Synchronous Serial Port (SSP) with SPI™
(Master mode) and I
• Universal Synchronous Asynchronous Receiver
Transmitter (US AR T/SCI) with 9-bi t addre ss
detection
• Parallel Slave Port (PSP) – 8 bits wide with
external RD, WR and CS co ntro ls (40/44-pin only)
• Brown-out detection circuitry for
Brown-out Reset (BOR)
2
C™ (Master/Slave)
Analog Features:
• 10-bit, up to 8-channel Analog-to-Digital
Converter (A/D)
• Brown-out Reset (BOR)
• Analog Comparator module with:
- Two analog comparators
- Programmable on-chip voltage reference
REF) module
(V
- Programmable input mu ltiplexing fr om device
inputs and internal voltage reference
- Comparator outputs are externally accessible
Special Microcontroller Features:
• 100,000 erase/write cycl e Enhan ced Flash
program memory typical
• 1,000,000 erase/write cycle Data EEPROM
memory typical
• Data EEPROM Retention > 40 years
• Self-reprogrammable under software control
• In-Circuit Serial Programming™ (ICSP™)
via two pins
• Single-supply 5V In-Circuit Serial Programming
• Watchdog Timer (WDT) with its own on-chip RC
oscillator for reliable operation
3.0Data EEPROM and Flash Program Memory............................................................................................................................ 33
9.0Master Synchronous Serial Port (MSSP) Module..................................................................................................................... 71
14.0 Special Features of the CPU.................................................................................................................................................. 143
15.0 Instruction Set Summary.................... ............ ......................... ...................................... .......................................................... 159
18.0 DC and AC Characteristics Graphs and Tables ..................................................................................................................... 197
Index ................................................................................................................................................................................................. 221
Systems Information and Upgrade Hot Line..................................................................................................................................... 229
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 t o better suit your needs. Our publications will be refined and
enhanced as new volumes and updates are introduced.
If you have any questions or c omm ents regarding t his publication, p lease c ontact the M arket ing Co mmunications 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 literature 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.
DS39582B-page 4 2003 Microchip Technology Inc.
PIC16F87XA
1.0DEVICE OVERVIEW
This document contains device specific information
about the following devices:
• PIC16F873A
• PIC16F874A
• PIC16F876A
• PIC16F877A
PIC16F873A/876A devic es are avail able on ly in 28-pi n
packages, while PIC16F874A/877A devices are available in 40-pin and 44-pin packages. All devices in the
PIC16F87XA family share common architecture with
the following differences:
• The PIC16F873A and PIC16F874A h ave one-hal f
of the total on-chip memory of the PIC16F876A
and PIC16F877A
• The 28-pin devices ha ve three I/ O ports , while the
40/44-pin devices have five
• The 28-pin device s have four teen interrupt s, while
the 40/44-pin devices have fifteen
• The 28-pin devices have five A/D input channels,
while the 40/44-pin devices have eight
• The Parallel Slave Port is implemented only on
the 40/44-pin devices
The available features are summarized in Table 1-1.
Block diagrams of the PIC16F873A/876A and
PIC16F874A/877A devices are provided in Figure 1-1
and Figure 1-2, respectively. The pinouts for these
device families are listed in Table 1-2 and Table 1-3.
Additional information may be found in the PICmicro
Mid-Range Reference Manual (DS33023), which may
be obtained from your local Microchip Sales Representative or downloaded from the Microchip web site. The
Reference Manual should be considered a complementary document to this data sheet and is highly recommended reading for a better understanding of the device
architecture and operation of the peripheral modules.
2:This buffer is a Schmitt Trigger input when used in Serial Programming mode.
3:This buffer is a Schmitt Trigger input when configured in RC Oscillator mode and a CMOS input otherwise.
PDIP , SOIC,
SSOP Pin#
9
107
126
227
328
41
52
63
74
QFN
Pin#
6
I/O/P
Type
I
I
O
O
I
P
I/O
I
I/O
I
I/O
I
I
O
I/O
I
I
I/O
I
O
I/O
I
I
O
Buffer
Type
(3)
ST/CMOS
—Oscillator crystal or clock output.
STMaster Clear (input) or programming voltage (output).
TTL
TTL
TTL
TTL
ST
TTL
Oscillator crystal or external clock input.
Oscillator crystal input or external clock source input. ST
buffer when configured in RC mode; otherwise CMOS.
External clock source input. Always associated with pin
function OSC1 (see OSC1/CLKI, OSC2/CLKO pins).
Oscillator crystal output. Connects to crystal or resonator
in Crystal Oscillator mode.
In RC mode, OSC2 pin outputs CLKO, which has 1/4 the
frequency of OSC1 and denotes the instruction cycle rate.
Master Clear (Reset) input. This pin is an active low Reset
to the device.
Programming voltage input.
PORTA is a bidirectional I/O port.
Digital I/O.
Analog input 0.
Digital I/O.
Analog input 1.
Digital I/O.
Analog input 2.
A/D reference voltage (Low) input.
Comparator V
Digital I/O.
Analog input 3.
A/D reference voltage (High) input.
Digital I/O – Open-drain when configured as output.
Timer0 external clock input.
Comparator 1 output.
Digital I/O.
Analog input 4.
SPI slave select input.
Comparator 2 output.
2:This buffer is a Schmitt Trigger input when used in Serial Programming mode.
3:This buffer is a Schmitt Trigger input when configured in RC Oscillator mode and a CMOS input otherwise.
PDIP , SOIC,
SSOP Pin#
2118
2219I/OTTL
2320I/OTTL
2421
2522I/OTTL
2623I/OTTL
2724
2825
118
129
1310
1411
1512
1613
1714
1815
QFN
Pin#
I/O/P
Type
I/O
I
I/O
I
I/O
I
I/O
I/O
I/O
O
I
I/O
I
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I
I/O
I/O
O
I/O
O
I/O
I/O
I
I/O
Buffer
Type
TTL/ST
TTL
TTL/ST
TTL/ST
ST
ST
ST
ST
ST
ST
ST
ST
Description
PORTB is a bidirectional I/O port. PORTB can be software
programmed for internal weak pull-ups on all inputs.
(1)
Digital I/O.
External interrupt.
Digital I/O.
Digital I/O.
Digital I/O.
Low-voltage (single-supply) ICSP programming enable pin.
Digital I/O.
(2)
(2)
Digital I/O.
Digital I/O.
In-circuit debugger and ICSP programming clock.
Digital I/O.
In-circuit debugger and ICSP programming data.
PORTC is a bidirectional I/O port.
Digital I/O.
Timer1 oscillator output.
Timer1 external clock input.
2:This buffer is a Schmitt Trigger input when used in Serial Programming mode.
3:This buffer is a Schmitt Trigger input when configured in RC Oscillator mode and a CMOS input otherwise.
Pin#
13143032
14153133
121818
231919
342020
452121
562222
672323
782424
Pin#
TQFP
Pin#
QFN
Pin#
I/O/P
Type
I
I
O
O
I
P
I/O
I
I/O
I
I/O
I
I
O
I/O
I
I
I/O
I
O
I/O
I
I
O
Buffer
Type
(4)
ST/CMOS
STMaster Clear (input) or programming voltage (output).
TTL
TTL
TTL
TTL
ST
TTL
Oscillator crystal or external clock input.
Oscillator crystal input or external clock source
input. ST buffer when configured in RC mode;
otherwise CMOS.
External clock source input. Always associated
with pin function OSC1 (see OSC1/CLKI,
OSC2/CLKO pins).
—Oscillator crystal or clock output.
Oscillator crystal output.
Connects to crystal or resonator in Crystal
Oscillator mode.
In RC mode, OSC2 pin outputs CLKO, which
has 1/4 the frequency of OSC1 and denotes the
instruction cycle rate.
Master Clear (Reset) input. This pin is an active
low Reset to the device.
Programming voltage input.
PORTA is a bidirectional I/O port.
Digital I/O.
Analog input 0.
Digital I/O.
Analog input 1.
Digital I/O.
Analog input 2.
A/D reference voltage (Low) input.
Comparator V
Digital I/O.
Analog input 3.
A/D reference voltage (High) input.
Digital I/O – Open-drain when configured as
output.
Timer0 external clock input.
Comparator 1 output.
Digital I/O.
Analog input 4.
SPI slave select input.
Comparator 2 output.
Note 1:This buffer is a Schmitt Trigger input when configured as the external interrupt.
2:This buffer is a Schmitt Trigger input when used in Serial Programming mode.
3:This buffer is a Schmitt Trigger input when configured in RC Oscillator mode and a CMOS input otherwise.
Pin#
33368
363911
394316
404417
Pin#
TQFP
Pin#
QFN
Pin#
9
10I/O
11I/O
12
14I/O
15I/O
16
17
I/O/P
Type
I/O
I
I/O
I
I/O
I
I/O
I/O
Buffer
Type
PORTB is a bidirectional I/O port. PORTB can be
software programmed for internal weak pull-up on all
inputs.
Note 1:This buffer is a Schmitt Trigger input when configured as the external interrupt.
2:This buffer is a Schmitt Trigger input when used in Serial Programming mode.
3:This buffer is a Schmitt Trigger input when configured in RC Oscillator mode and a CMOS input otherwise.
Pin#
15163234
16183535
17193636
18203737
23254242
24264343
25274444
262911
Pin#
TQFP
Pin#
QFN
Pin#
I/O/P
Type
I/O
O
I
I/O
I
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I
I/O
I/O
O
I/O
O
I/O
I/O
I
I/O
Buffer
Type
ST
ST
ST
ST
ST
ST
ST
ST
Description
PORTC is a bidirectional I/O port.
Digital I/O.
Timer1 oscillator output.
Timer1 external clock input.
Digital I/O.
Timer1 oscillator input.
Capture2 i nput, Comp are2 output , PWM2 output.
Digital I/O.
Capture1 i nput, Comp are1 output , PWM1 output.
Digital I/O.
Synchronous serial clock input/output for SPI
mode.
Synchronous serial clock input/output for I
mode.
Digital I/O.
SPI data in.
2
C data I/O.
I
Digital I/O.
SPI data out.
Digital I/O.
USART asynchronous transmit.
USART1 synchronous clock.
Digital I/O.
USART asynchronous receive.
USART synchronous data.
Note 1:This buffer is a Schmitt Trigger input when configured as the external interrupt.
2:This buffer is a Schmitt Trigger input when used in Serial Programming mode.
3:This buffer is a Schmitt Trigger input when configured in RC Oscillator mode and a CMOS input otherwise.
QFN
Pin#
I/O/P
Type
Buffer
Type
Description
PORTD is a bidirectional I/O port or Parallel Slave
Port when interfacing to a microprocessor bus.
(3)
ST/TTL
I/O
I/O
ST/TTL
I/O
I/O
ST/TTL
I/O
I/O
ST/TTL
I/O
I/O
ST/TTL
I/O
I/O
ST/TTL
I/O
I/O
ST/TTL
I/O
I/O
ST/TTL
I/O
I/O
Digital I/O.
Parallel Slave Port data.
(3)
Digital I/O.
Parallel Slave Port data.
(3)
Digital I/O.
Parallel Slave Port data.
(3)
Digital I/O.
Parallel Slave Port data.
(3)
Digital I/O.
Parallel Slave Port data.
(3)
Digital I/O.
Parallel Slave Port data.
(3)
Digital I/O.
Parallel Slave Port data.
(3)
Digital I/O.
Parallel Slave Port data.
PORTE is a bidirectional I/O port.
(3)
ST/TTL
I/O
I
I
ST/TTL
I/O
I
I
ST/TTL
I/O
I
I
Digital I/O.
Read control for Parallel Slave Port.
Analog input 5.
(3)
Digital I/O.
Write control for Parallel Slave Port.
Analog input 6.
(3)
Digital I/O.
Chip select control for Parallel Slave Port.
Analog input 7.
P—Ground reference for logic and I/O pins.
31
P—Positive supply for logic and I/O pins.
28, 29
13——These pins are not internally connected. These pins
should be left unconnected.
2003 Microchip Technology Inc.DS39582B-page 13
PIC16F87XA
NOTES:
DS39582B-page 14 2003 Microchip Technology Inc.
PIC16F87XA
2.0MEMORY ORGANIZATION
There are three memory blocks in each of the
PIC16F87XA devices. The program memory and data
memory have separate buses so that concurrent
access can oc cur and is detailed in this section. The
EEPROM data memory blo ck is deta iled in Section 3.0“Data EEPROM and Flash Program Memory”.
Additional informa tion on devi ce memory may be found
in the PIC micro
Manual (DS33023).
FIGURE 2-1:PIC16F876A/877A
CALL, RETURN
RETFIE, RETLW
®
Mid-Range MCU Family Reference
PROGRAM MEMORY MAP
AND STACK
PC<12:0>
13
Stack Level 1
Stack Level 2
2.1Program Memory Organization
The PIC16F87XA devices have a 13-bit program
counter capable of addressing an 8K word x 14 bit
program memory space. The PIC16F876A/877A
devices have 8K words x 14 bits of Flash program
memory, while PIC16F873A/874A devices have
4K words x 14 bits. Accessing a location above the
physically implemented address will cause a
wraparound.
The Reset vector is at 0000h an d the interrupt vec tor is
at 0004h.
FIGURE 2-2:PIC16F873A/874A
PROGRAM MEMO RY MAP
AND STACK
PC<12:0>
CALL, RETURN
RETFIE, RETLW
Stack Level 1
Stack Level 2
13
On-Chip
Program
Memory
Stack Level 8
Reset Vector
Interrupt Vector
Page 0
Page 1
Page 2
Page 3
0000h
0004h
0005h
07FFh
0800h
0FFFh
1000h
17FFh
1800h
1FFFh
On-Chip
Program
Memory
Stack Level 8
Reset Vector
Interrupt Vector
Page 0
Page 1
0000h
0004h
0005h
07FFh
0800h
0FFFh
1000h
1FFFh
2003 Microchip Technology Inc.DS39582B-page 15
PIC16F87XA
2.2Data Memory Organization
The data memory is partitioned into multiple banks
which contain the General Purpose Registers and the
Special Function Registers. Bits RP1 (Status<6>) and
RP0 (Status<5>) are the bank select bits.
RP1:RP0Bank
000
011
102
113
Each bank extends up to 7Fh (128 bytes). The lower
locations of each bank are reserved for the Special
Function Registers. Ab ove the Speci al Function Registers are General Purpose Registers, implemented as
static RAM. All implemented banks contain Special
Function Registers. Some frequently used Special
Function Registers from one bank may be mirrored in
another bank for code reduction and quicker access.
Note:The EEPROM data memory description can
be found in Section 3.0 “Data EEPROMand Flash Program Memory” of this data
sheet.
2.2.1GENERAL PURPOSE REGISTER
FILE
The register file can be accessed either directly, or
indirectly, through the File Select Register (FSR).
Note 1: These registers are not implemented on the PIC16F873A.
2:These registers are reserved; maintain these r egisters clear.
DS39582B-page 18 2003 Microchip Technology Inc.
PIC16F87XA
2.2.2SPECIAL FUNCTION REGISTERS
The Special Function Registers are registers used by
the CPU and peripheral modules for controlling the
desired operation of the device. These registers are
implemented as static RAM. A list of these registers is
given in Table 2-1.
The Special Function Registers can be classified into
two sets: core (CPU) and peripheral. Those registers
associated with the core functions are described in
detail in this section. Those related to the operation of
the peripheral features are described in detail in the
peripheral features section.
TABLE 2-1:SPECIAL FUNCTION REGISTER SUMMARY
AddressNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
Bank 0
(3)
00h
01hTMR0Timer0 Mo dule Registerxxxx xxxx 55, 150
02h
03h
04h
05hPORTA
06hPORTBPORTB Data Latch when written: PORTB pins when readxxxx xxxx 45, 150
07hPORTCPORTC Data Latch when written: POR TC pins when readxxxx xxxx 47, 150
08h
09h
0Ah
0Bh
0ChPIR1PSPIF
0DhPIR2
0EhTMR1LHolding Register for th e Least Sign ifican t Byte of the 16-bit TMR1 Registerxxxx xxxx 60, 150
0FhTMR1HHolding Register for the Most Significant Byte of t he 16-bi t TMR1 Registerxxxx xxxx 60, 150
contents are transferred to the upper byte of the program counter.
2:Bits PSPIE and PSPIF are reserved on PIC16F873A/876A devices; always maintain these bits clear.
3:These registers can be addressed from any bank.
4:PORTD, PORTE, TRISD and TRI SE are not implemented on PIC16F873A/876A devices, read as ‘0’.
5:Bit 4 of EEADRH implemented only on the PIC16F876A/877A devices.
contents are transferred to the upper byte of the program counter.
2:Bits PSPIE and PSPIF are reserved on PIC16F873A/876A devices; always maintain these bits clear.
3:These registers can be addressed from any bank.
4:PORTD, PORTE, TRISD and TRI SE are not implemented on PIC16F873A/876A devices, read as ‘0’.
5:Bit 4 of EEADRH implemented only on the PIC16F876A/877A devices.
———WRERRWRENWRRDx--- x000 34, 151
18DhEECON2EEPROM Control Register 2 (not a physical register)---- ---- 39, 151
18Eh—Reserved; maintain cle ar0000 0000—
18Fh—Reserved; maintain clear0000 0000—
Legend:x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as ‘0’, r = reserved.
Shaded locations are unimplemented, read as ‘0’.
Note 1:The upper byte of the program counter is not directly accessible. PCLA TH is a holding register for the PC<12:8>, whose
contents are transferred to the upper byte of the program counter.
2:Bits PSPIE and PSPIF are reserved on PIC16F873A/876A devices; always maintain these bits clear.
3:These registers can be addressed from any bank.
4:PORTD, PORTE, TRISD and TRI SE are not implemented on PIC16F873A/876A devices, read as ‘0’.
5:Bit 4 of EEADRH implemented only on the PIC16F876A/877A devices.
Details
on page:
2003 Microchip Technology Inc.DS39582B-page 21
PIC16F87XA
2.2.2.1Status Register
The St atus reg ister co ntai ns the ar ithmetic st atu s of the
ALU, the Reset st atu s an d th e ba nk sel ec t bi ts for data
memory.
The Status register can be the destination for any
instruction, as with any othe r regi st er. If the Status re gister is the destinat ion for an instruction that affects the
Z, DC or C bits, then the writ e to these three bits is disabled. These bits are set or cleared according to the
device logic. Furthermore, the TO
writable, therefore, the result of an instruction with the
Status register as destination may be different than
intended.
and PD bits are not
For example, CLRF STATUS, will c lea r the up per three
bits and set the Z bit. Thi s leaves the Status register as
000u u1uu (where u = unchanged).
It is recommended, therefore, that only BCF, BSF,SWAPF and MOVWF instructions are used to alter the
Stat us regist er because the se inst ructions do not af fect
the Z, C or DC bits from the Status register. For other
instructions not affecting any status bits, see
Section 15.0 “Instruction Set Summary”.
Note:The C and DC bits operate as a borrow
and digit borrow bit, respectively, in subtraction. See the SUBLW and SUBWF
instructions for examples.
bit 7IRP: Register Bank Sele ct bit (used for indirect addressing)
1 = Bank 2, 3 (100h-1FFh)
0 = Bank 0, 1 (00h-FFh)
bit 6-5RP1:RP0: Register Bank Select bits (used for direct addressing)
11 = Bank 3 (180h-1FFh)
10 = Bank 2 (100h-17Fh)
01 = Bank 1 (80h-FFh)
00 = Bank 0 (00h-7Fh)
Each bank is 128 bytes.
bit 4TO
bit 3PD
bit 2Z: Zero bit
bit 1DC: Digit carry/borrow
bit 0C: Carry/borrow
: Time-out bit
1 = After power-up, CLRWDT instruction or SLEEP instruction
0 = A WDT time-out occurred
: Power-down bit
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instruction
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
bit (ADDWF, ADDLW,SUBLW,SUBWF instructions)
(for borrow
1 = A carry-out from the 4th low order bit of the result occurred
0 = No carry-out from the 4th low order bit of the result
1 = A carry-out from the Most Significant bit of the result occurred
0 = No carry-out from the Most Significant bit of the result occurred
Note:For borrow
, the polarity is reversed)
bit (ADDWF, ADDLW,SUBLW,SUBWF instructions)
, the polarity is reversed. A subtraction is executed by adding the two’s
complement of the second operand. For rotate (RRF, RLF) instructions, this bit is
loaded with either the high, or low order bit of the source register.
PDZDCC
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
DS39582B-page 22 2003 Microchip Technology Inc.
PIC16F87XA
2.2.2.2OPTION_RE G Regi st er
The OPTION_R EG Regis ter i s a readabl e an d writ abl e
register , which cont ains various contr ol bits to conf igure
the TMR0 prescaler/WDT postscaler (single assignable register known also as the prescaler), the external
INT interrupt, TMR0 and the weak pull-u ps o n POR TB.
Note:To achieve a 1:1 prescaler assignment for
the TMR0 register, assign the prescaler to
the Watchdog Timer.
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
Note:When using Low-V olta ge ICSP Programm ing (LVP) and the pull-ups on PORTB ar e
enabled, bit 3 in the TRISB register must be cleared to disable the pull-up on RB3
and ensure the proper operation of the device
2003 Microchip Technology Inc.DS39582B-page 23
PIC16F87XA
2.2.2.3INTCON Register
The INTCON register is a readable and writable register, which contains various enable and flag bits for the
TMR0 register overflow, RB port change and external
RB0/INT pin interrupts.
Note:Interrupt flag bits are set when an interrupt
condition occurs regardless of the state of its
corresponding enable bit or the global
enable bit, GIE (INTCON<7>). User software
should ensure the appropriate interrupt flag
bits are clear prior to enabling an interrupt.
1 = Enables all unmasked interrupts
0 = Disables all interrupts
bit 6PEIE: Peripheral Interrupt Enable bit
1 = Enables all unmasked peripheral interrupts
0 = Disables all peripheral interrupts
bit 5TMR0IE: TMR0 Overfl ow Interrupt Enable bit
1 = Enables the TMR0 interrupt
0 = Disables the TMR0 interrupt
bit 4INTE: RB0/INT External Interrupt Enable bit
1 = Enables the RB0/INT external interrupt
0 = Disables the RB0/INT external interrupt
bit 3RBIE: RB Port Change Interrupt Enable bit
1 = Enables the RB port change interrupt
0 = Disables the RB port change interrupt
bit 2TMR0IF: TMR0 Overflow Interrupt Flag bit
1 = TMR0 regis ter has overflowed (must be cleared in software)
0 = TMR0 register did not overflow
bit 1INTF: RB0/INT External Interrupt Flag bit
1 = The RB0/INT external interrupt occurred (must be cleared in software)
0 = The RB0/INT external interrupt did not occur
bit 0RBIF: RB Port Change Interrupt Flag bit
1 = At least one of the RB7:RB4 pins ch ang ed s t a te; a mismatch condi tion will continue to s et
the bit. Reading PORTB will end the mismatch condition and allow the bit to be cleared
(must be cleared in software).
0 = None of the RB7:RB4 pins have changed state
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
DS39582B-page 24 2003 Microchip Technology Inc.
PIC16F87XA
2.2.2.4PI E1 Regi st er
The PIE1 register cont ains the ind ividual enab le bits for
the periph eral interrupts.
Note:Bit PEIE (INTCON<6>) must be set to
REGISTER 2-4:PIE1 REGISTER (ADDRESS 8Ch)
R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0
(1)
PSPIE
bit 7bit 0
bit 7PSPIE: Parallel Slav e Port Read/ W r i te Interru pt Enab le bit
1 = Enables the PSP read/write interrupt
0 = Disables the PSP read/write interrupt
Note 1: PSPIE is reserved on PIC16F873A/876A devices; always maintain this bit clear.
bit 6ADIE: A/D Converter Interrupt Enable bit
1 = Enables the A/D converter interrupt
0 = Disables the A/D converter interrupt
bit 5RCIE: USART Receive Interrupt Enable bit
1 = Enables the USART receive interrupt
0 = Disables the USART receive interrupt
bit 4TXIE: USART Transmit Interrupt Enable bit
1 = Enables the USART transmit interrupt
0 = Disables the USART transmit interrupt
bit 3SSPIE: Synchronous Serial Port Interrupt Enable bit
1 = Enables the SSP interrupt
0 = Disables the SSP interrupt
bit 2CCP1IE: CCP1 Interrupt Enable bit
1 = Enables the CCP1 interrupt
0 = Disables the CCP1 interrupt
bit 1TMR2IE: TMR2 to PR2 Match Interrupt Enable bit
1 = Enables the TMR2 to PR2 match interrupt
0 = Disables the TMR2 to PR2 match interrupt
bit 0TMR1IE: TMR1 Overfl ow Interrupt Enable bit
1 = Enables the TMR1 overflow interrupt
0 = Disables the TMR1 overflow interrupt
ADIERCIETXIESSPIECCP1IETMR2IETMR1IE
enable any peripheral interrupt.
(1)
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
2003 Microchip Technology Inc.DS39582B-page 25
PIC16F87XA
2.2.2.5PIR1 Register
The PIR1 register contains the individual flag bits for
the periph eral interrupts.
Note:Interrupt flag bits are set when an interrupt
REGISTER 2-5:PIR1 REGISTER (ADDRESS 0Ch)
R/W-0R/W-0R-0R-0R/W-0R/W-0R/W-0R/W-0
(1)
PSPIF
bit 7bit 0
bit 7PSPIF: Parallel Slave Port Read/Write Interrupt Flag bit
1 = A read or a write operation has taken place (must be cleared in software)
0 = No read or write has occurred
Note 1: PSPIF is reserved on PIC16F873A/876A devices; always maintain this bit clear.
bit 6ADIF: A/D Converter Interrupt Flag bit
1 = An A/D conversion completed
0 = The A/D conversion is not complete
bit 5RCIF: USART Receive Interrupt Flag bit
1 = The USART receive buffer is full
0 = The USART receive buffer is empty
bit 4TXIF: USART Transmit Interrupt Flag bit
1 = The USART transmit buffer is empty
0 = The USART transmit buffer is full
bit 3SSPIF: Synchronous Serial Port (SSP) Interrupt Flag bit
1 = The SSP interrupt condition has occurred and must be cleared in software before retu rning
from the Interrupt Service Routine. The conditions that will set this bit are:
• SPI – A transmission/reception has taken place.
• I
•I
- A transmission/reception has taken place.
- The initiated Start condition was completed by the SSP module.
- The initiated Stop condition was completed by the SSP module.
- The initiated Restart condition was completed by the SSP module.
- The initiated Acknowledge condition was completed by the SSP module.
- A Start cond ition occ urred whil e the SSP modul e was Idl e (mult i-master s ystem).
- A Stop con dit ion o ccurre d whil e the SSP module was I dle (m ul ti-mas ter s ys tem ).
0 = No SSP interrupt condition has occurred
bit 2CCP1IF: CCP1 Interrupt Flag bit
Capture mode:
1 = A TMR1 regist er capture occurred (must be cleared in software)
0 = No TMR1 regi ster capture occurred
Compare mode:
1 = A TMR1 register compare match occurred (must be cleared in software)
0 = No TMR1 register compare match occurred
PWM mode:
Unused in this mode.
bit 1TMR2IF: TMR2 to PR2 Match Interrupt Flag bit
1 = TMR2 to PR2 match occurred (must be cleared in software)
0 = No TMR2 to PR2 match occurred
bit 0TMR1IF: TMR1 Overflow Interrupt Flag bit
1 = TMR1 register overflowed (must be cleared in software)
0 = TMR1 register did not overflow
ADIFRCIFTXIFSSPIFCCP1IFTMR2IFTMR1IF
2
C Slave – A transmission/reception has taken place.
2
C Master
condition occurs regardless of the state of its
corresponding enable bit or the global
enable bit, GIE (INTCON<7>). User software
should ensure the appropriate interrupt bits
are clear prior to enabling an interrupt.
(1)
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
DS39582B-page 26 2003 Microchip Technology Inc.
PIC16F87XA
2.2.2.6PI E2 Regi st er
The PIE2 register cont ains the ind ividual enab le bits for
the CCP2 peripheral interrupt, the SSP bus collision
interrupt, EEPROM write operation interrupt and the
comparator interrupt.
Note:Bit PEIE (INTCON<6>) must be set to
enable any peripheral interrupt.
REGISTER 2-6:PIE2 REGISTER (ADDRESS 8Dh)
U-0R/W-0U-0R/W-0R/W-0U-0U-0R/W-0
—CMIE—EEIEBCLIE——CCP2IE
bit 7bit 0
bit 7Unimplemented: Read as ‘0’
bit 6CMIE: Comparator Interrupt Enable bit
1 = Enables the comparator interrupt
0 = Disable the comparator interrupt
bit 5Unimplemented: Read as ‘0’
bit 4EEIE: EEPROM Write Operation Interrupt Enable bit
1 = Enable bus collision interrupt
0 = Disable bus collision interrupt
bit 2-1Unimplemented: Read as ‘0’
bit 0CCP2IE: CCP2 Interrupt Enable bit
1 = Enables the CCP2 interrupt
0 = Disables the CCP2 interrupt
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
2003 Microchip Technology Inc.DS39582B-page 27
PIC16F87XA
2.2.2.7PIR2 Register
The PIR2 register contains the flag bits for the CCP2
interrupt, the SSP bus collision interrupt, EEPROM
write operation interrupt and the comparator interrupt.
Note:Interrupt flag bits are set when an in terrupt
condition occurs regardle ss of the sta te of
its corresponding enable bit or the global
enable bit, GIE (INTCON<7>). User
software should ensure the appropriate
interrupt flag bits are clear prior to
enabling an interrupt.
REGISTER 2-7:PIR2 REGISTER (ADDRESS 0Dh)
U-0R/W-0U-0R/W-0R/W-0U-0U-0R/W-0
—CMIF—EEIFBCLIF——CCP2IF
bit 7bit 0
bit 7Unimplemented: Read as ‘0’
bit 6CMIF: Comparator Interrupt Flag bit
1 = The comparator input has changed (must be cleared in software)
0 = The comparator input has not changed
bit 5Unimplemented: Read as ‘0’
bit 4EEIF: EEPROM Write Operation Interrupt Flag bit
1 = The write operation completed (must be cleared in software)
0 = The write operation is not complete or has not been started
bit 3BCLIF: Bus Collision Interrupt Flag bit
1 = A bus collision has occurred in the SSP when configured for I
0 = No bus collision has occurred
bit 2-1Unimplemented: Read as ‘0’
bit 0CCP2IF: CCP2 Interrupt Flag bit
Capture mode:
1 = A TMR1 regist er capture occurred (must be cleared in software)
0 = No TMR1 regi ster capture occurred
Compare mode:
1 = A TMR1 register compare match occurred (must be cleared in software)
0 = No TMR1 register compare match occurred
PWM mode:
Unused.
2
C Master mode
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
DS39582B-page 28 2003 Microchip Technology Inc.
Loading...
+ 204 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.