14.0 SPECIAL FEATURES OF THE CPU
All PIC16F87XA devices have a host of features intended to maximize system reliability, minimize cost through elimination of external components, provide power saving operating modes and offer code protection. These are:
- Oscillator Selection
- Reset
- Power-on Reset (POR)
- Power-up Timer (PWRT)
- Oscillator Start-up Timer (OST)
- Brown-out Reset (BOR)
- Interrupts
- Watchdog Timer (WDT)
- Sleep
- Code Protection
- ID Locations
- In-Circuit Serial Programming
- Low-Voltage In-Circuit Serial Programming
- In-Circuit Debugger
PIC16F87XA devices have a Watchdog Timer which can be shut-off only through configuration bits. It runs off its own RC oscillator for added reliability.
There are two timers that offer necessary delays on power-up. One is the Oscillator Start-up Timer (OST), intended to keep the chip in Reset until the crystal oscillator is stable. The other is the Power-up Timer (PWRT), which provides a fixed delay of 72 ms (nominal) on power-up only. It is designed to keep the part in Reset while the power supply stabilizes. With these two timers on-chip, most applications need no external Reset circuitry.
Sleep mode is designed to offer a very low current power-down mode. The user can wake-up from Sleep through external Reset, Watchdog Timer wake-up or through an interrupt.
Several oscillator options are also made available to allow the part to fit the application. The RC oscillator option saves system cost while the LP crystal option saves power. A set of configuration bits is used to select various options.
Additional information on special features is available in the PIC® Mid-Range MCU Family Reference Manual (DS33023).
14.1 Configuration Bits
The configuration bits can be programmed (read as '0'), or left unprogrammed (read as '1') to select various device configurations. The erased or unprogrammed value of the Configuration Word register is 3FFFh. These bits are mapped in program memory location 2007h.
It is important to note that address 2007h is beyond the user program memory space which can be accessed only during programming.
REGISTER 14-1: CONFIGURATION WORD (ADDRESS 2007h)(1)
| R/P-1 | U-0 | R/P-1 | R/P-1 | R/P-1 | R/P-1 | R/P-1 | R/P-1 | U-0 | U-0 | R/P-1 | R/P-1 | R/P-1 | R/P-1 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| CP | — | DEBUG | WRT1 | WRT0 | CPD | LVP | BOREN | — | — | PWR TEN | WDTEN | Fosc1 | Fosc0 |
| bit 13 | bit0 |
bit 13
CP: Flash Program Memory Code Protection bit
1 = Code protection off
0 = All program memory code-protected
bit 12
Unimplemented: Read as ‘1’
bit 11
DEBUG: In-Circuit Debugger Mode bit
1 = In-Circuit Debugger disabled, RB6 and RB7 are general purpose I/O pins
0 = In-Circuit Debugger enabled, RB6 and RB7 are dedicated to the debugger
bit 10-9
WRT1:WRT0 Flash Program Memory Write Enable bits
For PIC16F876A/877A:
11 = Write protection off; all program memory may be written to by EECON control
10 = 0000h to 00FFh write-protected; 0100h to 1FFFh may be written to by EECON control
01 = 0000h to 07FFh write-protected; 0800h to 1FFFh may be written to by EECON control
00 = 0000h to 0FFFh write-protected; 1000h to 1FFFh may be written to by EECON control
For PIC16F873A/874A:
11 = Write protection off; all program memory may be written to by EECON control
10 = 0000h to 00FFh write-protected; 0100h to 0FFFh may be written to by EECON control
01 = 0000h to 03FFh write-protected; 0400h to 0FFFh may be written to by EECON control
00 = 0000h to 07FFh write-protected; 0800h to 0FFFh may be written to by EECON control
bit 8
CPD: Data EEPROM Memory Code Protection bit
1 = Data EEPROM code protection off
0 = Data EEPROM code-protected
bit 7
LVP: Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit
1 = RB3/PGM pin has PGM function; low-voltage programming enabled
0 = RB3 is digital I/O, HV on MCLR must be used for programming
bit 6
BOREN: Brown-out Reset Enable bit
1 = BOR enabled
0 = BOR disabled
bit 5-4
Unimplemented: Read as ‘1’
bit 3
PWR TEN: Power-up Timer Enable bit
1 = PWRT disabled
0 = PWRT enabled
bit 2
WDTEN: Watchdog Timer Enable bit
1 = WDT enabled
0 = WDT disabled
bit 1-0
Fosc1:Fosc0: Oscillator Selection bits
11 = RC oscillator
10 = HS oscillator
01 = XT oscillator
00 = LP oscillator
Legend:
R = Readable bit
P = Programmable bit
U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed
u = Unchanged from programmed state
Note 1: The erased (unprogrammed) value of the Configuration Word is 3FFFh.
14.2 Oscillator Configurations
14.2.1 OSCILLATOR TYPES
The PIC16F87XA can be operated in four different oscillator modes. The user can program two configuration bits (Fosc1 and Fosc0) to select one of these four modes:
- LP Low-Power Crystal
- XT Crystal/Resonator
- HS High-Speed Crystal/Resonator
- RC Resistor/Capacitor
14.2.2 CRYSTAL OSCILLATOR/CERAMIC RESONATORS
In XT, LP or HS modes, a crystal or ceramic resonator is connected to the OSC1/CLKI and OSC2/CLKO pins to establish oscillation (Figure 14-1). The PIC16F87XA oscillator design requires the use of a parallel cut crystal. Use of a series cut crystal may give a frequency out of the crystal manufacturer’s specifications. When in XT, LP or HS modes, the device can have an external clock source to drive the OSC1/CLKI pin (Figure 14-2).
FIGURE 14-1: CRYSTAL/CERAMIC RESONATOR OPERATION (HS, XT OR LP OSC CONFIGURATION)

