PIC18F87K22 FAMILY
64/80-Pin, High-Performance, 1-Mbit Enhanced Flash MCUs
with 12-Bit A/D and XLP Technology
Low-Power Features:
• Power-Managed modes:
- Run: CPU on, peripherals on
- Idle: CPU off, peripherals on
- Sleep: CPU off, peripherals off
• Two-Speed Oscillator Start-up
• Fail-Safe Clock Monitor
• Power-Saving Peripheral Module Disable (PMD)
• Ultra Low-Power Wake-up
• Fast Wake-up, 1
s
Typical
• Low-Power WDT, 300 nA Typical
• Ultra Low 50 nA Input Leakage
• Run mode Currents Down to 5.5
A,
Typical
• Idle mode Currents Down to 1.7
A
Typical
• Sleep mode Currents Down to Very Low 20 nA,
Typical
• RTCC Current Downs to Very Low 700 nA,
Typical
Special Microcontroller Features:
•
•
•
•
•
•
•
•
•
•
Operating Voltage Range: 1.8V to 5.5V
On-Chip 3.3V Regulator
Operating Speed up to 64 MHz
Up to 128 Kbytes On-Chip Flash Program
Memory
Data EEPROM of 1,024 Bytes
4K x 8 General Purpose Registers (SRAM)
10,000 Erase/Write Cycle Flash Program
Memory, Minimum
1,000,000 Erase/write Cycle Data EEPROM
Memory, Typical
Flash Retention: 40 Years, Minimum
Three Internal Oscillators: LF-INTRC (31 kHz),
MF-INTOSC (500 kHz) and HF-INTOSC
(16 MHz)
Self-Programmable under Software Control
Priority Levels for Interrupts
8 x 8 Single-Cycle Hardware Multiplier
Extended Watchdog Timer (WDT):
- Programmable period from 4 ms to 4,194s
(about 70 minutes)
In-Circuit Serial Programming™ (ICSP™) via
Two Pins
In-Circuit Debug via Two Pins
Programmable:
- BOR
- LVD
•
•
•
•
•
•
•
Comparators
Device
Flash # Single-Word SRAM EEPROM
(bytes) Instructions (bytes) (bytes)
32K
64K
128K
32K
64K
128K
16,383
32,768
65,536
16,383
32,768
65,536
2K
4K
4K
2K
4K
4K
1K
1K
1K
1K
1K
1K
I/O
12-Bit CCP/
A/D ECCP
(ch) (PWM)
16
16
16
24
24
24
5/3
7/3
7/3
5/3
7/3
7/3
2
2
2
2
2
2
EUSART
Timers
8/16-Bit
Program Memory
Data Memory
MSSP
SPI
Y
Y
Y
Y
Y
Y
Master
I
2
C
Y
Y
Y
Y
Y
Y
External Bus
CTMU
Y
Y
Y
Y
Y
Y
PIC18F65K22
PIC18F66K22
PIC18F67K22
PIC18F85K22
PIC18F86K22
PIC18F87K22
53
53
53
69
69
69
2
2
2
2
2
2
3
3
3
3
3
3
4/4
6/5
6/5
4/4
6/5
6/5
N
N
N
Y
Y
Y
2009-2018 Microchip Technology Inc.
DS30009960E-page 1
RTCC
Y
Y
Y
Y
Y
Y
PIC18F87K22 FAMILY
Peripheral Highlights:
• Up to Ten CCP/ECCP modules:
- Up to seven Capture/Compare/PWM (CCP)
modules
- Three Enhanced Capture/Compare/PWM
(ECCP) modules
• Up to Eleven 8/16-Bit Timer/Counter modules:
- Timer0 – 8/16-bit timer/counter with 8-bit
programmable prescaler
- Timer1,3 – 16-bit timer/counter
- Timer2,4,6,8 – 8-bit timer/counter
- Timer5,7 – 16-bit timer/counter for 64k and
128k parts
- Timer10,12 – 8-bit timer/counter for 64k and
128k parts
• Three Analog Comparators
• Configurable Reference Clock Output
• Hardware Real-Time Clock and Calendar (RTCC)
module with Clock, Calendar and Alarm Functions
• Charge Time Measurement Unit (CTMU):
- Capacitance measurement for mTouch
®
sensing solution
- Time measurement with 1 ns typical
resolution
- Integrated temperature sensor
• High-Current Sink/Source 25 mA/25 mA
(PORTB and PORTC)
• Up to Four External Interrupts
• Two Master Synchronous Serial Port (MSSP)
modules:
- 3/4-wire SPI (supports all four SPI modes)
- I
2
C Master and Slave modes
• Two Enhanced Addressable USART modules:
- LIN/J2602 support
- Auto-Baud Detect (ABD)
• 12-Bit A/D Converter with up to 24 Channels:
- Auto-acquisition and Sleep operation
- Differential input mode of operation
• Integrated Voltage Reference
DS30009960E-page 2
2009-2018 Microchip Technology Inc.
PIC18F87K22 FAMILY
Pin Diagrams – PIC18F6XK22
64-Pin TQFP, QFN
RE3/P3C/CCP9
(2)
/REF0
RD0/PSP0/CTPLS
RE7/ECCP2/P2A
RE5/P1C/CCP7
RE4/P3B/CCP8
RE6/P1B/CCP6
RD6/PSP6/SCK2/SCL2
RE2/CS/P2B/CCP10
(2)
RD5/PSP5/SDI2/SDA2
RD1/PSP1/T5CKI/T7G
RD4/PSP4/SDO2
V
DD
64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49
RE1/WR/P2C
RE0/RD/P2D
RG0/ECCP3/P3A
RG1/TX2/CK2/AN19/C3OUT
RG2/RX2/DT2/AN18/C3INA
RG3/CCP4/AN17/P3D/C3INB
MCLR/RG5
RG4/RTCC/T7CKI
(2)
/T5G/CCP5/AN16/P1D/C3INC
V
SS
V
DDCORE
/V
CAP
RF7/AN5/SS1
RF6/AN11/C1INA
RF5/AN10/CV
REF
/C1INB
RF4/AN9/C2INA
RF3/AN8/C2INB/CTMUI
RF2/AN7/C1OUT
RD7/PSP7/SS2
RD2/PSP2
RD3/PSP3
V
SS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
RB0/INT0/FLT0
RB1/INT1
RB2/INT2/CTED1
RB3/INT3/CTED2/ECCP2
(1)
/PA2
RB4/KBI0
RB5/KBI1/T3CKI/T1G
RB6/KBI2/PGC
V
SS
OSC2/CLKO/RA6
OSC1/CLKI/RA7
V
DD
RB7/KBI3/PGD
RC5/SDO1
RC4/SDI1/SDA1
RC3/SCK1/SCL1
RC2/ECCP1/P1A
PIC18F65K22
PIC18F66K22
PIC18F67K22
AV
DD
RA3/AN3/V
REF
+
V
DD
RA5/AN4/T1CKI/T3G/HLVDIN
RA4/T0CKI
RC1/SOSCI/ECCP2
(1)
/P2A
RF1/AN6/C2OUT/CTDIN
RA1/AN1
RC0/SOSCO/SCLKI
RA2/AN2/V
REF
-
RC6/TX1/CK1
ENVREG
RA0/AN0/ULPWU
Note 1:
2:
The ECCP2 pin placement depends on the CCP2MX Configuration bit setting and whether the device is
in Microcontroller or Extended Microcontroller mode.
Not available on the PIC18F65K22 and PIC18F85K22 devices.
2009-2018 Microchip Technology Inc.
RC7/RX1/DT1
AV
SS
V
SS
DS30009960E-page 3
PIC18F87K22 FAMILY
Pin Diagrams – PIC18F8XK22
80-Pin TQFP
RH2/AN21/A18
RH3/AN20/A19
RE1/P2C/WR/AD9
RE0/P2D/RD/AD8
RG0/ECCP3/P3A
RG1/TX2/CK2/AN19/C3OUT
RG2/RX2/DT2/AN18/C3INA
RG3/CCP4/AN17/P3D/C3INB
MCLR/RG5
RG4/RTCC/T7CKI
(2)
/T5G/CCP5/AN16/P1D/C3INC
V
SS
V
DDCORE
/V
CAP
RF7/AN5/SS1
RF6/AN11/C1INA
RF5/AN10/C1INB
RF4/AN9/C2INA
RF3/AN8/C2INB/CTMUI
RF2/AN7/C1OUT
RH7/CCP6
(3)
/P1B/AN15
RH6/CCP7
(3)
/P1C/AN14/C1INC
RH1/AN22/A17
RH0/AN23/A16
RE2/P2B/CCP10
(2)
/CS/AD10
RE3/P3C/CCP9
(2,3)/
REF0/AD11
RE4/P3B/CCP8
(3)
/AD12
RE5/P1C/CCP7
(3)
/AD13
RE6/P1B/CCP6
(3)
/AD14
RE7/ECCP2/P2A/AD15
RD0/PSP0/CTPLS/AD0
V
DD
V
SS
RD1/T5CKI/T7G/PSP1/AD1
RD2/PSP2/AD2
RD3/PSP3/AD3
RD4/SDO2/PSP4/AD4
RD5/SDI2/SDA2/PSP5/AD5
RD6/SCK2/SCL2/PSP6/AD6
RD7/SS2/PSP7/AD7
RJ0/ALE
RJ1/OE
80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
60
59
58
57
56
55
54
53
52
51
50
49
48
47
46
45
44
43
42
41
PIC18F85K22
PIC18F86K22
PIC18F87K22
RJ2/WRL
RJ3/WRH
RB0/INT0/FLT0
RB1/INT1
RB2/INT2/CTED1
RB3/INT3/CTED2/ECCP2
(1)
/P2A
RB4/KBI0
RB5/KBI1/T3CKI/T1G
RB6/KBI2/PGC
V
SS
OSC2/CLKO/RA6
OSC1/CLKI/RA7
V
DD
RB7/KBI3/PGD
RC5/SDO1
RC4/SDI1/SDA1
RC3/SCK1/SCL1
RC2/ECCP1/P1A
RJ7/UB
RJ6/LB
Note 1:
2:
3:
The ECCP2 pin placement depends on the CCP2MX Configuration bit setting and whether the device is
in Microcontroller or Extended Microcontroller mode.
Not available on the PIC18F65K22 and PIC18F85K22 devices.
The CC6, CCP7, CCP8 and CCP9 pin placement depends on the setting of the ECCPMX Configuration
bit (CONFIG3H<1>).
DS30009960E-page 4
RH5/CCP8
(3)
/P3B/AN13/C2IND
RH4/CCP9
(2,3)
/P3C/AN12/C2INC
RF1/AN6/C2OUT/CTDIN
ENVREG
AV
DD
AV
SS
RA3/AN3/V
REF
+
RA2/AN2/V
REF
-
RA1/AN1
RA0/AN0/ULPWU
V
SS
V
DD
RA5/AN4/T1CKI/T3G/HLVDIN
RA4/T0CKI
RC1/SOSC/ECCP2/P2A
RC0/SOSCO/SCKLI
RC6/TX1/CK1
RC7/RX1/DT1
RJ4/BA0
RJ5/CE
2009-2018 Microchip Technology Inc.
PIC18F87K22 FAMILY
Table of Contents
1.0 Device Overview .......................................................................................................................................................................... 7
2.0 Guidelines for Getting Started with PIC18FXXKXX Microcontrollers ......................................................................................... 35
3.0 Oscillator Configurations ............................................................................................................................................................ 40
4.0 Power-Managed Modes ............................................................................................................................................................. 53
5.0 Reset .......................................................................................................................................................................................... 68
6.0 Memory Organization ................................................................................................................................................................. 82
7.0 Flash Program Memory............................................................................................................................................................ 106
8.0 External Memory Bus ............................................................................................................................................................... 116
9.0 Data EEPROM Memory ........................................................................................................................................................... 127
10.0 8 x 8 Hardware Multiplier.......................................................................................................................................................... 133
11.0 Interrupts .................................................................................................................................................................................. 135
12.0 I/O Ports ................................................................................................................................................................................... 159
13.0 Timer0 Module ......................................................................................................................................................................... 186
14.0 Timer1 Module ......................................................................................................................................................................... 189
15.0 Timer2 Module ......................................................................................................................................................................... 201
16.0 Timer3/5/7 Modules.................................................................................................................................................................. 203
17.0 Timer4/6/8/10/12 Modules........................................................................................................................................................ 215
18.0 Real-Time Clock and Calendar (RTCC)................................................................................................................................... 218
19.0 Capture/Compare/PWM (CCP) Modules ................................................................................................................................. 235
20.0 Enhanced Capture/Compare/PWM (ECCP) Module................................................................................................................ 248
21.0 Master Synchronous Serial Port (MSSP) Module .................................................................................................................... 271
22.0 Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART) ............................................................... 317
23.0 12-Bit Analog-to-Digital Converter (A/D) Module ..................................................................................................................... 341
24.0 Comparator Module.................................................................................................................................................................. 357
25.0 Comparator Voltage Reference Module................................................................................................................................... 365
26.0 High/Low-Voltage Detect (HLVD)............................................................................................................................................. 368
27.0 Charge Time Measurement Unit (CTMU) ................................................................................................................................ 374
28.0 Special Features of the CPU.................................................................................................................................................... 391
29.0 Instruction Set Summary .......................................................................................................................................................... 418
30.0 Development Support............................................................................................................................................................... 468
31.0 Electrical Characteristics .......................................................................................................................................................... 472
32.0 Packaging Information.............................................................................................................................................................. 512
Appendix A: Revision History............................................................................................................................................................. 520
Appendix B: Migration From PIC18F87J11 and PIC18F8722 to PIC18F87K22................................................................................ 521
The Microchip Web Site ..................................................................................................................................................................... 522
Customer Change Notification Service .............................................................................................................................................. 522
Customer Support .............................................................................................................................................................................. 522
Product Identification System ............................................................................................................................................................ 523
2009-2018 Microchip Technology Inc.
DS30009960E-page 5