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 improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digit al Millennium Copyright Act. If suc h a c t s
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 provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED,
WRITTEN OR ORAL, STATUTORY OR OTHERWISE,
RELATED TO THE INFORMATION, INCLUDING BUT NOT
LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE,
MERCHANTABILITY OR FITNESS FOR PURPOSE.
Microchip disclaims all liability arising from this information and
its use. Use of M icrochip’s prod ucts 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 Microchip intellectual property
rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, K
EELOQ, microID, MPLAB, PIC, PICmicro, PICSTART,
PRO MATE, PowerSmart, rfPIC, and SmartShunt are
registered trademarks of Microchip Technology Incorporated
in the U.S.A. and other countries.
AmpLab, FilterLab, Migratable Memory, MXDEV, MXLAB,
PICMASTER, SEEVAL, SmartSensor and The Embedded
Control Solutions Company are registered trademarks of
Microchip Technology Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, dsPICDEM,
dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR,
FanSense, FlexROM, fuzzyLAB, In-Circuit Serial
Programmin g, IC SP, ICEPI C, M PASM, MPLIB, MPLINK,
MPSIM, PICkit, PICDEM, PICDEM.net, PICLAB, PICtail,
PowerCal, PowerInfo, PowerMate, PowerTool, rfLAB,
rfPICDEM, Select Mode, Smart Serial, SmartT el and Total
Endurance are trademarks of Microchip Technology
Incorporated in the U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
Microchip received ISO/TS-16949:2002 quality system certification for
its worldwide headquarters, design and wafer fabrication facilities in
Chandler and Tempe, Arizona and Mountain View, California in
October 2003. The Company’s quality system processes and
procedures are for its PICmicro
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
®
8-bit MCUs, KEELOQ
®
code hopping
DS30487C-page ii 2005 Microchip Technology Inc.
PIC16F87/88
18/20/28-Pin Enhanced Fl ash MCUs with nanoWatt Technology
Low-Power Features:
• Power-Managed modes:
- Primary Run: RC oscillator, 76 µA, 1 MHz, 2V
- RC_RUN: 7 µA, 31.25 kHz, 2V
- SEC_RUN: 9 µA, 32 kHz, 2V
- Sleep: 0.1 µA, 2V
• Timer1 Oscillator: 1.8 µA, 32 kHz, 2V
• Watchdog Timer: 2.2 µA, 2V
• Two-Speed Oscillator Start-u p
Oscillators:
• Three Crystal modes:
- LP, XT, HS: up to 20 MHz
• Two External RC modes
• One External Clock mode:
- ECIO: up to 20 MHz
• Internal oscillator block:
- 8 user selectable frequencies: 31 kHz,
125 kHz, 250 kHz, 500 kHz, 1 M Hz, 2 MHz,
4MHz, 8MHz
Peripheral Features:
• Capture, Compare, PWM (CCP) module:
- 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, 7-channel Analog-to-Digital Converter
• Synchronous Serial Port (SSP) with SPI™
(Master/Slave) and I
3.0Data EEPROM and Flash Program Memory.............................................................................................................................. 27
10.0 Synchronous Serial Port (SSP) Module ..................................................................................................................................... 87
11.0 Addressable Universal Synchronous Asynchronous Receiv er Transmitter (AUS ART ) ............................................................. 97
15.0 Special Features of the CPU........................................................ ..................... ....................................................................... 129
16.0 Instruction Set Summary..........................................................................................................................................................149
17.0 Development Support. .............................................................................................................................................................. 157
19.0 DC and AC Characteristics Graphs and Tables....................................................................................................................... 193
Index .................................................................................................................................................................................................. 215
The Microchip Web Site....................................... ............................................................. ................................................................. 223
Customer Change Notification Service ..............................................................................................................................................223
PIC16F87/88 Product Identification System ......................................................................................................................................225
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 c omm ents regarding t his publication, p lease c ontact the M arket ing Co mmunications Department via
E-mail at docerrors@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)
When contacting a sales office, 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 to receive the most current information on all of our products.
DS30487C-page 4 2005 Microchip Technology Inc.
PIC16F87/88
1.0DEVICE OVERVIEW
This document contains device specific information for
the operation of the PIC16F87/88 devices. Additional
information may be found in the “PICmicro® Mid-Range
MCU Family Reference Manual” (DS33023) which may
be downloaded from the Microchip web site. This
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.
The PIC16F87/88 belongs to the Mid-Range family of
the PICmicro
are shown in Figure1-1 and Figure 1-2. These devices
contain features that are new to the PIC16 prod uct line:
• Low-power modes: RC_RUN allows the core and
peripherals to be clocked from the INTRC, while
SEC_RUN allows the core and peripherals to be
clocked from the low-power Timer1. Refer to
Section 4.7 “Power-Managed Modes” for
further details.
• Internal RC oscillator with eight selectable
frequencies, including 31.25 kHz, 125 kHz,
250 kHz, 500 kHz, 1 MHz, 2 MHz, 4 MHz and
8 MHz. The INTRC can be configured as a
primary or secondary clock source. Refer to
Section 4.5 “Internal Oscillator Block” for
further details.
• The Timer1 module current consumption has
been greatly reduced from 20 µA (previous PIC16
devices) to 1.8µA typical (32 kHz at 2V), which is
ideal for real-time clock applications. Refer to
Section 7.0 “Timer1 Module” for further details.
• Extended W atchdog T imer (WD T) that can hav e a
programmable period from 1 ms to 268s. The
WDT has its own 16-bit prescaler. Refer to
Section 15.12 “Watchdog Timer (WDT)” for
further details.
• Two-Speed Start-up: When the oscillator is
configured for LP, XT or HS Oscillator mode, this
feature will cl ock t he dev ice f rom the INTRC whil e
the oscillator is warming up. This, in turn, will
enable almost immediate code execution. Refer
to Section 15.12.3 “Two-Speed Cl ock Start-up Mode” for further details.
• Fail-Safe Clock Monitor: This feature will allow the
device to continue operation if the primary or
secondary clock source fails by switching over to
the INTRC.
• The A/D module has a new register for PIC16
devices named ANSEL. This register allows
easier configuration of analog or digital I/O pins.
®
devices. Block diagrams of the devices
TABLE 1-1:AVAILABLE MEMORY IN
PIC16F87/88 DEVICES
2
Program
Flash
C™
Device
PIC16F87/884K x 14368 x 8256 x 8
There are 16 I/O pins that are user configurable on a
pin-to-pin basis. Some pins are multiplexed with other
device functions. These functions include:
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.
4:PIC 16F88 devices only.
5:The CCP1 pin is determined by the CCPMX bit in Configuration Word 1 register.
SSOP
SOIC
Pin#
171923
182024
1126
2227
3328
441
151720
161821
Pin#
QFN
Pin#
I/O/P
Type
I/O
I
I/O
I
I/O
I
O
I
I/O
I
I
O
I/O
I
I
O
I
I
P
I/O
O
O
I/O
I
I
Buffer
Type
TTL
Analog
TTL
Analog
TTL
Analog
Analog
TTL
Analog
Analog
ST
Analog
ST
ST
ST
–
ST
–
–
ST
ST/CMOS
–
Description
PORTA is a bidirectional I/O port.
Bidirectional I/O pin.
Analog input channel 0.
Bidirectional I/O pin.
Analog input channel 1.
Bidirectional I/O pin.
Analog input channel 2.
Comparator V
A/D reference voltage (Low) input.
Bidirectional I/O pin.
Analog input channel 3.
A/D reference voltage (High) input.
Comparator 1 output.
Bidirectional I/O pin.
Analog input channel 4.
Clock input to the TMR0 timer/counter.
Comparator 2 output.
Input pin.
Master Clear (Reset). Input/programming voltage
input. This pin is an active-low Reset to the device.
Programming voltage input.
Bidirectional I/O pin.
Oscillator crystal output. Connects to crystal or
resonator in Crystal Oscillator mode.
In RC mode, this pin outputs CLKO signal which has
1/4 the frequency of OSC1 and denotes the
instruction cycle rate.
Note 1:T his 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.
4:PIC16F88 devices only.
5:The CCP1 pin is determined by the CCPMX bit in Configuration Word 1 register.
QFN
Pin#
I/O/P
Type
I/O
I
I/O
I/O
I
I/O
I/O
O
I
I/O
I/O
I/O
I
I/O
I/O
I
I/O
I
O
I/O
I/O
I
I/O
O
I
I/O
I
I
I
Buffer
Type
TTL
(1)
ST
ST
TTL
ST
ST
TTL
ST
TTL
ST
ST
TTL
ST
ST
TTL
TTL
TTL
(2)
ST
ST
ST
TTL
(2)
ST
ST
Description
PORTB is a bidirectional I/O port. PORTB can be
software programmed for internal weak pull-up on all
inputs.
Bidirectional I/O pin. Interrupt-on-change pin.
Analog input channel 6.
In-Circuit Debugger and ICSP programming data pin.
Timer1 oscillator input.
2
C.
2005 Microchip Technology Inc.DS30487C-page 9
PIC16F87/88
NOTES:
DS30487C-page 10 2005 Microchip Technology Inc.
PIC16F87/88
2.0MEMORY ORGANIZATION
There are two memory blocks in the PIC16F87/88
devices. Thes e are t he p rog ram m emo ry an d the d ata
memory . Each bloc k has its o wn bus, so ac cess to each
block can occur during the same oscillator cycle.
The data memory can be further broken down into the
general purpose RAM and the Special Function
Registers (SFRs). The operation of the SFRs that
control the “core” are described here. The SFRs used
to control the peripheral modules are described in the
section discussing each individual peripheral module.
The data memory area also contains the data EEPROM
memory. This memory is not directly mapped into the
data memory but is indirectly mapped. That is, an indirect address pointer specifies the address of the data
EEPROM memory to read/write. The PIC16F87/88
device’s 256 bytes of data EEPROM memory have the
address range of 00h-FFh. More details on the
EEPROM memory can be found in Section 3.0 “DataEEPROM and Flash Program Memory”.
Additional informa tion on devi ce memory may be found
in the “PICmicroManual” (DS33023).
2.1Program Memory Organization
The PIC16F87/88 devices have a 13-bit program
counter capable of addressing an 8K x 14 program
memory space. For the PIC16F87/88, the first 4K x 14
(0000h-0FFFh) is physically implemented (see
Figure 2-1). Accessing a location above the physically
implemented address will cause a wraparound. For
example, the same instruction will be accessed at
locations 020h, 420h, 820h, C20h, 1020h, 1420h,
1820h and 1C20h.
The Reset vector is at 0000h an d the interrupt ve ctor is
at 0004h.
®
Mid-Range MCU Family Reference
FIGURE 2-1:PROGRAM MEMORY MAP
AND STACK: PIC16F87/88
PC<12:0>
On-Chip
Program
Memory
CALL, RETURN
RETFIE, RETLW
Stack Level 1
Stac k Lev el 2
Stac k Lev el 8
Reset Vector
Interrupt V ec tor
Page 0
Page 1
Wraps to
0000h-03FFh
13
0000h
0004h
0005h
07FFh
0800h
0FFFh
1000h
1FFFh
2.2Data Memory Organization
The data memory is pa rtit ioned into m ultipl e ban ks th at
contain the Ge neral Purpose Reg isters 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. Abo ve the Speci al Function Re gisters are General Purpose Registers, implemented as
static RAM. All implemented banks contain SFRs.
Some “high use” SFRs from one bank may be mirrored
in another bank for code reduction and quicker access
(e.g., the STATUS register is in Banks 0-3).
Note:EEPROM data memory description can be
found in Section 3.0 “Data EEPROM andFlash Program Memory” of this data
sheet.
2005 Microchip Technology Inc.DS30487C-page 11
PIC16F87/88
2.2.1GENERAL PURPOSE REGISTER FILE
The register file can be accessed either directly, or
indirectly, through the File Select Register (FSR).
Note 1: This register is reserved, maintain this register clear.
2005 Microchip Technology Inc.DS30487C-page 13
PIC16F87/88
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 feature section.
INDFAddressing this location uses contents of FSR to address data memory (not a physical register)0000 0000 26, 1 35
TMR0Timer0 Module Registerxxxx xxxx69
(2)
PCLProgram Counter (PC) Least Significant Byte0000 0000
(2)
STATUSIRPRP1RP0TOPDZDCC0001 1xxx17
(2)
FSRIndirect Data Memory Address Poi nterxxxx xxxx135
PORTAPORTA Data Latch when written; PORTA pins when read (PIC16F87)
PORTBPORTB Data Latch when written; PORTB pins when read (PIC16F87)
—Unimplemented——
—Unimplemented——
(1,2)
(2)
—Unimplemented——
PCLATH———Write Buffer for the Upper 5 bits of the Program Counter---0 0000135
INTCONGIE PEIETMR0IEINT0IERBIETMR0IFINT0IFRBIF0000 000x19, 69,
PIR1—ADIF
PIR2OSFIFCMIF—EEIF————00-0 ----23, 34
TMR1LHolding Register for the Least Significant Byte of the 16-bit TMR1 Registerxxxx xxxx77, 83
TMR1HHolding Register for the Most Significant Byte of the 16-bit TMR1 Registerxxxx xxxx77, 83
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. PCLATH is a holding register for PC<12:8>, whose
contents are transferred to the upper byte of the program counter.
2:These registers can be addressed from any bank.
3:RA5 is an input only; the state of the TRISA5 bit has no effect and will always read ‘1’.
4:PIC 16F88 device only.
Value on:
POR, BOR
xxxx 0000
xxx0 0000
xxxx xxxx
00xx xxxx
Details
on
page
52
58
77
DS30487C-page 14 2005 Microchip Technology Inc.
PIC16F87/88
TABLE 2-1:SPECIAL FUNCTION REGISTER SUMMARY (CONTINUED)
INDFAddressing this location uses contents of FSR to address data memory (not a physical register)0000 0000
OPTION_REGRBPUINTEDGT0CST0SEPSAPS2PS1PS01111 1111
(2)
PCLProgram Counter (PC) Least Significant Byte0000 0000
(2)
STATUSIRPRP1RP0TOPDZDCC0001 1xxx
(2)
FSRIndirect Data Memory Address Poi nterxxxx xxxx
TRISATRISA7TRISA6TRISA5
TRISBPORTB Data Direction Register1111 111158, 85
PORTA Data Direction Register (TRISA<4:0>)1111 1111
RCIETXIESSPIECCP1IETMR2IETMR1IE-000 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. PCLATH is a holding register for PC<12:8>, whose
contents are transferred to the upper byte of the program counter.
2:These registers can be addressed from any bank.
3:RA5 is an input only; the state of the TRISA5 bit has no effect and will always read ‘1’.
4:PIC16F88 device only.
Value on:
POR, BOR
——
——
——
——
Details
on
page
26, 135
18, 69
135
17
135
52, 126
135
19, 69,
77
20, 80
24
—
95
88, 95
120
126, 128
120
52, 115,
120
2005 Microchip Technology Inc.DS30487C-page 15
PIC16F87/88
TABLE 2-1:SPECIAL FUNCTION REGISTER SUMMARY (CONTINUED)
EEDATAEEPROM/Flash Data Register Low Bytexxxx xxxx34
EEADREEPROM/Flash Address Register Low Bytexxxx xxxx34
EEDATH——EEPROM/Flash Data Register High Byte--xx xxxx34
EEADRH————EEPROM/Flash Address Regi st er Hi gh Byte---- xxxx
(2)
INDFAddressing this location uses contents of FSR to address data memory (not a physical register)0000 0000
OPTION_REGRBPUINTEDGT0CST0SEPSAPS2PS1PS01111 111118, 69
(2)
PCLProgram Counter (PC) Least Significant Byte0000 0000
EECON1EEPGD——FREEWRERRWRENWRRDx--x x00028, 34
EECON2EEPROM Control Register 2 (not a physical register)---- ----34
———
PORTB Data Latch when written; PORTB pins when read (PIC16F88)
WDTPS3WDTPS2WDTPS1WDTPS0 SWDTEN ---0 1000142
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. PCLATH is a holding register for PC<12:8>, whose
contents are transferred to the upper byte of the program counter.
2:These registers can be addressed from any bank.
3:RA5 is an input only; the state of the TRISA5 bit has no effect and will always read ‘1’.
4:PIC 16F88 device only.
Value on:
POR, BOR
xxxx xxxx
00xx xxxx
0000 0000—
0000 0000—
Details
on
page
26, 135
135
17
135
58
135
19, 69,
77
34
135
135
17
135
135
19, 69,
77
DS30487C-page 16 2005 Microchip Technology Inc.
PIC16F87/88
2.2.2.1STATUS Register
The STATUS register, shown in Register 2-1, contains
the arithmetic status of the ALU, the Reset status and
the bank select bits for data memory.
The STATUS register can be the destination for any
instruction, as with any other register. If the STATUS
register is the destination for an instruction that affects
the Z, DC or C bits, then the write to these three bits is
disabled. These bit s are set or cleared ac cording to the
device logic. Furthermore, the TO
writable. Therefore, the result of an instruction with the
STATUS register as destinatio n may be different than
intended.
and PD bits are not
For example, CLRF STATUS will clear the up per three
bits and set t he Z bit. T his 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 STATUS
register because these instructions do not affect the Z, C
or DC bits from the STATUS register. For other
instructions not affecting any Status bits, see
Section 16.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 Select bit (used for indirect addressing)
1 = Bank 2, 3 (100h-1FFh)
0 = Bank 0, 1 (00h-FFh)
bit 6-5RP<1:0>: 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 (ADDWF, ADDLW, SUBLW and SUBWF instructions)
bit 0C: Carry/borrow
: Tim e- 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
1 = A carry-ou t from the 4 th low-order bit of the result occurred
0 = No carry-out from the 4th low-order bit of the result
bit (ADDWF, ADDLW, SUBLW and SUBWF instructions)
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
PDZDCC
(1)
(1,2)
Note 1:For borrow, the polarity is reversed. A subtraction is executed by adding the two’s
complement of the second operand.
2:For rotate (RRF, RLF) instructions, this bit is loaded w ith eit her the hi gh or low- order
bit of the source register.
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
2005 Microchip Technology Inc.DS30487C-page 17
PIC16F87/88
2.2.2.2OPTION_REG Register
The OPTION_REG register is a readable and writable
register that contains various control bits to configure
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. Although the prescaler can be assigne d to either the WDT or
Timer0, bu t not both, a new div ide co unter
is implemented in the WDT circuit to give
multiple WDT time-out selections. This
allows TMR0 and WDT to each have their
own scaler. Refer to Section 15.12“Watchdog Timer (WDT)” for further
details.
REGISTER 2-2:OPTION_REG: OPTION CONTROL REGISTER (ADDRESS 81h, 181h)
R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1
RBPU
bit 7bit 0
bit 7RBPU
1 = PORTB pull-ups are disabled
0 = PORTB pull-ups are enabled by individual port latch values
bit 6INTEDG: Interrupt Edge Select bit
1 = Interrupt on rising edge of RB0/INT pin
0 = Interrupt on falling edge of RB0/INT pin
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
DS30487C-page 18 2005 Microchip Technology Inc.
PIC16F87/88
2.2.2.3INTCON Register
The INTCON register is a readable and writable register that contains various enable and flag bits for the
TMR0 register overflow, RB Port change and External
RB0/INT pin interrupts.
Note:Interrupt flag bits get set when an interrupt
condition occurs, regar dless of the st ate 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-3:INTCON: INTERRUPT CONTROL REGISTER (ADDRESS 0Bh, 8Bh, 10Bh, 18Bh)
R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-x
GIEPEIETMR0IEINT0IERBIETMR0IFINT0IFRBIF
bit 7bit 0
bit 7GIE: Global Interrupt Enable bit
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 Overflow Interrupt Enable bit
1 = Enables the TMR0 interrupt
0 = Disables the TMR0 interrupt
bit 4INT0IE: 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 register has overflowed (must be cleared in software)
0 = TMR0 register did not overflow
bit 1INT0IF: 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
A mismatch conditi on will c ontinue t o set fla g bit RBI F. Reading PORTB will end the mismatc h
condition and allow flag bit RBIF to be cleared.
1 = At least one of the RB7:RB4 pins changed state (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
2005 Microchip Technology Inc.DS30487C-page 19
PIC16F87/88
2.2.2.4PIE1 Register
This register contains the individual enable bits for the
peripheral interrupts.
bit 7Unimplemented: Read as ‘0’
bit 6ADIE: A/D Converter Interrupt Enable bit
1 = Enabled
0 = Disabled
Note 1: This bit is only implemente d on the PIC16F 88. The bit will read ‘0’ on the PIC16F87.
bit 5RCIE: AUSART Receive Interrupt Enable bit
1 = Enabled
0 = Disabled
bit 4TXIE: AUSART Transmit Interrupt Enable bit
1 = Enabled
0 = Disabled
bit 3SSPIE: Synchronous Serial Port (SSP) Interrupt Enable bit
1 = Enabled
0 = Disabled
bit 2CCP1IE: CCP1 Interrupt Enable bit
1 = Enabled
0 = Disabled
bit 1TMR2IE: TMR2 to PR2 Match Interrupt Enable bit
1 = Enabled
0 = Disabled
bit 0TMR1IE: TMR1 Overflow Interrupt Enable bit
1 = Enabled
0 = Disabled
(1)
RCIETXIESSPIECCP1IETMR2IETMR1IE
(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
DS30487C-page 20 2005 Microchip Technology Inc.
PIC16F87/88
2.2.2.5PIR1 Register
This register contains the individual flag bits for the
peripheral interrupts.
Note:Interrupt flag bits are set w hen an in terrupt
condition occurs , regardle ss of the st ate 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.
bit 5Unimplemented: Read as ‘0’
bit 4EEIE: EEPROM Write Operation Interrupt Enable bit
1 = Enabled
0 = Disabled
bit 3-0Unimplemented: Read as ‘0’
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
DS30487C-page 22 2005 Microchip Technology Inc.
PIC16F87/88
2.2.2.7PIR2 Register
The PIR2 register contains the fla g bit for the EEPROM
write operation interrupt.
.
Note:Interrupt flag bits are set w hen an in terrupt
condition occurs , regardle ss of the st ate 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 = System oscillator failed, clock input has changed to INTRC (must be cleared in software)
0 = System clock operating
bit 6CMIF: Comparator Interrupt Flag bit
1 = Comparator input has changed (must be cleared in software)
0 = 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 3-0Unimplemented: Read as ‘0’
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
2005 Microchip Technology Inc.DS30487C-page 23
PIC16F87/88
2.2.2.8PCON Register
Note:Interrupt flag bits get set when an interrupt
condition occurs , regardle ss of the st ate 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.
The Power Control (PCON) register contains a flag bit
to allow differentiation between a Power-on Reset
(POR), a Brown-out Reset, an external MCLR Reset
and WDT Reset.
Note:BOR is unknown on Power-on Reset. It
must then be set by the us er an d c hec ke d
on subsequent Resets to see if BOR
clear , indicating a brown-out has occurred.
The BOR status bit is a ‘don’t care’ and is
not necessarily predictable if the brownout circuit is disabled (by clearing the
BOREN bit in the Configuration Word
register).
REGISTER 2-8:PCON: POWER CONTROL REGISTER (ADDRESS 8Eh)
U-0U-0U-0U-0U-0U-0R/W-0R/W-x
——————PORBOR
bit 7bit 0
bit 7-2Unimplemented: Read as ‘0’
bit 1POR
bit 0BOR
: Power-on Reset Status bit
1 = No Power-on Reset occurred
0 = A Power-on Reset occurred (must be set in software after a Power-on Reset occurs)
: Brown-out Reset Status bit
1 = No Brown-out Reset occurred
0 = A Brown-out Reset occurred (must be set in software after a Brown-out Reset occurs)
is
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
DS30487C-page 24 2005 Microchip Technology Inc.
2.3PCL and PCLATH
The Program Counter (PC) is 13 bits wide. The low
byte comes from the PCL register which is a readable
PIC16F87/88
2005 Microchip Technology Inc.DS30487C-page 25
PIC16F87/88
2.5Indirect Addressing, INDF and
FSR Registers
The INDF register is not a physi cal register. Addressing
the INDF register will cause indirect addressing.
Indirect addressing is possible by using the INDF register. Any instruc tion using the INDF register actual ly
accesses the register pointed to by the File Sele ct Register, FSR. Reading the INDF register itself, indirectly
(FSR = 0) will read 00h. Writing to the INDF register
indirectly result s in a no op era tion ( alth oug h status bits
may be affected ). An ef fective 9- bit add ress is obt ained
by concatenating the 8 -bit FSR regi ster and the IRP b it
(STATUS<7>), as shown in Figure 2-5.
FIGURE 2-5:DIRECT/INDIRECT ADDRESSING
RP1:RP 06
Bank SelectLocation Select
From Opcode
0
00011011
00h
80h
100h
A simple program to clear RAM locations 20h-2Fh
using indirect addressing is shown in Example 2-2.
EXAMPLE 2-2:INDIRECT ADDRESSING
MOVLW 0x20;initialize pointer
NEXTCLRFINDF;clear INDF register
CONTINUE
MOVWF FSR;to RAM
INCFFSR, F ;inc pointer
BTFSS FSR, 4 ;all done?
GOTONEXT;no clear next
:;yes continue
Indirect AddressingDirect Addressing
IRPFSR Register
Bank Select
180h
7
0
Location Select
Data
(1)
Memory
7Fh
Bank 0Bank 1Bank 2Bank 3
Note 1:For register file map detail, see Figure 2-2 or Figure 2-3.
FFh
17Fh
1FFh
DS30487C-page 26 2005 Microchip Technology Inc.
PIC16F87/88
3.0DATA EEPROM AND FLASH
PROGRAM MEMORY
The data EEPROM and Flash program memory are
readable and writable during normal operation (over
the full V
in the register file space. Instead, it is indirectly
addressed through the Special Function Registers.
There are six SFRs used to read and write this
memory:
• EECON1
• EECON2
• EEDATA
• EEDATH
• EEADR
• EEADRH
This section focuses on reading and writing data
EEPROM and Flash program memory during normal
operation. Refer to the appropriate device programming specification document for serial programming
information.
When interfacing the data memory block, EEDATA
holds the 8-bit data for read/write and EEADR 0.0677 Tw[(h)12.3(o)-1(ld)12.3w1-1(t)14.3(a)a06772l0 -1.44 cods thad/wi9C.2(8yd EE77 Tw6(h )13.3(EE0-8-651.w3.3(n)0.0101 TFcc)3.5(4nrh)12.)t eo7d.3(eo7)8i1ropo0h
DD range). This memory is not directl y mapped
2005 Microchip Technology Inc.DS30487C-page 27
PIC16F87/88
REGISTER 3-1:EECON1: EEPROM ACCESS CONTROL REGISTER 1 (ADDRESS 18Ch)
R/W-xU-0U-0R/W-xR/W-xR/W-0R/S-0R/S-0
EEPGD——FREEWRERRWRENWRRD
bit 7bit 0
bit 7EEPGD: Program/Data EEPROM Select bit
1 = Accesses program memory
0 = Accesses data memory
bit 6-5Unimplemented: Read as ‘0’
bit 4FREE: EEPROM Forced Row Erase bit
1 = Erase the program memory row a ddressed by EEADRH:EEADR on th e next WR command
0 = Perform write only
bit 3WRERR: EEPROM Error Flag bit
1 = A write operation is prematurely terminated (any MCLR
operation)
0 = The write operation completed
bit 2WREN: EEPROM Write Enable bit
1 = Allows write cycles
0 = Inhibits write to the EEPROM
bit 1WR: Write Control bit
1 = Initiates a write cycle. The bit is cleared by hardware once write is complete. The WR bit
can only be set (not cleared) in software.
0 = Write cycle to the EEPROM is complete
bit 0RD: Read Control bit
1 = Initiates an EEPROM read, RD is cleared in hardware. The RD bit can only be set (not
cleared) in software.
0 = Does not initiate an EEPROM read
or any WDT Reset during normal
Legend:
R = Readable bi tW = Writable bitU = Un implemented bit, read as ‘0 ’ S = Set only
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
DS30487C-page 28 2005 Microchip Technology Inc.
Loading...
+ 198 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.