Note 1: See Table 14-1 and Table 14-2 for recommended values of C1 and C2.
2: A series resistor (Rs) may be required for AT strip cut crystals.
3: RF varies with the crystal chosen.
FIGURE 14-2: EXTERNAL CLOCK INPUT OPERATION (HS, XT OR LP OSC CONFIGURATION)

TABLE 14-1: CERAMIC RESONATORS
| Ranges Tested: | |||
|---|---|---|---|
| Mode | Freq. | OSC1 | OSC2 |
| XT | 455 kHz | 68-100 pF | 68-100 pF |
| 2.0 MHz | 15-68 pF | 15-68 pF | |
| 4.0 MHz | 15-68 pF | 15-68 pF | |
| HS | 8.0 MHz | 10-68 pF | 10-68 pF |
| 16.0 MHz | 10-22 pF | 10-22 pF | |
| These values are for design guidance only. See notes following Table 14-2. | |||
| Resonators Used: | |||
| 2.0 MHz | Murata Erie CSA2.00MG | ± 0.5% | |
| 4.0 MHz | Murata Erie CSA4.00MG | ± 0.5% | |
| 8.0 MHz | Murata Erie CSA8.00MT | ± 0.5% | |
| 16.0 MHz | Murata Erie CSA16.00MX | ± 0.5% | |
| All resonators used did not have built-in capacitors. |
TABLE 14-2: CAPACITOR SELECTION FOR CRYSTAL OSCILLATOR
| Osc Type | Crystal Freq. | Cap. Range C1 | Cap. Range C2 |
|---|---|---|---|
| LP | 32 kHz | 33 pF | 33 pF |
| 200 kHz | 15 pF | 15 pF | |
| XT | 200 kHz | 47-68 pF | 47-68 pF |
| 1 MHz | 15 pF | 15 pF | |
| 4 MHz | 15 pF | 15 pF | |
| HS | 4 MHz | 15 pF | 15 pF |
| 8 MHz | 15-33 pF | 15-33 pF | |
| 20 MHz | 15-33 pF | 15-33 pF |
These values are for design guidance only.
See notes following this table.
Crystals Used
| 32 kHz | Epson C-001R32.768K-A | ± 20 PPM |
|---|---|---|
| 200 kHz | STD XTL 200.000KHz | ± 20 PPM |
| 1 MHz | ECS ECS-10-13-1 | ± 50 PPM |
| 4 MHz | ECS ECS-40-20-1 | ± 50 PPM |
| 8 MHz | EPSON CA-301 8.000M-C | ± 30 PPM |
| 20 MHz | EPSON CA-301 20.000M-C | ± 30 PPM |
Note 1: Higher capacitance increases the stability of oscillator but also increases the start-up time.
2: Since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external components.
3: RS may be required in HS mode, as well as XT mode, to avoid overdriving crystals with low drive level specification.
4: When migrating from other PIC® devices, oscillator performance should be verified.
14.2.3 RC OSCILLATOR
For timing insensitive applications, the “RC” device option offers additional cost savings. The RC oscillator frequency is a function of the supply voltage, the resistor (REXT) and capacitor (CEXT) values and the operating temperature. In addition to this, the oscillator frequency will vary from unit to unit due to normal process parameter variation. Furthermore, the difference in lead frame capacitance between package types will also affect the oscillation frequency, especially for low CEXT values. The user also needs to take into account variation due to tolerance of external R and C components used. Figure 14-3 shows how the R/C combination is connected to the PIC16F87XA.
FIGURE 14-3: RC OSCILLATOR MODE

Recommended values: 3 kΩ ≤ REXT ≤ 100 kΩ
CEXT > 20 pF
14.3 Reset
The PIC16F87XA differentiates between various kinds of Reset:
- Power-on Reset (POR)
- \overlineMCLR Reset during normal operation
- \overlineMCLR Reset during Sleep
- WDT Reset (during normal operation)
- WDT Wake-up (during Sleep)
- Brown-out Reset (BOR)
Some registers are not affected in any Reset condition. Their status is unknown on POR and unchanged in any other Reset. Most other registers are reset to a "Reset state" on Power-on Reset (POR), on the \overlineMCLR and WDT Reset, on \overlineMCLR Reset during Sleep and Brown-out Reset (BOR). They are not affected by a WDT wake-up which is viewed as the resumption of normal operation. The \overlineTO and \overlinePD bits are set or cleared differently in different Reset situations as indicated in Table 14-4. These bits are used in software to determine the nature of the Reset. See Table 14-6 for a full description of Reset states of all registers.
A simplified block diagram of the on-chip Reset circuit is shown in Figure 14-4.
FIGURE 14-4: SIMPLIFIED BLOCK DIAGRAM OF ON-CHIP RESET CIRCUIT

Note 1: This is a separate oscillator from the RC oscillator of the CLKI pin.
14.4 MCLR
PIC16F87XA devices have a noise filter in the MCLR Reset path. The filter will detect and ignore small pulses.
It should be noted that a WDT Reset does not drive MCLR pin low.
The behavior of the ESD protection on the MCLR pin differs from previous devices of this family. Voltages applied to the pin that exceed its specification can result in both Resets and current consumption outside of device specification during the Reset event. For this reason, Microchip recommends that the MCLR pin no longer be tied directly to VDD. The use of an RCR network, as shown in Figure 14-5, is suggested.
FIGURE 14-5: RECOMMENDED MCLR CIRCUIT

Note 1: R1 < 40 kΩ is recommended to make sure that the voltage drop across R does not violate the device’s electrical specification.
2: R2 > than 1K will limit any current flowing into MCLR from the external capacitor C, in the event of MCLR/VPP breakdown due to Electrostatic Discharge (ESD) or Electrical Overstress (EOS).
14.5 Power-on Reset (POR)
A Power-on Reset pulse is generated on-chip when VDD rise is detected (in the range of 1.2V-1.7V). To take advantage of the POR, tie the MCLR pin to VDD through an RC network, as described in Section 14.4 “MCLR”. A maximum rise time for VDD is specified. See Section 17.0 “Electrical Characteristics” for details.
When the device starts normal operation (exits the Reset condition), device operating parameters (voltage, frequency, temperature, etc.) must be met to ensure operation. If these conditions are not met, the device must be held in Reset until the operating conditions are met. Brown-out Reset may be used to meet the start-up conditions. For additional information, refer to application note, AN607, “Power-up Trouble Shooting” (DS00607).
14.6 Power-up Timer (PWRT)
The Power-up Timer provides a fixed 72 ms nominal time-out on power-up only from the POR. The Power-up Timer operates on an internal RC oscillator. The chip is kept in Reset as long as the PWRT is active. The PWRT’s time delay allows VDD to rise to an acceptable level. A configuration bit is provided to enable or disable the PWRT.
The power-up time delay will vary from chip to chip due to VDD, temperature and process variation. See Section 17.0 “Electrical Characteristics” for details (TPWRT, parameter #33).
14.7 Oscillator Start-up Timer (OST)
The Oscillator Start-up Timer (OST) provides a delay of 1024 oscillator cycles (from OSC1 input) after the PWRT delay is over (if PWRT is enabled). This helps to ensure that the crystal oscillator or resonator has started and stabilized.
The OST time-out is invoked only for XT, LP and HS modes and only on Power-on Reset or wake-up from Sleep.
14.8 Brown-out Reset (BOR)
The configuration bit, BODEN, can enable or disable the Brown-out Reset circuit. If VDD falls below VBOR (parameter D005, about 4V) for longer than TBOR (parameter #35, about 100 μS), the brown-out situation will reset the device. If VDD falls below VBOR for less than TBOR, a Reset may not occur.
Once the brown-out occurs, the device will remain in Brown-out Reset until VDD rises above VBOR. The Power-up Timer then keeps the device in Reset for TPWRT (parameter #33, about 72 mS). If VDD should fall below VBOR during TPWRT, the Brown-out Reset process will restart when VDD rises above VBOR with the Power-up Timer Reset. The Power-up Timer is always enabled when the Brown-out Reset circuit is enabled, regardless of the state of the PWRT configuration bit.
14.9 Time-out Sequence
On power-up, the time-out sequence is as follows: the PWRT delay starts (if enabled) when a POR Reset occurs. Then, OST starts counting 1024 oscillator cycles when PWRT ends (LP, XT, HS). When the OST ends, the device comes out of Reset.
If MCLR is kept low long enough, the time-outs will expire. Bringing MCLR high will begin execution immediately. This is useful for testing purposes or to synchronize more than one PIC16F87XA device operating in parallel.
Table 14-5 shows the Reset conditions for the Status, PCON and PC registers, while Table 14-6 shows the Reset conditions for all the registers.
14.10 Power Control/Status Register (PCON)
The Power Control/Status Register, PCON, has up to two bits depending upon the device.
Bit 0 is the Brown-out Reset Status bit, \overlineBOR. The \overlineBOR bit is unknown on a Power-on Reset. It must then be set by the user and checked on subsequent Resets to see if it has been cleared, indicating that a BOR has occurred.
When the Brown-out Reset is disabled, the state of the \overlineBOR bit is unpredictable and is, therefore, not valid at any time.
Bit 1 is the Power-on Reset Status bit, \overlinePOR. It is cleared on a Power-on Reset and unaffected otherwise. The user must set this bit following a Power-on Reset.
TABLE 14-3: TIME-OUT IN VARIOUS SITUATIONS
| Oscillator Configuration | Power-up | Brown-out | Wake-up from Sleep | |
|---|---|---|---|---|
| PWRTE = 0 | PWRTE = 1 | |||
| XT, HS, LP | 72 ms + 1024 TOSC | 1024 TOSC | 72 ms + 1024 TOSC | 1024 TOSC |
| RC | 72 ms | — | 72 ms | — |
TABLE 14-4: STATUS BITS AND THEIR SIGNIFICANCE
| \overlinePOR | \overlineBOR | \overlineTO | \overlinePD | Condition |
|---|---|---|---|---|
| 0 | x | 1 | 1 | Power-on Reset |
| 0 | x | 0 | x | Illegal, \overlineTO is set on \overlinePOR |
| 0 | x | x | 0 | Illegal, \overlinePD is set on \overlinePOR |
| 1 | 0 | 1 | 1 | Brown-out Reset |
| 1 | 1 | 0 | 1 | WDT Reset |
| 1 | 1 | 0 | 0 | WDT Wake-up |
| 1 | 1 | u | u | \overlineMCLR Reset during normal operation |
| 1 | 1 | 1 | 0 | \overlineMCLR Reset during Sleep or Interrupt Wake-up from Sleep |
Legend: x = don’t care, u = unchanged
TABLE 14-5: RESET CONDITIONS FOR SPECIAL REGISTERS
| Condition | Program Counter | Status Register | PCON Register |
|---|---|---|---|
| Power-on Reset | 000h | 0001 1xxx | ---- --0x |
| \overlineMCLR Reset during normal operation | 000h | 000u uuuu | ---- --uu |
| \overlineMCLR Reset during Sleep | 000h | 0001 0uuu | ---- --uu |
| WDT Reset | 000h | 0000 1uuu | ---- --uu |
| WDT Wake-up | PC + 1 | uuu0 0uuu | ---- --uu |
| Brown-out Reset | 000h | 0001 1uuu | ---- --u0 |
| Interrupt Wake-up from Sleep | PC + 1(1) | uuu1 0uuu | ---- --uu |
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’
Note 1: When the wake-up is due to an interrupt and the GIE bit is set, the PC is loaded with the interrupt vector (0004h).
TABLE 14-6: INITIALIZATION CONDITIONS FOR ALL REGISTERS
| Register | Devices | Power-on Reset, Brown-out Reset | MCLR Resets, WDT Reset | Wake-up via WDT or Interrupt | |||
|---|---|---|---|---|---|---|---|
| 73A | 74A | 76A | 77A | ||||
| W | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| INDF | 73A | 74A | 76A | 77A | N/A | N/A | N/A |
| TMR0 | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| PCL | 73A | 74A | 76A | 77A | 0000 0000 | 0000 0000 | PC + 1(2) |
| STATUS | 73A | 74A | 76A | 77A | 0001 1xxx | 000q quuu(3) | uuug quuu(3) |
| FSR | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| PORTA | 73A | 74A | 76A | 77A | --0x 0000 | --0u 0000 | --uu uuuu |
| PORTB | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| PORTC | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| PORTD | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| PORTE | 73A | 74A | 76A | 77A | ---- -xxx | ---- -uuu | ---- -uuu |
| PCLATH | 73A | 74A | 76A | 77A | ---0 0000 | ---0 0000 | ---u uuuu |
| INTCON | 73A | 74A | 76A | 77A | 0000 000x | 0000 000u | uuuu uuuu(1) |
| PIR1 | 73A | 74A | 76A | 77A | r000 0000 | r000 0000 | ruuu uuuu(1) |
| 73A | 74A | 76A | 77A | 0000 0000 | 0000 0000 | uuuu uuuu(1) | |
| PIR2 | 73A | 74A | 76A | 77A | -0-0 0--0 | -0-0 0--0 | -u-u u--u(1) |
| TMR1L | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| TMR1H | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| T1CON | 73A | 74A | 76A | 77A | --00 0000 | --uu uuuu | --uu uuuu |
| TMR2 | 73A | 74A | 76A | 77A | 0000 0000 | 0000 0000 | uuuu uuuu |
| T2CON | 73A | 74A | 76A | 77A | -000 0000 | -000 0000 | -uuu uuuu |
| SSPBUF | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| SSPCON | 73A | 74A | 76A | 77A | 0000 0000 | 0000 0000 | uuuu uuuu |
| CCPR1L | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| CCPR1H | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| CCP1CON | 73A | 74A | 76A | 77A | --00 0000 | --00 0000 | --uu uuuu |
| RCSTA | 73A | 74A | 76A | 77A | 0000 000x | 0000 000x | uuuu uuuu |
| TXREG | 73A | 74A | 76A | 77A | 0000 0000 | 0000 0000 | uuuu uuuu |
| RCREG | 73A | 74A | 76A | 77A | 0000 0000 | 0000 0000 | uuuu uuuu |
| CCPR2L | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| CCPR2H | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| CCP2CON | 73A | 74A | 76A | 77A | 0000 0000 | 0000 0000 | uuuu uuuu |
| ADRESH | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| ADCON0 | 73A | 74A | 76A | 77A | 0000 00-0 | 0000 00-0 | uuuu uu-u |
| OPTION_REG | 73A | 74A | 76A | 77A | 1111 1111 | 1111 1111 | uuuu uuuu |
| TRISA | 73A | 74A | 76A | 77A | --11 1111 | --11 1111 | --uu uuuu |
| TRISB | 73A | 74A | 76A | 77A | 1111 1111 | 1111 1111 | uuuu uuuu |
| TRISC | 73A | 74A | 76A | 77A | 1111 1111 | 1111 1111 | uuuu uuuu |
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition, r = reserved, maintain clear. Shaded cells indicate conditions do not apply for the designated device.
Note 1: One or more bits in INTCON, PIR1 and/or PIR2 will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GIE bit is set, the PC is loaded with the interrupt vector (0004h).
3: See Table 14-5 for Reset value for specific condition.
DS39582C-page 150 © 2001-2013 Microchip Technology Inc.
TABLE 14-6: INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
| Register | Devices | Power-on Reset, Brown-out Reset | MCLR Resets, WDT Reset | Wake-up via WDT or Interrupt | |||
|---|---|---|---|---|---|---|---|
| 73A | 74A | 76A | 77A | ||||
| TRISD | 73A | 74A | 76A | 77A | 1111 1111 | 1111 1111 | uuuu uuuu |
| TRISE | 73A | 74A | 76A | 77A | 0000 -111 | 0000 -111 | uuuu -uuu |
| PIE1 | 73A | 74A | 76A | 77A | r000 0000 | r000 0000 | ruuu uuuu |
| 73A | 74A | 76A | 77A | 0000 0000 | 0000 0000 | uuuu uuuu | |
| PIE2 | 73A | 74A | 76A | 77A | -0-0 0--0 | -0-0 0--0 | -u-u u--u |
| PCON | 73A | 74A | 76A | 77A | ---- --uu | ---- --uu | |
| SSPCON2 | 73A | 74A | 76A | 77A | 0000 0000 | 0000 0000 | uuuu uuuu |
| PR2 | 73A | 74A | 76A | 77A | 1111 1111 | 1111 1111 | 1111 1111 |
| SSPADD | 73A | 74A | 76A | 77A | 0000 0000 | 0000 0000 | uuuu uuuu |
| SSPSTAT | 73A | 74A | 76A | 77A | --00 0000 | --00 0000 | --uu uuuu |
| TXSTA | 73A | 74A | 76A | 77A | 0000 -010 | 0000 -010 | uuuu -uuu |
| SPBRG | 73A | 74A | 76A | 77A | 0000 0000 | 0000 0000 | uuuu uuuu |
| CMCON | 73A | 974 | 76A | 77A | 0000 0111 | 0000 0111 | uuuu uuuu |
| CVRCON | 73A | 74A | 76A | 77A | 000- 0000 | 000- 0000 | uuu- uuuu |
| ADRESL | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| ADCON1 | 73A | 74A | 76A | 77A | 00-- 0000 | 00-- 0000 | uu-- uuuu |
| EEDATA | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| EEADR | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| EEDATH | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| EEADRH | 73A | 74A | 76A | 77A | xxxx xxxx | uuuu uuuu | uuuu uuuu |
| EECON1 | 73A | 74A | 76A | 77A | x--- x000 | u--- u000 | u--- uuuu |
| EECON2 | 73A | 74A | 76A | 77A | ---- ---- | ---- ---- | ---- ---- |
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition, r = reserved, maintain clear. Shaded cells indicate conditions do not apply for the designated device.
Note 1: One or more bits in INTCON, PIR1 and/or PIR2 will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GIE bit is set, the PC is loaded with the interrupt vector (0004h).
3: See Table 14-5 for Reset value for specific condition.
FIGURE 14-6: TIME-OUT SEQUENCE ON POWER-UP (MCLR TIED TO VDD VIA RC NETWORK)

FIGURE 14-7: TIME-OUT SEQUENCE ON POWER-UP (\overlineMCLR NOT TIED TO VDD): CASE 1

FIGURE 14-8: TIME-OUT SEQUENCE ON POWER-UP (\overlineMCLR NOT TIED TO VDD): CASE 2

FIGURE 14-9: SLOW RISE TIME (\overlineMCLR TIED TO VDD VIA RC NETWORK)

DS39582C-page 152 © 2001-2013 Microchip Technology Inc.
14.11 Interrupts
The PIC16F87XA family has up to 15 sources of interrupt. The Interrupt Control register (INTCON) records individual interrupt requests in flag bits. It also has individual and global interrupt enable bits.
Note: Individual interrupt flag bits are set regardless of the status of their corresponding mask bit or the GIE bit.
A global interrupt enable bit, GIE (INTCON<7>), enables (if set) all unmasked interrupts or disables (if cleared) all interrupts. When bit GIE is enabled and an interrupt's flag bit and mask bit are set, the interrupt will vector immediately. Individual interrupts can be disabled through their corresponding enable bits in various registers. Individual interrupt bits are set regardless of the status of the GIE bit. The GIE bit is cleared on Reset.
The "return from interrupt" instruction, RETFIE, exits the interrupt routine, as well as sets the GIE bit, which re-enables interrupts.
The RB0/INT pin interrupt, the RB port change interrupt and the TMR0 overflow interrupt flags are contained in the INTCON register.
The peripheral interrupt flags are contained in the Special Function Registers, PIR1 and PIR2. The corresponding interrupt enable bits are contained in Special Function Registers, PIE1 and PIE2, and the peripheral interrupt enable bit is contained in Special Function Register, INTCON.
When an interrupt is responded to, the GIE bit is cleared to disable any further interrupt, the return address is pushed onto the stack and the PC is loaded with 0004h. Once in the Interrupt Service Routine, the source(s) of the interrupt can be determined by polling the interrupt flag bits. The interrupt flag bit(s) must be cleared in software before re-enabling interrupts to avoid recursive interrupts.
For external interrupt events, such as the INT pin or PORTB change interrupt, the interrupt latency will be three or four instruction cycles. The exact latency depends when the interrupt event occurs. The latency is the same for one or two-cycle instructions. Individual interrupt flag bits are set regardless of the status of their corresponding mask bit, PEIE bit or GIE bit.
FIGURE 14-10: INTERRUPT LOGIC

Note 1: PSP interrupt is implemented only on PIC16F874A/877A devices.
14.11.1 INT INTERRUPT
External interrupt on the RB0/INT pin is edge triggered, either rising if bit INTEDG (OPTION_REG<6>) is set or falling if the INTEDG bit is clear. When a valid edge appears on the RB0/INT pin, flag bit, INTF (INTCON<1>), is set. This interrupt can be disabled by clearing enable bit, INTE (INTCON<4>). Flag bit INTF must be cleared in software in the Interrupt Service Routine before re-enabling this interrupt. The INT interrupt can wake-up the processor from Sleep if bit INTE was set prior to going into Sleep. The status of global interrupt enable bit, GIE, decides whether or not the processor branches to the interrupt vector following wake-up. See Section 14.14 “Power-down Mode (Sleep)” for details on Sleep mode.
14.11.2 TMR0 INTERRUPT
An overflow (FFh → 00h) in the TMR0 register will set flag bit, TMR0IF (INTCON<2>). The interrupt can be enabled/disabled by setting/clearing enable bit, TMR0IE (INTCON<5>). See Section 5.0 “Timer0 Module”.
14.11.3 PORTB INTCON CHANGE
An input change on PORTB<7:4> sets flag bit, RBIF (INTCON<0>). The interrupt can be enabled/disabled by setting/clearing enable bit, RBIE (INTCON<4>). See Section 4.2 “PORTB and the TRISB Register”.
14.12 Context Saving During Interrupts
During an interrupt, only the return PC value is saved on the stack. Typically, users may wish to save key registers during an interrupt (i.e., W register and Status register). This will have to be implemented in software.
For the PIC16F873A/874A devices, the register W_TEMP must be defined in both Banks 0 and 1 and must be defined at the same offset from the bank base address (i.e., If W_TEMP is defined at 0x20 in Bank 0, it must also be defined at 0xA0 in Bank 1). The registers, PCLATH_TEMP and STATUS_TEMP, are only defined in Bank 0.
Since the upper 16 bytes of each bank are common in the PIC16F876A/877A devices, temporary holding registers, W_TEMP, STATUS_TEMP and PCLATH_TEMP, should be placed in here. These 16 locations don’t require banking and therefore, make it easier for context save and restore. The same code shown in Example 14-1 can be used.
EXAMPLE 14-1: SAVING STATUS, W AND PCLATH REGISTERS IN RAM
\begin{tabular}{lll} MOVWF & W_TEMP & ;Copy W to TEMP register \ SWAPF & STATUS,W & ;Swap status to be saved into W \ CLRF & STATUS & ;bank 0, regardless of current bank, Clears IRP,RP1,RP0 \ MOVWF & STATUS_TEMP & ;Save status to bank zero STATUS_TEMP register \ MOVF & PCLATH, W & ;Only required if using pages 1, 2 and/or 3 \ MOVWF & PCLATH_TEMP & ;Save PCLATH into W \ CLRF & PCLATH & ;Page zero, regardless of current page \ : & & \ :(ISR) & & ;(Insert user code here) \ : & & \ MOVF & PCLATH_TEMP, W & ;Restore PCLATH \ MOVWF & PCLATH & ;Move W into PCLATH \ SWAPF & STATUS_TEMP,W & ;Swap STATUS_TEMP register into W \ & & ;(sets bank to original state) \ MOVWF & STATUS & ;Move W into STATUS register \ SWAPF & W_TEMP,F & ;Swap W_TEMP \ SWAPF & W_TEMP,W & ;Swap W_TEMP into W \ \end{tabular}
14.13 Watchdog Timer (WDT)
The Watchdog Timer is a free running, on-chip RC oscillator which does not require any external components. This RC oscillator is separate from the RC oscillator of the OSC1/CLKI pin. That means that the WDT will run even if the clock on the OSC1/CLKI and OSC2/CLKO pins of the device has been stopped, for example, by execution of a SLEEP instruction.
During normal operation, a WDT time-out generates a device Reset (Watchdog Timer Reset). If the device is in Sleep mode, a WDT time-out causes the device to wake-up and continue with normal operation (Watchdog Timer Wake-up). The TO bit in the Status register will be cleared upon a Watchdog Timer time-out.
The WDT can be permanently disabled by clearing configuration bit, WDTE (Section 14.1 “Configuration Bits”).
WDT time-out period values may be found in Section 17.0 “Electrical Characteristics” under parameter #31. Values for the WDT prescaler (actually a postscaler but shared with the Timer0 prescaler) may be assigned using the OPTION_REG register.
Note 1: The CLRWDT and SLEEP instructions clear the WDT and the postscaler, if assigned to the WDT and prevent it from timing out and generating a device Reset condition.
2: When a CLRWDT instruction is executed and the prescaler is assigned to the WDT, the prescaler count will be cleared but the prescaler assignment is not changed.
FIGURE 14-11: WATCHDOG TIMER BLOCK DIAGRAM

TABLE 14-7: SUMMARY OF WATCHDOG TIMER REGISTERS
| Address | Name | Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 |
|---|---|---|---|---|---|---|---|---|---|
| 2007h | Config. bits | (1) | BODEN(1) | CP1 | CP0 | PWRTE(1) | WDTE | Fosc1 | Fosc0 |
| 81h, 181h | OPTION_REG | RBPU | INTEDG | T0CS | T0SE | PSA | PS2 | PS1 | PS0 |
Legend: Shaded cells are not used by the Watchdog Timer.
Note 1: See Register 14-1 for operation of these bits.
14.14 Power-down Mode (Sleep)
Power-down mode is entered by executing a SLEEP instruction.
If enabled, the Watchdog Timer will be cleared but keeps running, the PD bit (Status<3>) is cleared, the TO (Status<4>) bit is set and the oscillator driver is turned off. The I/O ports maintain the status they had before the SLEEP instruction was executed (driving high, low or high-impedance).
For lowest current consumption in this mode, place all I/O pins at either VDD or VSS, ensure no external circuitry is drawing current from the I/O pin, power-down the A/D and disable external clocks. Pull all I/O pins that are high-impedance inputs, high or low externally, to avoid switching currents caused by floating inputs. The T0CKI input should also be at VDD or VSS for lowest current consumption. The contribution from on-chip pull-ups on PORTB should also be considered.
The MCLR pin must be at a logic high level (VIHMC).
14.14.1 WAKE-UP FROM SLEEP
The device can wake-up from Sleep through one of the following events:
- External Reset input on MCLR pin.
- Watchdog Timer wake-up (if WDT was enabled).
- Interrupt from INT pin, RB port change or peripheral interrupt.
External MCLR Reset will cause a device Reset. All other events are considered a continuation of program execution and cause a "wake-up". The TO and PD bits in the Status register can be used to determine the cause of device Reset. The PD bit, which is set on power-up, is cleared when Sleep is invoked. The TO bit is cleared if a WDT time-out occurred and caused wake-up.
The following peripheral interrupts can wake the device from Sleep:
- PSP read or write (PIC16F874/877 only).
- TMR1 interrupt. Timer1 must be operating as an asynchronous counter.
- CCP Capture mode interrupt.
- Special event trigger (Timer1 in Asynchronous mode using an external clock).
- SSP (Start/Stop) bit detect interrupt.
- SSP transmit or receive in Slave mode (SPI/I²C).
- USART RX or TX (Synchronous Slave mode).
- A/D conversion (when A/D clock source is RC).
- EEPROM write operation completion.
- Comparator output changes state.
Other peripherals cannot generate interrupts since during Sleep, no on-chip clocks are present.
When the SLEEP instruction is being executed, the next instruction (PC + 1) is prefetched. For the device to wake-up through an interrupt event, the corresponding interrupt enable bit must be set (enabled). Wake-up is regardless of the state of the GIE bit. If the GIE bit is clear (disabled), the device continues execution at the instruction after the SLEEP instruction. If the GIE bit is set (enabled), the device executes the instruction after the SLEEP instruction and then branches to the interrupt address (0004h). In cases where the execution of the instruction following SLEEP is not desirable, the user should have a NOP after the SLEEP instruction.
14.14.2 WAKE-UP USING INTERRUPTS
When global interrupts are disabled (GIE cleared) and any interrupt source has both its interrupt enable bit and interrupt flag bit set, one of the following will occur:
- If the interrupt occurs before the execution of a SLEEP instruction, the SLEEP instruction will complete as a NOP. Therefore, the WDT and WDT postscaler will not be cleared, the TO bit will not be set and PD bits will not be cleared.
- If the interrupt occurs during or after the execution of a SLEEP instruction, the device will immediately wake-up from Sleep. The SLEEP instruction will be completely executed before the wake-up. Therefore, the WDT and WDT postscaler will be cleared, the TO bit will be set and the PD bit will be cleared.
Even if the flag bits were checked before executing a SLEEP instruction, it may be possible for flag bits to become set before the SLEEP instruction completes. To determine whether a SLEEP instruction executed, test the PD bit. If the PD bit is set, the SLEEP instruction was executed as a NOP.
To ensure that the WDT is cleared, a CLRWDT instruction should be executed before a SLEEP instruction.
DS39582C-page 156 © 2001-2013 Microchip Technology Inc.
FIGURE 14-12: WAKE-UP FROM SLEEP THROUGH INTERRUPT

Note 1: XT, HS or LP Oscillator mode assumed.
2: TOST = 1024 TOSC (drawing not to scale). This delay will not be there for RC Oscillator mode.
3: GIE = 1 assumed. In this case, after wake-up, the processor jumps to the interrupt routine.
If GIE = 0, execution will continue in-line.
4: CLKO is not available in these oscillator modes but shown here for timing reference.
14.15 In-Circuit Debugger
When the DEBUG bit in the configuration word is programmed to a ‘0’, the in-circuit debugger functionality is enabled. This function allows simple debugging functions when used with MPLAB® ICD. When the microcontroller has this feature enabled, some of the resources are not available for general use. Table 14-8 shows which features are consumed by the background debugger.
TABLE 14-8: DEBUGGER RESOURCES
| I/O pins | RB6, RB7 |
|---|---|
| Stack | 1 level |
| Program Memory | Address 0000h must be NOP |
| Last 100h words | |
| Data Memory | 0x070 (0x0F0, 0x170, 0x1F0) |
| 0x1EB-0x1EF |
To use the in-circuit debugger function of the microcontroller, the design must implement In-Circuit Serial Programming connections to MCLR/VPP, VDD, GND, RB7 and RB6. This will interface to the in-circuit debugger module available from Microchip or one of the third party development tool companies.
14.16 Program Verification/Code Protection
If the code protection bit(s) have not been programmed, the on-chip program memory can be read out for verification purposes.
14.17 ID Locations
Four memory locations (2000h-2003h) are designated as ID locations, where the user can store checksum or other code identification numbers. These locations are not accessible during normal execution but are readable and writable during program/verify. It is recommended that only the 4 Least Significant bits of the ID location are used.
14.18 In-Circuit Serial Programming
PIC16F87XA microcontrollers can be serially programmed while in the end application circuit. This is simply done with two lines for clock and data and three other lines for power, ground and the programming voltage. This allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. This also allows the most recent firmware or a custom firmware to be programmed.
When using ICSP, the part must be supplied at 4.5V to 5.5V if a bulk erase will be executed. This includes reprogramming of the code-protect, both from an on state to an off state. For all other cases of ICSP, the part may be programmed at the normal operating voltages. This means calibration values, unique user IDs or user code can be reprogrammed or added.
For complete details of serial programming, please refer to the "PIC16F87XA Flash Memory Programming Specification" (DS39589).
14.19 Low-Voltage (Single-Supply) ICSP Programming
The LVP bit of the configuration word enables low-voltage ICSP programming. This mode allows the microcontroller to be programmed via ICSP using a VDD source in the operating voltage range. This only means that VPP does not have to be brought to VIH H but can instead be left at the normal operating voltage. In this mode, the RB3/PGM pin is dedicated to the programming function and ceases to be a general purpose I/O pin. During programming, VDD is applied to the MCLR pin. To enter Programming mode, VDD must be applied to the RB3/PGM provided the LVP bit is set. The LVP bit defaults to on ('1') from the factory.
Note 1: The High-Voltage Programming mode is always available, regardless of the state of the LVP bit, by applying VIH H to the MCLR pin.
2: While in Low-Voltage ICSP mode, the RB3 pin can no longer be used as a general purpose I/O pin.
3: When using Low-Voltage ICSP Programming (LVP) and the pull-ups on PORTB are 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.
4: RB3 should not be allowed to float if LVP is enabled. An external pull-down device should be used to default the device to normal operating mode. If RB3 floats high, the PIC16F87XA device will enter Programming mode.
5: LVP mode is enabled by default on all devices shipped from Microchip. It can be disabled by clearing the LVP bit in the CONFIG register.
6: Disabling LVP will provide maximum compatibility to other PIC16CXXX devices.
If Low-Voltage Programming mode is not used, the LVP bit can be programmed to a '0' and RB3/PGM becomes a digital I/O pin. However, the LVP bit may only be programmed when programming is entered with VIH H on MCLR. The LVP bit can only be charged when using high voltage on MCLR.
It should be noted, that once the LVP bit is programmed to '0', only the High-Voltage Programming mode is available and only High-Voltage Programming mode can be used to program the device.
When using low-voltage ICSP, the part must be supplied at 4.5V to 5.5V if a bulk erase will be executed. This includes reprogramming of the code-protect bits from an on state to an off state. For all other cases of low-voltage ICSP, the part may be programmed at the normal operating voltage. This means calibration values, unique user IDs or user code can be reprogrammed or added.