Professional Documents
Culture Documents
26K20/43K20/44K20/45K20/
46K20
Data Sheet
28/40/44-Pin
Flash Microcontrollers
with 10-Bit A/D and nanoWatt Technology
Preliminary
DS41303C
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 Microchips 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 Microchips 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.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, KEELOQ, KEELOQ logo, microID, MPLAB, PIC,
PICmicro, PICSTART, PRO MATE, rfPIC and SmartShunt are
registered trademarks of Microchip Technology Incorporated
in the U.S.A. and other countries.
AmpLab, FilterLab, Linear Active Thermistor, Migratable
Memory, MXDEV, MXLAB, 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, CodeGuard,
dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN,
ECONOMONITOR, FanSense, FlexROM, fuzzyLAB,
In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi,
MPASM, MPLAB Certified logo, MPLIB, MPLINK, PICkit,
PICDEM, PICDEM.net, PICLAB, PICtail, PowerCal,
PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB, Select
Mode, Smart Serial, SmartTel, Total Endurance, UNI/O,
WiperLock and ZENA 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.
2007, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
Printed on recycled paper.
DS41303C-page ii
Preliminary
PIC18F2XK20/4XK20
28/40/44-Pin Flash Microcontrollers with
10-Bit A/D and nanoWatt Technology
Power-Managed Modes:
Peripheral Highlights:
Preliminary
DS41303C-page 1
PIC18F2XK20/4XK20
Program Memory
Device
Data Memory
(1)
Flash # Single-Word SRAM EEPROM I/O
(bytes) Instructions (bytes) (bytes)
10-bit
A/D
(ch)(2)
CCP/
ECCP
(PWM)
MSSP
SPI
Master
I2C
EUSART
Comp.
Timers
8/16-bit
PIC18F23K20
8K
4096
512
256
25
11
1/1
1/3
PIC18F24K20
16K
8192
768
256
25
11
1/1
1/3
PIC18F25K20
32K
16384
1536
256
25
11
1/1
1/3
PIC18F26K20
64k
32768
3936
1024
25
11
1/1
1/3
PIC18F43K20
8K
4096
512
256
36
14
1/1
1/3
PIC18F44K20
16K
8192
768
256
36
14
1/1
1/3
PIC18F45K20
32K
16384
1536
256
36
14
PIC18F46K20
64k
32768
3936
1024
36
14
Note 1: One pin is input only.
2: Channel count includes internal fixed voltage reference channel.
DS41303C-page 2
Preliminary
1/1
1/3
1/1
1/3
PIC18F2XK20/4XK20
Pin Diagrams
28-pin PDIP, SOIC, SSOP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
RA1/AN1/C12IN1RA0/AN0/C12IN0-
MCLR/VPP/RE3
RA0/AN0/C12IN0RA1/AN1/C12IN1RA2/AN2/VREF-/CVREF/C2IN+
RA3/AN3/VREF+/C1IN+
RA4/T0CKI/C1OUT
RA5/AN4/SS/HLVDIN/C2OUT
RE0/RD/AN5
RE1/WR/AN6
RE2/CS/AN7
VDD
VSS
OSC1/CLKIN/RA7
OSC2/CLKOUT/RA6
RC0/T1OSO/T13CKI
RC1/T1OSI/CCP2(1)
RC2/CCP1/P1A
RC3/SCK/SCL
RD0/PSP0
RD1/PSP1
PIC18F43K20
PIC18F44K20
PIC18F45K20
PIC18F46K20
40-pin PDIP
28-pin QFN
28
27
26
25
24
23
22
21
20
19
18
17
16
15
PIC18F23K20
PIC18F24K20
PIC18F25K20
PIC18F26K20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
RB7/KBI3/PGD
RB6//KBI2/PGC
RB5/KBI1/PGM
RB4/KBI0/AN11/P1D
RB3/AN9/C12IN2-/CCP2(1)
RB2/INT2/AN8/P1B
RB1/INT1/AN10/C12IN3-/P1C
RB0/INT0/FLT0/AN12
VDD
VSS
RC7/RX/DT
RC6/TX/CK
RC5/SDO
RC4/SDI/SDA
RB7/KBI3/PGD
RB6/KBI2/PGC
RB5/KBI1/PGM
RB4/KBI0/AN11
RB3/AN9/C12IN2-/CCP2(1)
RB2/INT2/AN8
RB1/INT1/AN10/C12IN3RB0/INT0/FLT0/AN12
VDD
VSS
RD7/PSP7/P1D
RD6/PSP6/P1C
RD5/PSP5/P1B
RD4/PSP4
RC7/RX/DT
RC6/TX/CK
RC5/SDO
RC4/SDI/SDA
RD3/PSP3
RD2/PSP2
MCLR/VPP/RE3
RB7/KBI3/PGD
RB6/KBI2/PGC
RB5/KBI1/PGM
RB4/KBI0/AN11/P1D
MCLR/VPP/RE3
RA0/AN0/C12IN0RA1/AN1/C12IN1RA2/AN2/VREF-/CVREF/C2IN+
RA3/AN3/VREF+/C1IN+
RA4/T0CKI/C1OUT
RA5/AN4/SS/HLVDIN/C2OUT
VSS
OSC1/CLKIN/RA7
OSC2/CLKOUT/RA6
RC0/T1OSO/T13CKI
RC1/T1OSI/CCP2(1)
RC2/CCP1/P1A
RC3/SCK/SCL
28 27 26 25 24 23 22
Note
1:
1
2
3
4
5
6
7
PIC18F23K20
PIC18F24K20
PIC18F25K20
PIC18F26K20
8 9 10 11 12 13 14
21
20
19
18
17
16
15
RB3/AN9/C12IN2-/CCP2(1)
RB2/INT2/AN8/P1B
RB1/INT1/AN10/C12IN3-/P1C
RB0/INT0/FLT0/AN12
VDD
VSS
RC7/RX/DT
RC0/T1OSO/T13CKI
RC1/T1OSI/CCP2(1)
RC2/CCP1/P1A
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RA2/AN2/VREF-/CVREF/C2IN+
RA3/AN3/VREF+/C1IN+
RA4/T0CKI/C1OUT
RA5/AN4/SS/HLVDIN/C2OUT
VSS
OSC1/CLKIN/RA7
OSC2/CLKOUT/RA6
Preliminary
DS41303C-page 3
PIC18F2XK20/4XK20
44
43
42
41
40
39
38
37
36
35
34
44-pin TQFP
RC6/TX/CK
RC5/SDO
RC4/SDI/SDA
RD3/PSP3
RD2/PSP2
RD1/PSP1
RD0/PSP0
RC3/SCK/SCL
RC2/CCP1/P1A
RC1/T1OSI/CCP2(1)
NC
Note
1:
12
13
14
15
16
17
18
19
20
21
22
NC
NC
RC6/TX/CK
RB4/KBI0/AN11
RC5/SDO
RB5/KBI1/PGM
RC4/SDI/SDA
RB6/KBI2/PGC
RD3/PSP3
RB7/KBI3/PGD
RD2/PSP2
MCLR/VPP/RE3
RD1/PSP1
RA0/AN0/C12IN0RD0/PSP0
RA1/AN1/C12IN1RC3/SCK/SCL
RA2/AN2/VREF-/CVREF/C2IN+
RC2/CCP1/P1A
RA3/AN3/VREF+/C1IN+
RC1/T1OSI/CCP2(1)
RC0/T1OSO/T13CKI
44
43
42
41
40
39
38
37
36
35
34
RC7/RX/DT
RD4/PSP4
RD5/PSP5/P1B
RD6/PSP6/P1C
RD7/PSP7/P1D
VSS
VDD
VDD
RB0/INT0/FLT0/AN12
RB1/INT1/AN10/C12IN3RB2/INT2/AN8
PIC18F43K20
PIC18F44K20
PIC18F45K20
PIC18F46K20
1
2
3
4
5
6
7
8
9
10
11
DS41303C-page 4
NC
RC0/T1OSO/T13CKI
OSC2/CLKOUT/RA6
OSC1/CLKIN/RA7
VSS
VDD
RE2/CS/AN7
RE1/WR/AN6
RE0/RD/AN5
RA5/AN4/SS/HLVDIN/C2OUT
RA4/T0CKI/C1OUT
33
32
31
30
29
28
27
26
25
24
23
PIC18F43K20
PIC18F44K20
PIC18F45K20
PIC18F46K20
33
32
31
30
29
28
27
26
25
24
23
12
13
14
15
16
17
18
19
20
21
22
44-pin QFN
1
2
3
4
5
6
7
8
9
10
11
OSC2/CLKOUT/RA6
OSC1/CLKIN/RA7
VSS
VSS
VDD
VDD
RE2/CS/AN7
RE1/WR/AN6
RE0/RD/AN5
RA5/AN4/SS/HLVDIN/C2OUT
RA4/T0CKI/C1OUT
RB3/AN9/C12IN2-/CCP2(1)
NC
RB4/KBI0/AN11
RB5/KBI1/PGM
RB6/KBI2/PGC
RB7/KBI3/PGD
MCLR/VPP/RE3
RA0/AN0/C12IN0RA1/AN1/C12IN1RA2/AN2/VREF-/CVREF/C2IN+
RA3/AN3/VREF+/C1IN+
RC7/RX/DT
RD4/PSP4
RD5/PSP5/P1B
RD6/PSP6/P1C
RD7/PSP7/P1D
VSS
VDD
RB0/INT0/FLT0/AN12
RB1/INT1/AN10/C12IN3RB2/INT2/AN8
RB3/AN9/C12IN2-/CCP2(1)
Preliminary
PIC18F2XK20/4XK20
RA2
AN2
C2IN+
VREF-/
CVREF
22
22
RA3
AN3
23
23
RA4
C1IN+
VREF+
C1OUT
DIL Pin
Basic
21
Pull-up
21
Interrupts
Slave
Timers
C12IN1-
MSSP
C12IN0-
AN1
EUSART
AN0
RA1
ECCP
RA0
20
Analog
19
20
I/O
19
QFN Pin
TQFP Pin
Reference
TABLE 1:
T0CKI
T1OSI
24
24
RA5
AN4
C2OUT
HLVDIN
14
31
33
RA6
13
30
32
RA7
33
RB0
AN12
34
10
RB1
AN10
C12IN3-
35
10
11
RB2
AN8
36
11
12
RB3
AN9
C12IN2-
37
14
14
RB4
AN11
38
15
15
RB5
39
16
16
RB6
40
17
17
RB7
15
32
34
RC0
16
35
35
RC1
36
36
RC2
CCP2(2)
17
18
37
37
RC3
SCK/
SCL
23
42
42
RC4
24
43
43
RC5
25
44
44
RC6
26
RC7
19
38
38
RD0
20
39
39
RD1
21
40
40
RD2
22
41
41
RD3
27
RD4
28
RD5
29
RD6
30
RD7
25
25
RE0
AN5
26
26
RE1
AN6
10
27
27
RE2
AN7
18
18
RE3(3)
11
32
28
28
12
31
29
30
NC
NC
29
NC
31
Note 1:
2:
3:
FLT0
CCP2(1)
CCP1/
P1A
P1B
P1C
P1D
SS
OSC2/
CLKOUT
OSC1/CLKIN
INT0
Yes
INT1
Yes
INT2
Yes
Yes
KBI0
Yes
KBI1
Yes
PGM
KBI2
Yes
PGC
KBI3
Yes
PGD
SDI/
SDA
SDO
TX/CK
RX/DT
T1OSO/
T13CKI
PSP0
PSP1
PSP2
PSP3
PSP4
PSP5
PSP6
PSP7
RD
WR
CS
MCLR/VPP
VDD
VDD
VSS
VSS
VDD
VDD
VSS
Preliminary
DS41303C-page 5
PIC18F2XK20/4XK20
AN2
C2IN+
VREF-/
CVREF
AN3
C1IN+
VREF+
Basic
RA2
Pull-up
Interrupts
C12IN1-
Slave
C12IN0-
AN1
Timers
AN0
RA1
MSSP
Comparator
RA0
28
EUSART
Analog
27
ECCP
I/O
Reference
Pin QUAD
Pin DIL
TABLE 2:
RA3
RA4
RA5
10
RA6
OSC2/
CLKOUT
RA7
OSC1/
CLKIN
C1OUT
AN4
21
18
RB0
AN12
22
19
RB1
AN10
23
20
RB2
AN8
24
21
RB3
AN9
25
22
RB4
AN11
C2OUT
C12IN3C12IN2-
T0CKI
HLVDIN
SS
FLT0
INT0
P1C
INT1
Yes
P1B
INT2
Yes
KBI0
Yes
CCP2(1)
Yes
Yes
P1D
26
23
RB5
KBI1
Yes
PGM
27
24
RB6
KBI2
Yes
PGC
28
25
RB7
KBI3
Yes
PGD
11
RC0
T1OSO/
T13CKI
12
RC1
CCP2(2)
13
10
RC2
CCP1/
P1A
14
11
RC3
SCK/
SCL
15
12
RC4
SDI/
SDA
T1OSI
16
13
RC5
17
14
RC6
TX/CK
RX/DT
18
15
RC7
26
RE3(3)
SDO
MCLR/
VPP
VSS
19
16
VSS
20
17
VDD
Note 1:
2:
3:
DS41303C-page 6
Preliminary
PIC18F2XK20/4XK20
Table of Contents
1.0 Device Overview ......................................................................................................................................................................... 9
2.0 Oscillator Module (With Fail-Safe Clock Monitor)...................................................................................................................... 25
3.0 Power-Managed Modes ............................................................................................................................................................ 41
4.0 Reset ......................................................................................................................................................................................... 49
5.0 Memory Organization ................................................................................................................................................................ 63
6.0 Flash Program Memory............................................................................................................................................................. 87
7.0 Data EEPROM Memory ............................................................................................................................................................ 97
8.0 8 x 8 Hardware Multiplier......................................................................................................................................................... 103
9.0 Interrupts ................................................................................................................................................................................. 105
10.0 I/O Ports .................................................................................................................................................................................. 119
11.0 Capture/Compare/PWM (CCP) Modules ................................................................................................................................ 139
12.0 Timer0 Module ........................................................................................................................................................................ 151
13.0 Timer1 Module ........................................................................................................................................................................ 155
14.0 Timer2 Module ........................................................................................................................................................................ 163
15.0 Timer3 Module ........................................................................................................................................................................ 165
16.0 Enhanced Capture/Compare/PWM (ECCP) Module............................................................................................................... 169
17.0 Master Synchronous Serial Port (MSSP) Module ................................................................................................................... 189
18.0 Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART) .............................................................. 231
19.0 Analog-to-Digital Converter (ADC) Module ............................................................................................................................. 259
20.0 Comparator Module................................................................................................................................................................. 273
21.0 VOLTAGE REFERENCES ............................................................................................................................................................. 283
22.0 High/Low-Voltage Detect (HLVD)............................................................................................................................................ 287
23.0 Special Features of the CPU................................................................................................................................................... 293
24.0 Instruction Set Summary ......................................................................................................................................................... 309
25.0 Development Support.............................................................................................................................................................. 359
26.0 Electrical Characteristics ......................................................................................................................................................... 363
27.0 DC and AC Characteristics Graphs and Tables...................................................................................................................... 397
28.0 Packaging Information............................................................................................................................................................. 399
Appendix A: Revision History............................................................................................................................................................ 409
Appendix B: Device Differences ....................................................................................................................................................... 409
The Microchip Web Site .................................................................................................................................................................... 421
Customer Change Notification Service ............................................................................................................................................. 421
Customer Support ............................................................................................................................................................................. 421
Reader Response ............................................................................................................................................................................. 422
Product Identification System ........................................................................................................................................................... 423
Preliminary
DS41303C-page 7
PIC18F2XK20/4XK20
TO OUR VALUED CUSTOMERS
It is our intention to provide our valued customers with the best documentation possible to ensure successful use of your Microchip
products. To this end, we will continue to improve our publications to better suit your needs. Our publications will be refined and
enhanced as new volumes and updates are introduced.
If you have any questions or comments regarding this publication, please contact the Marketing Communications Department via
E-mail at docerrors@mail.microchip.com or fax the Reader Response Form in the back of this data sheet to (480) 792-4150.
We welcome your feedback.
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:
Microchips 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.
DS41303C-page 8
Preliminary
PIC18F2XK20/4XK20
1.0
DEVICE OVERVIEW
1.1.2
PIC18F43K20
PIC18F24K20
PIC18F44K20
PIC18F25K20
PIC18F45K20
PIC18F26K20
PIC18F46K20
1.1
1.1.1
Preliminary
DS41303C-page 9
PIC18F2XK20/4XK20
1.2
1.3
DS41303C-page 10
Devices in the PIC18F2XK20/4XK20 family are available in 28-pin and 40/44-pin packages. Block diagrams
for the two groups are shown in Figure 1-1 and
Figure 1-2.
The devices are differentiated from each other in five
ways:
1.
2.
3.
4.
Preliminary
Preliminary
Yes
Note
1:
Packages
1 internal plus
10 Input
Channels
No
MSSP,
Enhanced
USART
A, B, C, (E)(1)
19
256
1 internal plus
10 Input
Channels
No
MSSP,
Enhanced
USART
A, B, C, (E)(1)
19
1024
3936
1 internal plus
13 Input
Channels
Yes
MSSP,
Enhanced
USART
A, B, C, D, E
20
256
512
4096
8192
DC 64 MHz
PIC18F43K20
1 internal plus
13 Input
Channels
Yes
MSSP,
Enhanced
USART
A, B, C, D, E
20
256
768
8192
16384
DC 64 MHz
PIC18F44K20
1 internal plus
13 Input
Channels
Yes
MSSP,
Enhanced
USART
A, B, C, D, E
20
256
1536
16384
32768
DC 64 MHz
PIC18F45K20
1 internal plus
13 Input
Channels
Yes
MSSP,
Enhanced
USART
A, B, C, D, E
20
1024
3936
32768
65536
DC 64 MHz
PIC18F46K20
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
28-pin PDIP
28-pin SOIC
28-pin QFN
28-pin SSOP
28-pin PDIP
28-pin SOIC
28-pin QFN
28-pin SSOP
28-pin PDIP
28-pin SOIC
28-pin QFN
28-pin SSOP
40-pin PDIP
44-pin QFN
44-pin TQFP
PORTE contains the single RE3 read-only bit. The LATE and TRISE registers are not implemented.
28-pin PDIP
28-pin SOIC
28-pin QFN
28-pin SSOP
40-pin PDIP
44-pin QFN
44-pin TQFP
40-pin PDIP
44-pin QFN
44-pin TQFP
40-pin PDIP
44-pin QFN
44-pin TQFP
Yes
Programmable
High/Low-Voltage Detect
Instruction Set
1 internal plus
10 Input
Channels
No
MSSP,
Enhanced
USART
256
1536
32768
65536
DC 64 MHz
PIC18F26K20
POR, BOR,
POR, BOR,
POR, BOR,
POR, BOR,
POR, BOR,
POR, BOR,
POR, BOR,
POR, BOR,
RESET
RESET
RESET
RESET
RESET
RESET
RESET
RESET
Instruction,
Instruction,
Instruction,
Instruction,
Instruction,
Instruction,
Instruction,
Instruction,
Stack Full, Stack Stack Full, Stack Stack Full, Stack Stack Full, Stack Stack Full, Stack Stack Full, Stack Stack Full, Stack Stack Full, Stack
Underflow
Underflow
Underflow
Underflow
Underflow
Underflow
Underflow
Underflow
(PWRT, OST),
(PWRT, OST),
(PWRT, OST),
(PWRT, OST),
(PWRT, OST),
(PWRT, OST),
(PWRT, OST),
(PWRT, OST),
MCLR (optional), MCLR (optional), MCLR (optional), MCLR (optional), MCLR (optional), MCLR (optional), MCLR (optional), MCLR (optional),
WDT
WDT
WDT
WDT
WDT
WDT
WDT
WDT
No
1 internal plus
10 Input
Channels
MSSP,
Enhanced
USART
Enhanced
Capture/Compare/PWM Modules
Serial Communications
A, B, C, (E)(1)
I/O Ports
1
19
Interrupt Sources
Capture/Compare/PWM Modules
A, B, C, (E)(1)
256
768
16384
32768
DC 64 MHz
PIC18F25K20
TABLE 1-1:
Timers
19
512
8192
4096
Program Memory
(Instructions)
16384
DC 64 MHz
8192
DC 64 MHz
Operating Frequency
PIC18F24K20
PIC18F23K20
Features
PIC18F2XK20/4XK20
DEVICE FEATURES
DS41303C-page 11
PIC18F2XK20/4XK20
FIGURE 1-1:
Table Pointer<21>
Data Latch
inc/dec logic
PORTA
Data Memory
PCLATU PCLATH
21
Address Latch
20
12
Data Address<12>
31-Level Stack
4
BSR
Address Latch
Program Memory
(8/16/32/64 Kbytes)
STKPTR
12
FSR0
FSR1
FSR2
Data Latch
4
Access
Bank
12
PORTB
inc/dec
logic
Table Latch
Address
Decode
ROM Latch
RA0/AN0
RA1/AN1
RA2/AN2/VREF-/CVREF
RA3/AN3/VREF+
RA4/T0CKI/C1OUT
RA5/AN4/SS/HLVDIN/C2OUT
OSC2/CLKOUT(3)/RA6
OSC1/CLKIN(3)/RA7
RB0/INT0/FLT0/AN12
RB1/INT1/AN10/C12IN3RB2/INT2/AN8
RB3/AN9/CCP2(1)/C12IN2RB4/KBI0/AN11
RB5/KBI1/PGM
RB6/KBI2/PGC
RB7/KBI3/PGD
IR
Instruction
Decode and
Control
State machine
control signals
PRODH PRODL
PORTC
8 x 8 Multiply
8
W
BITOP
8
Internal
Oscillator
Block
OSC1(3)
OSC2
(3)
T1OSI
LFINTOSC
Oscillator
T1OSO
16 MHz
Oscillator
Single-Supply
Programming
In-Circuit
Debugger
MCLR(2)
VDD, VSS
BOR
HLVD
FVR
CVREF Comparator
Note
Power-up
Timer
Oscillator
Start-up Timer
Power-on
Reset
RC0/T1OSO/T13CKI
RC1/T1OSI/CCP2(1)
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
ALU<8>
8
Watchdog
Timer
Precision
Band Gap
Reference
Brown-out
Reset
Fail-Safe
Clock Monitor
FVR
PORTE
MCLR/VPP/RE3(2)
Data
EEPROM
Timer0
Timer1
Timer2
Timer3
ECCP1
CCP2
MSSP
EUSART
ADC
10-bit
FVR
1:
CCP2 is multiplexed with RC1 when Configuration bit CCP2MX is set, or RB3 when CCP2MX is not set.
2:
3:
OSC1/CLKIN and OSC2/CLKOUT are only available in select oscillator modes and when these pins are not being used as digital I/O.
Refer to Section 2.0 Oscillator Module (With Fail-Safe Clock Monitor) for additional information.
DS41303C-page 12
Preliminary
PIC18F2XK20/4XK20
FIGURE 1-2:
Table Pointer<21>
RA0/AN0
RA1/AN1
RA2/AN2/VREF-/CVREF
RA3/AN3/VREF+
RA4/T0CKI/C1OUT
RA5/AN4/SS/HLVDIN/C2OUT
OSC2/CLKOUT(3)/RA6
OSC1/CLKIN(3)/RA7
Data Latch
inc/dec logic
PORTA
Data Memory
PCLATU PCLATH
21
Address Latch
20
12
Data Address<12>
31-Level Stack
4
BSR
Address Latch
Program Memory
(8/16/32/64 Kbytes)
STKPTR
FSR0
FSR1
FSR2
12
inc/dec
logic
Table Latch
RB0/INT0/FLT0/AN12
RB1/INT1/AN10/C12IN3RB2/INT2/AN8
RB3/AN9/CCP2(1)/C12IN2RB4/KBI0/AN11
RB5/KBI1/PGM
RB6/KBI2/PGC
RB7/KBI3/PGD
4
Access
Bank
12
Data Latch
PORTB
PORTC
Address
Decode
ROM Latch
RC0/T1OSO/T13CKI
RC1/T1OSI/CCP2(1)
RC2/CCP1/P1A
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
IR
Instruction
Decode and
Control
State machine
control signals
PRODH PRODL
PORTD
8 x 8 Multiply
BITOP
8
Internal
Oscillator
Block
OSC1(3)
OSC2
(3)
T1OSI
LFINTOSC
Oscillator
T1OSO
16 MHz
Oscillator
Single-Supply
Programming
In-Circuit
Debugger
MCLR(2)
VDD, VSS
BOR
HLVD
Power-up
Timer
Oscillator
Start-up Timer
Power-on
Reset
ALU<8>
8
PORTE
Brown-out
Reset
Fail-Safe
Clock Monitor
Precision
Band Gap
Reference
FVR
Data
EEPROM
Timer0
Timer1
Timer2
Timer3
ECCP1
CCP2
MSSP
EUSART
ADC
10-bit
FVR
CVREF Comparator
Note
Watchdog
Timer
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RD4/PSP4
RD5/PSP5/P1B
RD6/PSP6/P1C
RD7/PSP7/P1D
FVR
RE0/RD/AN5
RE1/WR/AN6
RE2/CS/AN7
MCLR/VPP/RE3(2)
PSP
1:
CCP2 is multiplexed with RC1 when Configuration bit CCP2MX is set, or RB3 when CCP2MX is not set.
2:
3:
OSC1/CLKIN and OSC2/CLKOUT are only available in select oscillator modes and when these pins are not being used as digital I/O.
Refer to Section 2.0 Oscillator Module (With Fail-Safe Clock Monitor) for additional information.
Preliminary
DS41303C-page 13
PIC18F2XK20/4XK20
TABLE 1-2:
Pin Name
Pin Buffer
PDIP,
QFN Type Type
SOIC
MCLR/VPP/RE3
MCLR
VPP
RE3
OSC1/CLKIN/RA7
OSC1
26
I
P
I
6
ST
ST
ST
CLKOUT
RA6
I/O
TTL
RA7
OSC2/CLKOUT/RA6
OSC2
10
CLKIN
Description
Note 1: Default assignment for CCP2 when Configuration bit CCP2MX is set.
2: Alternate assignment for CCP2 when Configuration bit CCP2MX is cleared.
DS41303C-page 14
Preliminary
PIC18F2XK20/4XK20
TABLE 1-2:
Pin Name
Pin Number
Pin Buffer
PDIP,
QFN Type Type
SOIC
Description
PORTA is a bidirectional I/O port.
RA0/AN0/C12IN0RA0
AN0
C12IN0-
RA1/AN1/C12IN1RA1
AN1
C12IN1-
RA2/AN2/VREF-/CVREF/
C2IN+
RA2
AN2
VREFCVREF
C2IN+
RA3/AN3/VREF+/C1IN+
RA3
AN3
VREF+
C1IN+
RA4/T0CKI/C1OUT
RA4
T0CKI
C1OUT
RA5/AN4/SS/HLVDIN/
C2OUT
RA5
AN4
SS
HLVDIN
C2OUT
27
I/O
TTL
I Analog
I Analog
Digital I/O
Analog input 0, ADC channel 0
Comparators C1 and C2 inverting input
I/O
TTL
I Analog
I Analog
Digital I/O
ADC input 1, ADC channel 1
Comparators C1 and C2 inverting input
I/O
I
I
O
I
Digital I/O
Analog input 2, ADC channel 2
A/D reference voltage (low) input
Comparator reference voltage output
Comparator C2 non-inverting input
28
1
TTL
Analog
Analog
Analog
Analog
2
I/O
TTL
I Analog
I Analog
I Analog
Digital I/O
Analog input 3, ADC channel 3
A/D reference voltage (high) input
Comparator C1 non-inverting input
I/O
ST
I
ST
O CMOS
Digital I/O
Timer0 external clock input
Comparator C1 output
I/O
TTL
I Analog
I
TTL
I Analog
O CMOS
Digital I/O
Analog input 4, ADC channel 4
SPI slave select input
High/Low-Voltage Detect input
Comparator C2 output
RA6
RA7
Note 1: Default assignment for CCP2 when Configuration bit CCP2MX is set.
2: Alternate assignment for CCP2 when Configuration bit CCP2MX is cleared.
Preliminary
DS41303C-page 15
PIC18F2XK20/4XK20
TABLE 1-2:
Pin Name
Pin Number
Pin Buffer
PDIP,
QFN Type Type
SOIC
Description
PORTB is a bidirectional I/O port. PORTB can be software
programmed for internal weak pull-up on each input.
RB0/INT0/FLT0/AN12
RB0
INT0
FLT0
AN12
21
RB1/INT1/AN10/C12IN3/P1C
RB1
INT1
AN10
C12IN3P1C
22
RB2/INT2/AN8/P1B
RB2
INT2
AN8
P1B
23
RB3/AN9/C12IN2-/CCP2
RB3
AN9
C12IN2CCP2(2)
24
RB4/KBI0/AN11/P1D
RB4
KBI0
AN11
P1D
25
RB5/KBI1/PGM
RB5
KBI1
PGM
26
RB6/KBI2/PGC
RB6
KBI2
PGC
27
RB7/KBI3/PGD
RB7
KBI3
PGD
28
18
I/O
TTL
I
ST
I
ST
I Analog
Digital I/O
External interrupt 0
PWM Fault input for CCP1
Analog input 12, ADC channel 12
I/O
TTL
I
ST
I Analog
I Analog
O CMOS
Digital I/O
External interrupt 1
Analog input 10, ADC channel 10
Comparators C1 and C2 inverting input
Enhanced CCP1 PWM output
I/O
TTL
I
ST
I Analog
O CMOS
Digital I/O
External interrupt 2
Analog input 8, ADC channel 8
Enhanced CCP1 PWM output
I/O
TTL
I Analog
I Analog
I/O
ST
Digital I/O
Analog input 9, ADC channel 9
Comparators C1 and C2 inverting input
Capture 2 input/Compare 2 output/PWM 2 output
I/O
TTL
I
TTL
I Analog
O CMOS
Digital I/O
Interrupt-on-change pin
Analog input 11, ADC channel 11
Enhanced CCP1 PWM output
I/O
I
I/O
TTL
TTL
ST
Digital I/O
Interrupt-on-change pin
Low-Voltage ICSP Programming enable pin
I/O
I
I/O
TTL
TTL
ST
Digital I/O
Interrupt-on-change pin
In-Circuit Debugger and ICSP programming clock pin
I/O
I
I/O
TTL
TTL
ST
Digital I/O
Interrupt-on-change pin
In-Circuit Debugger and ICSP programming data pin
19
20
21
22
23
24
25
Note 1: Default assignment for CCP2 when Configuration bit CCP2MX is set.
2: Alternate assignment for CCP2 when Configuration bit CCP2MX is cleared.
DS41303C-page 16
Preliminary
PIC18F2XK20/4XK20
TABLE 1-2:
Pin Name
Pin Number
Pin Buffer
PDIP,
QFN Type Type
SOIC
Description
PORTC is a bidirectional I/O port.
RC0/T1OSO/T13CKI
RC0
T1OSO
T13CKI
11
RC1/T1OSI/CCP2
RC1
T1OSI
CCP2(1)
12
RC2/CCP1/P1A
RC2
CCP1
P1A
13
RC3/SCK/SCL
RC3
SCK
SCL
14
RC4/SDI/SDA
RC4
SDI
SDA
15
RC5/SDO
RC5
SDO
16
RC6/TX/CK
RC6
TX
CK
17
RC7/RX/DT
RC7
RX
DT
18
RE3
VSS
VDD
8
I/O
O
I
Digital I/O
Timer1 oscillator output
Timer1/Timer3 external clock input
9
I/O
ST
I Analog
I/O
ST
Digital I/O
Timer1 oscillator input
Capture 2 input/Compare 2 output/PWM 2 output
I/O
ST
I/O
ST
O CMOS
Digital I/O
Capture 1 input/Compare 1 output
Enhanced CCP1 PWM output
10
11
I/O
I/O
I/O
ST
ST
ST
Digital I/O
Synchronous serial clock input/output for SPI mode
Synchronous serial clock input/output for I2C mode
I/O
I
I/O
ST
ST
ST
Digital I/O
SPI data in
I2C data I/O
I/O
O
ST
Digital I/O
SPI data out
I/O
O
I/O
ST
ST
Digital I/O
EUSART asynchronous transmit
EUSART synchronous clock (see related RX/DT)
I/O
I
I/O
ST
ST
ST
Digital I/O
EUSART asynchronous receive
EUSART synchronous data (see related TX/CK)
12
13
14
15
8, 19 5, 16
20
ST
ST
17
Note 1: Default assignment for CCP2 when Configuration bit CCP2MX is set.
2: Alternate assignment for CCP2 when Configuration bit CCP2MX is cleared.
Preliminary
DS41303C-page 17
PIC18F2XK20/4XK20
TABLE 1-3:
Pin Name
Pin Number
PDIP
MCLR/VPP/RE3
MCLR
VPP
RE3
OSC1/CLKIN/RA7
OSC1
13
Pin Buffer
QFN TQFP Type Type
18
18
I
P
I
32
30
I
CLKIN
RA7
OSC2/CLKOUT/RA6
OSC2
I/O
14
33
ST
ST
Description
Master Clear (input) or programming voltage (input)
Active-low Master Clear (device Reset) input
Programming voltage input
Digital input
31
O
CLKOUT
RA6
I/O
TTL
Note 1: Default assignment for CCP2 when Configuration bit CCP2MX is set.
2: Alternate assignment for CCP2 when Configuration bit CCP2MX is cleared.
DS41303C-page 18
Preliminary
PIC18F2XK20/4XK20
TABLE 1-3:
Pin Name
Pin Number
PDIP
Pin Buffer
QFN TQFP Type Type
Description
PORTA is a bidirectional I/O port.
RA0/AN0/C12IN0RA0
AN0
C12IN0-
RA1/AN1/C12IN0RA1
AN1
C12IN0-
RA2/AN2/VREF-/CVREF/
C2IN+
RA2
AN2
VREFCVREF
C2IN+
RA3/AN3/VREF+/
C1IN+
RA3
AN3
VREF+
C1IN+
RA4/T0CKI/C1OUT
RA4
T0CKI
C1OUT
RA5/AN4/SS/HLVDIN/
C2OUT
RA5
AN4
SS
HLVDIN
C2OUT
19
20
21
22
23
24
19
I/O
I
I
TTL
Analog
Analog
Digital I/O
Analog input 0, ADC channel 0
Comparator C1 and C2 inverting input
I/O
I
I
TTL
Analog
Analog
Digital I/O
Analog input 1, ADC channel 1
Comparator C1 and C2 inverting input
I/O
I
I
O
I
TTL
Analog
Analog
Analog
Analog
Digital I/O
Analog input 2, ADC channel 2
A/D reference voltage (low) input
Comparator reference voltage output
Comparator C2 non-inverting input
I/O
I
I
I
TTL
Analog
Analog
Analog
Digital I/O
Analog input 3, ADC channel 3
A/D reference voltage (high) input
Comparator C1 non-inverting input
I/O
I
O
ST
ST
CMOS
Digital I/O
Timer0 external clock input
Comparator C1 output
I/O
I
I
I
O
TTL
Analog
TTL
Analog
CMOS
Digital I/O
Analog input 4, ADC channel 4
SPI slave select input
High/Low-Voltage Detect input
Comparator C2 output
20
21
22
23
24
RA6
RA7
Note 1: Default assignment for CCP2 when Configuration bit CCP2MX is set.
2: Alternate assignment for CCP2 when Configuration bit CCP2MX is cleared.
Preliminary
DS41303C-page 19
PIC18F2XK20/4XK20
TABLE 1-3:
Pin Name
Pin Number
PDIP
Pin Buffer
QFN TQFP Type Type
Description
PORTB is a bidirectional I/O port. PORTB can be
software programmed for internal weak pull-up on
each input.
RB0/INT0/FLT0/AN12
RB0
INT0
FLT0
AN12
33
RB1/INT1/AN10/
C12IN3RB1
INT1
AN10
C12IN3-
34
RB2/INT2/AN8
RB2
INT2
AN8
35
RB3/AN9/C12IN2-/
CCP2
RB3
AN9
C12IN23CCP2(2)
36
RB4/KBI0/AN11
RB4
KBI0
AN11
37
RB5/KBI1/PGM
RB5
KBI1
PGM
38
RB6/KBI2/PGC
RB6
KBI2
PGC
39
RB7/KBI3/PGD
RB7
KBI3
PGD
40
10
11
12
14
15
16
17
8
I/O
I
I
I
TTL
ST
ST
Analog
Digital I/O
External interrupt 0
PWM Fault input for Enhanced CCP1
Analog input 12, ADC channel 12
I/O
I
I
I
TTL
ST
Analog
Analog
Digital I/O
External interrupt 1
Analog input 10, ADC channel 10
Comparator C1 and C2 inverting input
I/O
I
I
TTL
ST
Analog
Digital I/O
External interrupt 2
Analog input 8, ADC channel 8
I/O
I
I
I/O
TTL
Analog
Analog
ST
Digital I/O
Analog input 9, ADC channel 9
Comparator C1 and C2 inverting input
Capture 2 input/Compare 2 output/PWM 2 output
I/O
I
I
TTL
TTL
Analog
Digital I/O
Interrupt-on-change pin
Analog input 11, ADC channel 11
I/O
I
I/O
TTL
TTL
ST
Digital I/O
Interrupt-on-change pin
Low-Voltage ICSP Programming enable pin
I/O
I
I/O
TTL
TTL
ST
Digital I/O
Interrupt-on-change pin
In-Circuit Debugger and ICSP programming
clock pin
I/O
I
I/O
TTL
TTL
ST
Digital I/O
Interrupt-on-change pin
In-Circuit Debugger and ICSP programming
data pin
10
11
14
15
16
17
Note 1: Default assignment for CCP2 when Configuration bit CCP2MX is set.
2: Alternate assignment for CCP2 when Configuration bit CCP2MX is cleared.
DS41303C-page 20
Preliminary
PIC18F2XK20/4XK20
TABLE 1-3:
Pin Name
Pin Number
PDIP
Pin Buffer
QFN TQFP Type Type
Description
PORTC is a bidirectional I/O port.
RC0/T1OSO/T13CKI
RC0
T1OSO
T13CKI
15
RC1/T1OSI/CCP2
RC1
T1OSI
CCP2(1)
16
RC2/CCP1/P1A
RC2
CCP1
P1A
17
RC3/SCK/SCL
RC3
SCK
18
34
35
36
37
32
23
RC5/SDO
RC5
SDO
24
RC6/TX/CK
RC6
TX
CK
25
RC7/RX/DT
RC7
RX
DT
26
42
43
44
ST
ST
I/O
I
I/O
ST
CMOS
ST
Digital I/O
Timer1 oscillator input
Capture 2 input/Compare 2 output/PWM 2 output
I/O
I/O
O
ST
ST
Digital I/O
Capture 1 input/Compare 1 output/PWM 1 output
Enhanced CCP1 output
I/O
I/O
ST
ST
I/O
ST
Digital I/O
Synchronous serial clock input/output for
SPI mode
Synchronous serial clock input/output for I2C mode
I/O
I
I/O
ST
ST
ST
Digital I/O
SPI data in
I2C data I/O
I/O
O
ST
Digital I/O
SPI data out
I/O
O
I/O
ST
ST
Digital I/O
EUSART asynchronous transmit
EUSART synchronous clock (see related RX/DT)
I/O
I
I/O
ST
ST
ST
Digital I/O
EUSART asynchronous receive
EUSART synchronous data (see related TX/CK)
Digital I/O
Timer1 oscillator output
Timer1/Timer3 external clock input
35
36
37
SCL
RC4/SDI/SDA
RC4
SDI
SDA
I/O
O
I
42
43
44
Note 1: Default assignment for CCP2 when Configuration bit CCP2MX is set.
2: Alternate assignment for CCP2 when Configuration bit CCP2MX is cleared.
Preliminary
DS41303C-page 21
PIC18F2XK20/4XK20
TABLE 1-3:
Pin Name
Pin Buffer
QFN TQFP Type Type
Description
PORTD is a bidirectional I/O port or a Parallel Slave
Port (PSP) for interfacing to a microprocessor port.
These pins have TTL input buffers when PSP module
is enabled.
RD0/PSP0
RD0
PSP0
19
RD1/PSP1
RD1
PSP1
20
RD2/PSP2
RD2
PSP2
21
RD3/PSP3
RD3
PSP3
22
RD4/PSP4
RD4
PSP4
27
RD5/PSP5/P1B
RD5
PSP5
P1B
28
RD6/PSP6/P1C
RD6
PSP6
P1C
29
RD7/PSP7/P1D
RD7
PSP7
P1D
30
38
39
40
41
38
I/O
I/O
ST
TTL
Digital I/O
Parallel Slave Port data
I/O
I/O
ST
TTL
Digital I/O
Parallel Slave Port data
I/O
I/O
ST
TTL
Digital I/O
Parallel Slave Port data
I/O
I/O
ST
TTL
Digital I/O
Parallel Slave Port data
I/O
I/O
ST
TTL
Digital I/O
Parallel Slave Port data
I/O
I/O
O
ST
TTL
Digital I/O
Parallel Slave Port data
Enhanced CCP1 output
I/O
I/O
O
ST
TTL
Digital I/O
Parallel Slave Port data
Enhanced CCP1 output
I/O
I/O
O
ST
TTL
Digital I/O
Parallel Slave Port data
Enhanced CCP1 output
39
40
41
Note 1: Default assignment for CCP2 when Configuration bit CCP2MX is set.
2: Alternate assignment for CCP2 when Configuration bit CCP2MX is cleared.
DS41303C-page 22
Preliminary
PIC18F2XK20/4XK20
TABLE 1-3:
Pin Name
Pin Buffer
QFN TQFP Type Type
Description
PORTE is a bidirectional I/O port
RE0/RD/AN5
RE0
RD
25
25
AN5
RE1/WR/AN6
RE1
WR
26
10
27
Analog
I/O
I
ST
TTL
Analog
I/O
I
ST
TTL
Digital I/O
Read control for Parallel Slave Port
(see related WR and CS pins)
Analog input 5, ADC channel 5
Digital I/O
Write control for Parallel Slave Port
(see related CS and RD pins)
Analog input 6, ADC channel 6
27
AN7
RE3
ST
TTL
26
AN6
RE2/CS/AN7
RE2
CS
I/O
I
Digital I/O
Chip Select control for Parallel Slave Port
(see related RD and WR)
Analog input 7, ADC channel 7
Analog
6, 29
7, 8, 7, 28
28, 29
No connect
VSS
12, 31 6, 30,
31
VDD
11, 32
NC
13
12, 13,
33, 34
Note 1: Default assignment for CCP2 when Configuration bit CCP2MX is set.
2: Alternate assignment for CCP2 when Configuration bit CCP2MX is cleared.
Preliminary
DS41303C-page 23
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 24
Preliminary
PIC18F2XK20/4XK20
2.0
2.1
Overview
Low-Power Crystal
Crystal/Resonator
High-Speed Crystal/Resonator
High-Speed Crystal/Resonator
with PLL enabled
5. RC
External Resistor/Capacitor with
FOSC/4 output on RA6
6. RCIO
External Resistor/Capacitor with I/O
on RA6
7. INTOSC Internal Oscillator with FOSC/4
output on RA6 and I/O on RA7
8. INTOSCIO Internal Oscillator with I/O on RA6
and RA7
9. EC
External Clock with FOSC/4 output
10. ECIO
External Clock with I/O on RA6
LP
XT
HS
HSPLL
FIGURE 2-1:
PIC18F2XK20/4XK20
Primary Oscillator
OSC2
IDLEN
Sleep
4 x PLL
Secondary Oscillator
T1OSC
T1OSO
T1OSCEN
Enable
Oscillator
OSCCON<6:4>
16 MHz
FOSC<3:0> OSCCON<1:0>
31 kHz
Source
4 MHz
16 MHz
(HFINTOSC)
31 kHz (LFINTOSC)
Postscaler
Internal
Oscillator
Block
16 MHz
Source
8 MHz
2 MHz
1 MHz
500 kHz
250 kHz
Main
Peripherals
Internal Oscillator
CPU
111
Sleep
110
101
100
011
MUX
T1OSI
Sleep
OSCTUNE<6>(1)
MUX
OSC1
HSPLL, HFINTOSC/PLL
010
001
1 31 kHz
000
0
Clock
Control
FOSC<3:0> OSCCON<1:0>
Clock Source Option
for other Modules
OSCTUNE<7>
WDT, PWRT, FSCM
and Two-Speed Start-up
Note
1:
Preliminary
DS41303C-page 25
PIC18F2XK20/4XK20
2.2
Oscillator Control
2.2.4
2.2.1
2.2.2
INTERNAL FREQUENCY
SELECTION
2.2.3
CLOCK STATUS
2.2.5
POWER MANAGEMENT
2.2.6
DS41303C-page 26
OSCILLATOR TRANSITIONS
PIC18F2XK20/4XK20 devices contain circuitry to prevent clock glitches when switching between clock
sources. A short pause in the device clock occurs during the clock switch. The length of this pause is the sum
of two cycles of the old clock source and three to four
cycles of the new clock source. This formula assumes
that the new clock source is stable.
Preliminary
PIC18F2XK20/4XK20
REGISTER 2-1:
R/W-0
IDLEN
IRCF2
R/W-1
IRCF1
R/W-1
IRCF0
R-q
(1)
OSTS
R-0
R/W-0
R/W-0
IOFS
SCS1
SCS0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
q = depends on condition
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6-4
bit 3
bit 2
bit 1-0
Note 1:
2:
3:
Preliminary
DS41303C-page 27
PIC18F2XK20/4XK20
2.3
2.4.1
TABLE 2-1:
2.4
Switch From
Switch To
Frequency
Sleep/POR
LFINTOSC
HFINTOSC
31 kHz
250 kHz to 16 MHz
Oscillator Delay
Oscillator Warm-Up Delay (TWARM)
Sleep/POR
EC, RC
DC 64 MHz
2 instruction cycles
EC, RC
DC 64 MHz
1 cycle of each
Sleep/POR
LP, XT, HS
32 kHz to 40 MHz
Sleep/POR
HSPLL
32 MHz to 64 MHz
HFINTOSC
1 s (approx.)
2.4.2
EC MODE
FIGURE 2-2:
DS41303C-page 28
Clock from
Ext. System
PIC MCU
I/O
Note 1:
Preliminary
OSC2/CLKOUT(1)
PIC18F2XK20/4XK20
2.4.3
FIGURE 2-3:
FIGURE 2-4:
CERAMIC RESONATOR
OPERATION
(XT OR HS MODE)
QUARTZ CRYSTAL
OPERATION (LP, XT OR
HS MODE)
PIC MCU
OSC1/CLKIN
PIC MCU
C1
To Internal
Logic
OSC1/CLKIN
C1
Quartz
Crystal
C2
RP(3)
To Internal
Logic
RS(1)
RF(2)
RF(2)
Sleep
Sleep
C2 Ceramic
RS(1)
Resonator
OSC2/CLKOUT
OSC2/CLKOUT
Note 1:
2:
Preliminary
DS41303C-page 29
PIC18F2XK20/4XK20
2.4.4
2.5
EXTERNAL RC MODES
2.4.4.1
FIGURE 2-5:
EXTERNAL RC MODES
VDD
1.
PIC MCU
OSC1/CLKIN
Internal
Clock
CEXT
VSS
FOSC/4 or
I/O(2)
OSC2/CLKOUT(1)
2.
REXT
2.4.4.2
RC Mode
RCIO Mode
2.5.1
2.5.2
HFINTOSC
DS41303C-page 30
Preliminary
PIC18F2XK20/4XK20
2.5.2.1
OSCTUNE Register
REGISTER 2-2:
(PWRT), Watchdog Timer (WDT), Fail-Safe Clock Monitor (FSCM) and peripherals, are not affected by the
change in frequency.
The OSCTUNE register also implements the INTSRC
and PLLEN bits, which control certain features of the
internal oscillator block.
The INTSRC bit allows users to select which internal
oscillator provides the clock source when the 31 kHz
frequency option is selected. This is covered in greater
detail in Section 2.2.3 Low Frequency Selection.
The PLLEN bit controls the operation of the frequency
multiplier, PLL, in internal oscillator modes. For more
details about the function of the PLLEN bit see
Section 2.6.2 PLL in HFINTOSC Modes
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
INTSRC
PLLEN(1)
TUN5
TUN4
TUN3
TUN2
TUN1
TUN0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5-0
000001 =
000000 = Oscillator module is running at the factory calibrated frequency.
111111 =
Note 1:
The PLLEN bit is active only when the HFINTOSC is the primary clock source (FOSC<2:0> = 100X) and
the selected frequency is 8 MHz or 16 MHz. Otherwise, the PLLEN bit is unavailable and always reads 0.
Preliminary
DS41303C-page 31
PIC18F2XK20/4XK20
2.5.3
LFINTOSC
2.5.5
2.5.4
16 MHz
8 MHz
4 MHz
2 MHz
1 MHz (Default after Reset)
500 kHz
250 kHz
31 kHz (LFINTOSC or HFINTOSC/512)
Note:
2.5.5.1
2.5.5.2
2.5.5.3
DS41303C-page 32
Preliminary
PIC18F2XK20/4XK20
2.6
2.6.2
2.6.1
The 4x frequency multiplier can be used with the internal oscillator block to produce faster device clock
speeds than are normally possible with an internal
oscillator. When enabled, the PLL produces a clock
speed of up to 64 MHz.
Unlike HSPLL mode, the PLL is controlled through
software. The PLLEN control bit of the OSCTUNE
register is used to enable or disable the PLL operation
when the HFINTOSC is used.
The PLL is available when the device is configured to
use the internal oscillator block as its primary clock
source (FOSC<3:0> = 1001 or 1000). Additionally, the
PLL will only function when the selected output frequency is either 8 MHz or 16 MHz (OSCCON<6:4> =
111 or 110). If both of these conditions are not met, the
PLL is disabled.
The PLLEN control bit is only functional in those internal oscillator modes where the PLL is available. In all
other modes, it is forced to 0 and is effectively
unavailable.
FIGURE 2-6:
HS Oscillator Enable
PLL Enable
(from Configuration Register 1H)
OSC2
HS Mode
OSC1 Crystal
Osc
FIN
Phase
Comparator
FOUT
Loop
Filter
VCO
MUX
SYSCLK
Preliminary
DS41303C-page 33
PIC18F2XK20/4XK20
2.7
TABLE 2-2:
2.8
Power-up Delays
OSC Mode
OSC1 Pin
OSC2 Pin
RC, INTOSC
RCIO
INTOSCIO
ECIO
EC
Note:
See Table 4-2 in Section 4.0 Reset for time-outs due to Sleep and MCLR Reset.
DS41303C-page 34
Preliminary
PIC18F2XK20/4XK20
2.9
Clock Switching
2.10
2.9.1
2.9.2
2.10.1
Preliminary
DS41303C-page 35
PIC18F2XK20/4XK20
2.10.2
1.
2.
3.
4.
5.
6.
TWO-SPEED START-UP
SEQUENCE
2.10.4
2.10.3
4.
5.
6.
7.
DS41303C-page 36
Preliminary
PIC18F2XK20/4XK20
FIGURE 2-7:
High Speed
Old Clock
Start-up Time(1)
Clock Sync
Running
New Clock
New Clk Ready
IRCF <2:0> Select Old
Select New
System Clock
Low Speed
High Speed
Old Clock
Start-up Time(1)
Clock Sync
Running
New Clock
New Clk Ready
IRCF <2:0> Select Old
Select New
System Clock
Note 1: Start-up time includes TOST (1024 TOSC) for external clocks, plus TPLL (approx. 2 ms) for HSPLL mode.
Preliminary
DS41303C-page 37
PIC18F2XK20/4XK20
2.11
2.11.3
FIGURE 2-8:
External
Clock
LFINTOSC
Oscillator
64
31 kHz
(~32 s)
488 Hz
(~2 ms)
Sample Clock
2.11.1
2.11.4
Clock
Failure
Detected
FAIL-SAFE DETECTION
2.11.2
FAIL-SAFE OPERATION
DS41303C-page 38
Preliminary
PIC18F2XK20/4XK20
FIGURE 2-9:
Sample Clock
Oscillator
Failure
System
Clock
Output
Clock Monitor Output
(Q)
Failure
Detected
OSCFIF
Test
Note:
TABLE 2-3:
Test
Test
The system clock is normally at a much higher frequency than the sample clock. The relative frequencies in
this example have been chosen for clarity.
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets(1)
CONFIG1H
IESO
FCMEN
FOSC3
FOSC2
FOSC1
FOSC0
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
0000 000x
0000 000x
OSCCON
IDLEN
IRCF2
IRCF1
IRCF0
OSTS
IOFS
SCS1
SCS0
0011 q000
0011 q000
OSCTUNE
INTSRC
PLLEN
TUN5
TUN4
TUN3
TUN2
TUN1
TUN0
0000 0000
000u uuuu
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
0000 0000
0000 0000
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
0000 0000
0000 0000
INTCON
PIR2
Legend:
Note 1:
x = unknown, u = unchanged, = unimplemented locations read as 0. Shaded cells are not used by oscillators.
Other (non Power-up) Resets include MCLR Reset and Watchdog Timer Reset during normal operation.
Preliminary
DS41303C-page 39
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 40
Preliminary
PIC18F2XK20/4XK20
3.0
POWER-MANAGED MODES
3.1.1
3.1.2
Run modes
Idle modes
Sleep mode
ENTERING POWER-MANAGED
MODES
3.1
CLOCK SOURCES
TABLE 3-1:
POWER-MANAGED MODES
OSCCON Bits
Mode
Module Clocking
IDLEN(1)
SCS<1:0>
CPU
Peripherals
N/A
Off
Off
PRI_RUN
N/A
00
Clocked
Clocked
SEC_RUN
N/A
01
Clocked
Clocked
RC_RUN
N/A
1x
Clocked
Clocked
PRI_IDLE
00
Off
Clocked
SEC_IDLE
01
Off
Clocked
RC_IDLE
1x
Off
Clocked
Sleep
Note 1:
2:
Preliminary
DS41303C-page 41
PIC18F2XK20/4XK20
3.1.3
Primary Oscillator
HFINTOSC
Secondary Oscillator
LFINTOSC or
HFINTOSC is not yet stable
DS41303C-page 42
PRI_RUN MODE
3.2.2
SEC_RUN MODE
3.1.4
Run Modes
3.2.1
Three flag bits indicate the current clock source and its
status. They are:
TABLE 3-2:
3.2
Preliminary
PIC18F2XK20/4XK20
3.2.3
3.3
RC_RUN MODE
Sleep Mode
3.4
Idle Modes
Preliminary
DS41303C-page 43
PIC18F2XK20/4XK20
FIGURE 3-1:
Q1 Q2 Q3 Q4 Q1
OSC1
CPU
Clock
Peripheral
Clock
Sleep
Program
Counter
PC
FIGURE 3-2:
PC + 2
Q1
OSC1
PLL Clock
Output
TOST(1)
TPLL(1)
CPU Clock
Peripheral
Clock
Program
Counter
PC
Wake Event
PC + 2
PC + 4
PC + 6
Note1: TOST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
DS41303C-page 44
Preliminary
PIC18F2XK20/4XK20
3.4.1
PRI_IDLE MODE
3.4.2
FIGURE 3-3:
SEC_IDLE MODE
Note:
Q3
Q2
Q4
Q1
OSC1
CPU Clock
Peripheral
Clock
Program
Counter
PC
FIGURE 3-4:
PC + 2
Q2
Q3
Q4
OSC1
TCSD
CPU Clock
Peripheral
Clock
Program
Counter
PC
Wake Event
Preliminary
DS41303C-page 45
PIC18F2XK20/4XK20
3.4.3
RC_IDLE MODE
3.5.1
In RC_IDLE mode, the CPU is disabled but the peripherals continue to be clocked from the internal oscillator
block from the HFINTOSC multiplexer output. This
mode allows for controllable power conservation during
Idle periods.
From RC_RUN, this mode is entered by setting the
IDLEN bit and executing a SLEEP instruction. If the
device is in another Run mode, first set IDLEN, then set
the SCS1 bit and execute SLEEP. It is recommended
that SCS0 also be cleared, although its value is
ignored, to maintain software compatibility with future
devices. The HFINTOSC multiplexer may be used to
select a higher clock frequency by modifying the IRCF
bits before executing the SLEEP instruction. When the
clock source is switched to the HFINTOSC multiplexer,
the primary oscillator is shut down and the OSTS bit is
cleared.
If the IRCF bits are set to any non-zero value, or the
INTSRC bit is set, the HFINTOSC output is enabled.
The IOFS bit becomes set, after the HFINTOSC output
becomes stable, after an interval of TIOBST
(parameter 39, Table 26-10). Clocks to the peripherals
continue while the HFINTOSC source stabilizes. If the
IRCF bits were previously at a non-zero value, or
INTSRC was set before the SLEEP instruction was executed and the HFINTOSC source was already stable,
the IOFS bit will remain set. If the IRCF bits and
INTSRC are all clear, the HFINTOSC output will not be
enabled, the IOFS bit will remain clear and there will be
no indication of the current clock source.
When a wake event occurs, the peripherals continue to
be clocked from the HFINTOSC multiplexer output.
After a delay of TCSD following the wake event, the CPU
begins executing code being clocked by the
HFINTOSC multiplexer. The IDLEN and SCS bits are
not affected by the wake-up. The LFINTOSC source
will continue to run if either the WDT or the Fail-Safe
Clock Monitor is enabled.
3.5
3.5.2
3.5.3
EXIT BY RESET
DS41303C-page 46
EXIT BY INTERRUPT
Preliminary
PIC18F2XK20/4XK20
3.5.4
TABLE 3-3:
EXIT DELAY ON WAKE-UP BY RESET FROM SLEEP MODE OR ANY IDLE MODE
(BY CLOCK SOURCES)
Clock Source
before Wake-up
Clock Source
after Wake-up
Exit Delay
LP, XT, HS
Primary Device Clock
(PRI_IDLE mode)
HSPLL
EC, RC
TCSD(1)
HFINTOSC(2)
T1OSC or LFINTOSC(1)
HFINTOSC(2)
None
(Sleep mode)
2:
3:
4:
IOFS
LP, XT, HS
TOST(3)
HSPLL
TOST + tPLL(3)
OSTS
EC, RC
HFINTOSC(1)
TCSD(1)
TIOBST(4)
IOFS
LP, XT, HS
TOST(4)
HSPLL
TOST + tPLL(3)
EC, RC
TCSD(1)
HFINTOSC(1)
None
LP, XT, HS
TOST(3)
HSPLL
TOST + tPLL(3)
OSTS
EC, RC
TCSD(1)
TIOBST(4)
IOFS
HFINTOSC(1)
Note 1:
OSTS
OSTS
IOFS
TCSD (parameter
38) is a required delay when waking from Sleep and all Idle modes and runs concurrently
with any other required delays (see Section 3.4 Idle Modes). On Reset, HFINTOSC defaults to 1 MHz.
Includes both the HFINTOSC 16 MHz source and postscaler derived frequencies.
TOST is the Oscillator Start-up Timer (parameter 32). tPLL is the PLL Lock-out Timer (parameter F12).
Execution continues during the HFINTOSC stabilization period, TIOBST (parameter 39).
Preliminary
DS41303C-page 47
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 48
Preliminary
PIC18F2XK20/4XK20
4.0
RESET
differentiate
4.1
RCON Register
FIGURE 4-1:
RESET
Instruction
Stack Full/Underflow Reset
Stack
Pointer
External Reset
MCLRE
MCLR
( )_IDLE
Sleep
WDT
Time-out
VDD Rise
Detect
POR Pulse
VDD
Brown-out
Reset
BOREN
OST/PWRT
OST(2) 1024 Cycles
Chip_Reset
OSC1
32 s
LFINTOSC
PWRT(2) 65.5 ms
11-bit Ripple Counter
Enable PWRT
Enable OST(1)
Note 1:
2:
Preliminary
DS41303C-page 49
PIC18F2XK20/4XK20
REGISTER 4-1:
R/W-0
IPEN
SBOREN
U-0
(1)
R/W-1
RI
R-1
TO
R-1
R/W-0
PD
(2)
R/W-0
POR
bit 7
BOR
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1:
2:
3:
Note 1: Brown-out Reset is indicated when BOR is 0 and POR is 1 (assuming that both POR and BOR were set
to 1 by firmware immediately after POR).
2: It is recommended that the POR bit be set after a Power-on Reset has been detected so that subsequent
Power-on Resets may be detected.
DS41303C-page 50
Preliminary
PIC18F2XK20/4XK20
4.2
FIGURE 4-2:
4.3
VDD
VDD
EXTERNAL POWER-ON
RESET CIRCUIT (FOR
SLOW VDD POWER-UP)
PIC MCU
R
R1
MCLR
Note 1:
2:
3:
Preliminary
DS41303C-page 51
PIC18F2XK20/4XK20
4.4
4.4.2
4.4.1
DETECTING BOR
TABLE 4-1:
4.4.3
4.4.4
BOR CONFIGURATIONS
BOR Configuration
BOREN1
BOREN0
Status of
SBOREN
(RCON<6>)
Unavailable
Available
Unavailable
Unavailable
DS41303C-page 52
BOR Operation
BOR disabled; must be enabled by reprogramming the Configuration bits.
BOR enabled by software; operation controlled by SBOREN.
Preliminary
PIC18F2XK20/4XK20
4.5
4.5.1
The
Power-up
Timer
(PWRT)
of
PIC18F2XK20/4XK20 devices is an 11-bit counter
which uses the LFINTOSC source as the clock input.
This yields an approximate time interval of
2048 x 32 s = 65.6 ms. While the PWRT is counting,
the device is held in Reset.
The power-up time delay depends on the LFINTOSC
clock and will vary from chip-to-chip due to temperature
and process variation. See DC parameter 33 for
details.
The PWRT is enabled by clearing the PWRTEN
Configuration bit.
4.5.2
TABLE 4-2:
4.5.3
4.5.4
TIME-OUT SEQUENCE
Oscillator
Configuration
HSPLL
PWRTEN = 1
Exit from
Power-Managed Mode
PWRTEN = 0
66
ms(1)
+ 1024 TOSC + 2
ms(2)
HS, XT, LP
1024 TOSC
1024 TOSC
EC, ECIO
66 ms(1)
RC, RCIO
ms(1)
(1)
INTIO1, INTIO2
66
66 ms
Preliminary
DS41303C-page 53
PIC18F2XK20/4XK20
FIGURE 4-3:
TIME-OUT SEQUENCE ON POWER-UP (MCLR TIED TO VDD, VDD RISE < TPWRT)
VDD
MCLR
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
FIGURE 4-4:
VDD
MCLR
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
FIGURE 4-5:
VDD
MCLR
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
DS41303C-page 54
Preliminary
PIC18F2XK20/4XK20
FIGURE 4-6:
SLOW RISE TIME (MCLR TIED TO VDD, VDD RISE > TPWRT)
5V
VDD
0V
MCLR
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
FIGURE 4-7:
VDD
MCLR
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
TPLL
PLL TIME-OUT
INTERNAL RESET
Note:
Preliminary
DS41303C-page 55
PIC18F2XK20/4XK20
4.6
TABLE 4-3:
Condition
Program
Counter
RCON Register
SBOREN
RI
TO
PD
STKPTR Register
POR BOR STKFUL
STKUNF
Power-on Reset
0000h
RESET Instruction
0000h
u(2)
Brown-out Reset
0000h
(2)
0000h
u(2)
0000h
u(2)
0000h
u(2)
0000h
u(2)
0000h
u(2)
0000h
u(2)
0000h
u(2)
PC + 2
u(2)
PC + 2(1)
u(2)
Legend: u = unchanged
Note 1: When the wake-up is due to an interrupt and the GIEH or GIEL bits are set, the PC is loaded with the
interrupt vector (008h or 0018h).
2: Reset state is 1 for SBOREN and unchanged for all other Resets when software BOR is enabled
(BOREN<1:0> Configuration bits = 01). Otherwise, the Reset state is 0.
DS41303C-page 56
Preliminary
PIC18F2XK20/4XK20
TABLE 4-4:
Power-on Reset,
Brown-out Reset
MCLR Resets,
WDT Reset,
RESET Instruction,
Stack Resets
TOSU
PIC18F2XK20 PIC18F4XK20
---0 0000
---0 0000
---0 uuuu(3)
TOSH
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu(3)
TOSL
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu(3)
STKPTR
PIC18F2XK20 PIC18F4XK20
00-0 0000
uu-0 0000
uu-u uuuu(3)
PCLATU
PIC18F2XK20 PIC18F4XK20
---0 0000
---0 0000
---u uuuu
PCLATH
Register
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
PCL
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
PC + 2(2)
TBLPTRU
PIC18F2XK20 PIC18F4XK20
--00 0000
--00 0000
--uu uuuu
TBLPTRH
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
TBLPTRL
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
TABLAT
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
PRODH
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
PRODL
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
INTCON
PIC18F2XK20 PIC18F4XK20
0000 000x
0000 000u
uuuu uuuu(1)
INTCON2
PIC18F2XK20 PIC18F4XK20
1111 -1-1
1111 -1-1
uuuu -u-u(1)
INTCON3
PIC18F2XK20 PIC18F4XK20
11-0 0-00
11-0 0-00
uu-u u-uu(1)
INDF0
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
POSTINC0
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
POSTDEC0
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
PREINC0
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
PLUSW0
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
FSR0H
PIC18F2XK20 PIC18F4XK20
---- 0000
---- 0000
---- uuuu
FSR0L
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
WREG
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
INDF1
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
POSTINC1
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
POSTDEC1
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
PREINC1
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
PLUSW1
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
Legend:
Note 1:
2:
3:
4:
5:
6:
Preliminary
DS41303C-page 57
PIC18F2XK20/4XK20
TABLE 4-4:
Power-on Reset,
Brown-out Reset
MCLR Resets,
WDT Reset,
RESET Instruction,
Stack Resets
FSR1H
PIC18F2XK20 PIC18F4XK20
---- 0000
---- 0000
---- uuuu
FSR1L
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
BSR
Register
PIC18F2XK20 PIC18F4XK20
---- 0000
---- 0000
---- uuuu
INDF2
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
POSTINC2
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
POSTDEC2
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
PREINC2
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
PLUSW2
PIC18F2XK20 PIC18F4XK20
N/A
N/A
N/A
FSR2H
PIC18F2XK20 PIC18F4XK20
---- 0000
---- 0000
---- uuuu
FSR2L
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
STATUS
PIC18F2XK20 PIC18F4XK20
---x xxxx
---u uuuu
---u uuuu
TMR0H
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
TMR0L
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
T0CON
PIC18F2XK20 PIC18F4XK20
1111 1111
1111 1111
uuuu uuuu
OSCCON
PIC18F2XK20 PIC18F4XK20
0011 qq00
0011 qq00
uuuu uuuu
HLVDCON
PIC18F2XK20 PIC18F4XK20
0-00 0101
0-00 0101
u-uu uuuu
WDTCON
PIC18F2XK20 PIC18F4XK20
---- ---0
---- ---0
---- ---u
PIC18F2XK20 PIC18F4XK20
0q-1 11q0
0u-q qquu
uu-u qquu
RCON
(4)
TMR1H
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
TMR1L
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
T1CON
PIC18F2XK20 PIC18F4XK20
0000 0000
u0uu uuuu
uuuu uuuu
TMR2
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
PR2
PIC18F2XK20 PIC18F4XK20
1111 1111
1111 1111
1111 1111
T2CON
PIC18F2XK20 PIC18F4XK20
-000 0000
-000 0000
-uuu uuuu
SSPBUF
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
SSPADD
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
SSPSTAT
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
SSPCON1
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
SSPCON2
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
Legend:
Note 1:
2:
3:
4:
5:
6:
DS41303C-page 58
Preliminary
PIC18F2XK20/4XK20
TABLE 4-4:
Power-on Reset,
Brown-out Reset
MCLR Resets,
WDT Reset,
RESET Instruction,
Stack Resets
ADRESH
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
ADRESL
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
ADCON0
Register
PIC18F2XK20 PIC18F4XK20
--00 0000
--00 0000
--uu uuuu
ADCON1
PIC18F2XK20 PIC18F4XK20
--00 0qqq
--00 0qqq
--uu uuuu
ADCON2
PIC18F2XK20 PIC18F4XK20
0-00 0000
0-00 0000
u-uu uuuu
CCPR1H
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCPR1L
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCP1CON
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
CCPR2H
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCPR2L
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCP2CON
PIC18F2XK20 PIC18F4XK20
--00 0000
--00 0000
--uu uuuu
PSTRCON
PIC18F2XK20 PIC18F4XK20
---0 0001
---0 0001
---u uuuu
BAUDCTL
PIC18F2XK20 PIC18F4XK20
0100 0-00
0100 0-00
uuuu u-uu
PWM1CON
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
ECCP1AS
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
CVRCON
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
CVRCON2
PIC18F2XK20 PIC18F4XK20
00-- ----
00-- ----
uu-- ----
TMR3H
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
TMR3L
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
T3CON
PIC18F2XK20 PIC18F4XK20
0000 0000
uuuu uuuu
uuuu uuuu
SPBRGH
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
SPBRG
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
RCREG
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
TXREG
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
TXSTA
PIC18F2XK20 PIC18F4XK20
0000 0010
0000 0010
uuuu uuuu
RCSTA
PIC18F2XK20 PIC18F4XK20
0000 000x
0000 000x
uuuu uuuu
EEADR
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
EEADRH
PIC18F26K20
PIC18F46K20
---- --00
---- --00
---- --uu
EEDATA
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
EECON2
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
0000 0000
PIC18F2XK20 PIC18F4XK20
xx-0 x000
uu-0 u000
uu-0 u000
EECON1
Legend:
Note 1:
2:
3:
4:
5:
6:
Preliminary
DS41303C-page 59
PIC18F2XK20/4XK20
TABLE 4-4:
Register
Power-on Reset,
Brown-out Reset
MCLR Resets,
WDT Reset,
RESET Instruction,
Stack Resets
IPR2
PIC18F2XK20 PIC18F4XK20
1111 1111
1111 1111
uuuu uuuu
PIR2
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu(1)
PIE2
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
PIC18F2XK20 PIC18F4XK20
1111 1111
1111 1111
uuuu uuuu
PIC18F2XK20 PIC18F4XK20
-111 1111
-111 1111
-uuu uuuu
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu(1)
PIC18F2XK20 PIC18F4XK20
-000 0000
-000 0000
-uuu uuuu(1)
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
PIC18F2XK20 PIC18F4XK20
-000 0000
-000 0000
-uuu uuuu
OSCTUNE
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
TRISE
IPR1
PIR1
PIE1
PIC18F2XK20 PIC18F4XK20
---- -111
---- -111
---- -uuu
TRISD
PIC18F2XK20 PIC18F4XK20
1111 1111
1111 1111
uuuu uuuu
TRISC
PIC18F2XK20 PIC18F4XK20
1111 1111
1111 1111
uuuu uuuu
TRISB
PIC18F2XK20 PIC18F4XK20
1111 1111
(5)
1111 1111
(5)
uuuu uuuu
(5)
uuuu uuuu(5)
TRISA
PIC18F2XK20 PIC18F4XK20
1111 1111
LATE
PIC18F2XK20 PIC18F4XK20
---- -xxx
---- -uuu
---- -uuu
LATD
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
LATC
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
LATB
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
PIC18F2XK20 PIC18F4XK20
xxxx xxxx(5)
uuuu uuuu(5)
uuuu uuuu(5)
PIC18F2XK20 PIC18F4XK20
---- x000
---- u000
---- uuuu
PIC18F2XK20 PIC18F4XK20
---- x---
---- u---
---- u---
LATA(5)
PORTE
PORTD
1111 1111
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
PORTC
PIC18F2XK20 PIC18F4XK20
xxxx xxxx
uuuu uuuu
uuuu uuuu
PORTB
PIC18F2XK20 PIC18F4XK20
xxx0 0000
(5)
PORTA
PIC18F2XK20 PIC18F4XK20
ANSELH(6)
xx0x 0000
uuu0 0000
(5)
uu0u 0000
uuuu uuuu
(5)
uuuu uuuu(5)
PIC18F2XK20 PIC18F4XK20
---1 1111
---1 1111
---u uuuu
ANSEL
PIC18F2XK20 PIC18F4XK20
1111 1111
1111 1111
uuuu uuuu
IOCB
PIC18F2XK20 PIC18F4XK20
0000 ----
0000 ----
uuuu ----
WPUB
PIC18F2XK20 PIC18F4XK20
1111 1111
1111 1111
uuuu uuuu
CM1CON0
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
PIC18F2XK20 PIC18F4XK20
0000 0000
0000 0000
uuuu uuuu
CM2CON0
Legend:
Note 1:
2:
3:
4:
5:
6:
DS41303C-page 60
Preliminary
PIC18F2XK20/4XK20
TABLE 4-4:
Power-on Reset,
Brown-out Reset
MCLR Resets,
WDT Reset,
RESET Instruction,
Stack Resets
CM2CON1
PIC18F2XK20 PIC18F4XK20
0000 ----
0000 ----
uuuu ----
SLRCON
PIC18F2XK20 PIC18F4XK20
---1 1111
---1 1111
---u uuuu
PIC18F2XK20 PIC18F4XK20
1111 1111
1111 1111
uuuu uuuu
Register
SSPMSK
Legend:
Note 1:
2:
3:
4:
5:
6:
Preliminary
DS41303C-page 61
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 62
Preliminary
PIC18F2XK20/4XK20
5.0
MEMORY ORGANIZATION
5.1
FIGURE 5-1:
CALL,RCALL,RETURN
RETFIE,RETLW
Stack Level 1
Stack Level 31
2000h
0000h
0008h
0018h
On-Chip
Program Memory
3FFFh
4000h
PIC18F23K20/
43K20
On-Chip
Program Memory
User Memory Space
On-Chip
Program Memory
1FFFh
Reset Vector
On-Chip
Program Memory
PIC18F24K20/
44K20
7FFFh
8000h
PIC18F25K20/
45K20
Read 0
Read 0
Read 0
FFFFh
10000h
PIC18F26K20/
46K20
Read 0
Preliminary
1FFFFFh
200000h
DS41303C-page 63
PIC18F2XK20/4XK20
5.1.1
PROGRAM COUNTER
5.1.2
FIGURE 5-2:
5.1.2.1
Top-of-Stack Access
Top-of-Stack Registers
TOSU
00h
TOSH
1Ah
STKPTR<4:0>
00010
TOSL
34h
Top-of-Stack
DS41303C-page 64
Stack Pointer
001A34h
000D58h
Preliminary
00011
00010
00001
00000
PIC18F2XK20/4XK20
5.1.2.2
Note:
5.1.2.3
REGISTER 5-1:
The POP instruction discards the current TOS by decrementing the Stack Pointer. The previous value pushed
onto the stack then becomes the TOS value.
R/C-0
R/C-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
STKFUL(1)
STKUNF(1)
SP4
SP3
SP2
SP1
SP0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
U = Unimplemented
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
Unimplemented: Read as 0
bit 4-0
Note 1:
Preliminary
DS41303C-page 65
PIC18F2XK20/4XK20
5.1.2.4
5.1.4
5.1.3
5.1.4.1
Computed GOTO
EXAMPLE 5-2:
EXAMPLE 5-1:
CALL SUB1, FAST
RETURN, FAST
SUB1
DS41303C-page 66
ORG
TABLE
5.1.4.2
MOVF
CALL
nn00h
ADDWF
RETLW
RETLW
RETLW
.
.
.
Preliminary
PIC18F2XK20/4XK20
5.2
5.2.1
5.2.2
CLOCKING SCHEME
FIGURE 5-3:
INSTRUCTION FLOW/PIPELINING
CLOCK/INSTRUCTION CYCLE
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
OSC1
Q1
Q2
Internal
Phase
Clock
Q3
Q4
PC
PC
PC + 2
PC + 4
OSC2/CLKOUT
(RC mode)
Execute INST (PC 2)
Fetch INST (PC)
EXAMPLE 5-3:
TCY0
TCY1
Fetch 1
Execute 1
2. MOVWF PORTB
4. BSF
1. MOVLW 55h
3. BRA
SUB_1
Fetch 2
TCY2
TCY3
TCY4
TCY5
Execute 2
Fetch 3
Execute 3
Fetch 4
Flush (NOP)
Fetch SUB_1 Execute SUB_1
All instructions are single cycle, except for any program branches. These take two cycles since the fetch instruction
is flushed from the pipeline while the new instruction is being fetched and then executed.
Preliminary
DS41303C-page 67
PIC18F2XK20/4XK20
5.2.3
INSTRUCTIONS IN PROGRAM
MEMORY
FIGURE 5-4:
LSB = 0
0Fh
EFh
F0h
C1h
F4h
55h
03h
00h
23h
56h
Program Memory
Byte Locations
5.2.4
Instruction 1:
Instruction 2:
MOVLW
GOTO
055h
0006h
Instruction 3:
MOVFF
123h, 456h
TWO-WORD INSTRUCTIONS
EXAMPLE 5-4:
Word Address
000000h
000002h
000004h
000006h
000008h
00000Ah
00000Ch
00000Eh
000010h
000012h
000014h
TWO-WORD INSTRUCTIONS
CASE 1:
Object Code
0110 0110 0000
1100 0001 0010
1111 0100 0101
0010 0100 0000
0000
0011
0110
0000
Source Code
TSTFSZ
REG1
; is RAM location 0?
MOVFF
REG1, REG2 ; No, skip this word
; Execute this word as a NOP
ADDWF
REG3
; continue code
0000
0011
0110
0000
Source Code
TSTFSZ
REG1
; is RAM location 0?
MOVFF
REG1, REG2 ; Yes, execute this word
; 2nd word of instruction
ADDWF
REG3
; continue code
CASE 2:
Object Code
0110 0110 0000
1100 0001 0010
1111 0100 0101
0010 0100 0000
DS41303C-page 68
Preliminary
PIC18F2XK20/4XK20
5.3
Note:
5.3.1
Preliminary
DS41303C-page 69
PIC18F2XK20/4XK20
FIGURE 5-5:
BSR<3:0>
= 0000
= 0001
= 0010
= 0011
= 0100
= 0101
= 0110
= 0111
= 1000
= 1001
= 1010
= 1011
= 1100
= 1101
= 1110
= 1111
DS41303C-page 70
When a = 0:
Access RAM
FFh
00h
GPR
Bank 0
GPR
Bank 1
Bank 2
Bank 3
Bank 4
Bank 5
Bank 6
Bank 7
Bank 8
Bank 9
000h
05Fh
060h
0FFh
100h
FFh
00h
1FFh
200h
FFh
00h
2FFh
300h
FFh
00h
3FFh
400h
FFh
00h
4FFh
500h
FFh
00h
5FFh
600h
FFh
00h
6FFh
700h
7FFh
800h
FFh
00h
FFh
00h
Unused
Read 00h
9FFh
A00h
FFh
00h
AFFh
B00h
FFh
00h
BFFh
C00h
FFh
Bank 13 00h
CFFh
D00h
FFh
00h
DFFh
E00h
Bank 11
Bank 12
Bank 14
FFh
00h
Unused
FFh
SFR
Bank 15
Access Bank
Access RAM Low
00h
5Fh
Access RAM High 60h
(SFRs)
FFh
8FFh
900h
FFh
00h
Bank 10
EFFh
F00h
F5Fh
F60h
FFFh
Preliminary
PIC18F2XK20/4XK20
FIGURE 5-6:
BSR<3:0>
= 0000
= 0001
= 0010
= 0011
= 0100
= 0101
= 0110
= 0111
= 1000
= 1001
= 1010
= 1011
= 1100
= 1101
= 1110
= 1111
When a = 0:
Access RAM
FFh
00h
GPR
Bank 0
GPR
Bank 1
Bank 2
Bank 3
Bank 4
Bank 5
Bank 6
Bank 7
Bank 8
Bank 9
000h
05Fh
060h
0FFh
100h
1FFh
200h
FFh
00h
2FFh
300h
FFh
00h
3FFh
400h
FFh
00h
4FFh
500h
FFh
00h
5FFh
600h
FFh
00h
6FFh
700h
7FFh
800h
FFh
00h
FFh
00h
Unused
Read 00h
FFh
00h
AFFh
B00h
FFh
00h
BFFh
C00h
FFh
Bank 13 00h
CFFh
D00h
FFh
00h
DFFh
E00h
Bank 12
Bank 14
FFh
00h
Unused
FFh
SFR
Bank 15
Access Bank
Access RAM Low
00h
5Fh
Access RAM High 60h
(SFRs)
FFh
8FFh
900h
9FFh
A00h
Bank 11
GPR
FFh
00h
FFh
00h
Bank 10
EFFh
F00h
F5Fh
F60h
FFFh
Preliminary
DS41303C-page 71
PIC18F2XK20/4XK20
FIGURE 5-7:
BSR<3:0>
= 0000
= 0001
= 0010
= 0011
= 0100
= 0101
= 0110
= 0111
= 1000
= 1001
= 1010
= 1011
= 1100
= 1101
= 1110
= 1111
DS41303C-page 72
When a = 0:
Access RAM
FFh
00h
GPR
Bank 0
GPR
Bank 1
Bank 2
Bank 3
Bank 4
Bank 5
Bank 6
Bank 7
Bank 8
Bank 9
Bank 10
000h
05Fh
060h
0FFh
100h
1FFh
200h
FFh
00h
2FFh
300h
GPR
3FFh
400h
FFh
00h
When a = 1:
The BSR specifies the Bank
used by the instruction.
4FFh
500h
GPR
FFh
00h
5FFh
600h
FFh
00h
6FFh
700h
FFh
00h
7FFh
800h
FFh
00h
8FFh
900h
FFh
00h
Unused
Read 00h
BFFh
C00h
FFh
Bank 13 00h
CFFh
D00h
FFh
00h
DFFh
E00h
FFh
00h
Unused
FFh
SFR
Bank 15
Access Bank
Access RAM Low
00h
5Fh
Access RAM High 60h
(SFRs)
FFh
9FFh
A00h
FFh
00h
Bank 14
GPR
FFh
00h
AFFh
B00h
Bank 12
GPR
FFh
00h
FFh
00h
Bank 11
EFFh
F00h
F5Fh
F60h
FFFh
Preliminary
PIC18F2XK20/4XK20
FIGURE 5-8:
BSR<3:0>
= 0000
= 0001
= 0010
= 0011
= 0100
= 0101
= 0110
= 0111
= 1000
= 1001
= 1010
= 1011
= 1100
= 1101
= 1110
= 1111
When a = 0:
Access RAM
FFh
00h
GPR
Bank 0
GPR
Bank 1
Bank 2
Bank 3
Bank 4
Bank 5
Bank 6
Bank 7
Bank 8
Bank 9
Bank 10
Bank 11
Bank 12
GPR
FFh
00h
2FFh
300h
GPR
3FFh
400h
FFh
00h
When a = 1:
The BSR specifies the Bank
used by the instruction.
GPR
4FFh
500h
FFh
00h
GPR
5FFh
600h
FFh
00h
GPR
FFh
00h
6FFh
700h
GPR
7FFh
800h
FFh
00h
GPR
FFh
00h
Access Bank
Access RAM Low
00h
5Fh
Access RAM High 60h
(SFRs)
FFh
8FFh
900h
GPR
9FFh
A00h
FFh
00h
GPR
FFh
00h
FFh
00h
FFh
00h
AFFh
B00h
GPR
BFFh
C00h
GPR
CFFh
D00h
GPR
DFFh
E00h
GPR
FFh
00h
GPR
FFh
SFR
Bank 15
1FFh
200h
FFh
00h
FFh
Bank 13 00h
Bank 14
000h
05Fh
060h
0FFh
100h
EFFh
F00h
F5Fh
F60h
FFFh
Preliminary
DS41303C-page 73
PIC18F2XK20/4XK20
FIGURE 5-9:
Bank Select(2)
000h
Data Memory
00h
Bank 0
100h
Bank 1
200h
300h
Bank 2
FFh
00h
From Opcode(2)
FFh
00h
FFh
00h
Bank 3
through
Bank 13
E00h
Bank 14
F00h
FFFh
Note 1:
2:
Bank 15
FFh
00h
FFh
00h
FFh
The Access RAM bit of the instruction can be used to force an override of the selected bank (BSR<3:0>) to
the registers of the Access Bank.
The MOVFF instruction embeds the entire 12-bit address in the instruction.
DS41303C-page 74
Preliminary
PIC18F2XK20/4XK20
5.3.2
ACCESS BANK
5.3.3
5.3.4
Preliminary
DS41303C-page 75
PIC18F2XK20/4XK20
TABLE 5-1:
Address
Name
Address
Name
Address
Name
Address
Name
FFFh
TOSU
FD7h
TMR0H
FAFh
SPBRG
F87h
(2)
FFEh
TOSH
FD6h
TMR0L
FAEh
RCREG
F86h
(2)
FFDh
TOSL
FD5h
T0CON
FADh
TXREG
F85h
(2)
FFCh
STKPTR
FD4h
(2)
FACh
TXSTA
F84h
PORTE
FFBh
PCLATU
FD3h
OSCCON
FABh
RCSTA
F83h
PORTD(3)
FFAh
PCLATH
FD2h
HLVDCON
FAAh
EEADRH(4)
F82h
PORTC
FF9h
PCL
FD1h
WDTCON
FA9h
EEADR
F81h
PORTB
FF8h
TBLPTRU
FD0h
RCON
FA8h
EEDATA
F80h
PORTA
FF7h
TBLPTRH
FCFh
TMR1H
FA7h
EECON2(1)
F7Fh
ANSELH
FF6h
TBLPTRL
FCEh
TMR1L
FA6h
EECON1
F7Eh
ANSEL
FF5h
TABLAT
FCDh
T1CON
FA5h
(2)
F7Dh
IOCB
FF4h
PRODH
FCCh
TMR2
FA4h
(2)
F7Ch
WPUB
FF3h
PRODL
FCBh
PR2
FA3h
(2)
F7Bh
CM1CON0
FF2h
INTCON
FCAh
T2CON
FA2h
IPR2
F7Ah
CM2CON0
FF1h
INTCON2
FC9h
SSPBUF
FA1h
PIR2
F79h
CM2CON1
FF0h
INTCON3
FC8h
SSPADD
FA0h
PIE2
F78h
SLRCON
FEFh
INDF0(1)
FC7h
SSPSTAT
F9Fh
IPR1
F77h
SSPMSK
FEEh POSTINC0(1)
FC6h
SSPCON1
F9Eh
PIR1
F76h
(2)
FEDh
POSTDEC0(1)
FC5h
SSPCON2
F9Dh
PIE1
F75h
(2)
FECh
PREINC0(1)
FC4h
ADRESH
F9Ch
(2)
F74h
(2)
FEBh
PLUSW0(1)
FC3h
ADRESL
F9Bh
OSCTUNE
F73h
(2)
FEAh
FSR0H
FC2h
ADCON0
F9Ah
(2)
F72h
(2)
F71h
(2)
FE9h
FSR0L
FC1h
ADCON1
F99h
(2)
FE8h
WREG
FC0h
ADCON2
F98h
(2)
F70h
(2)
FE7h
INDF1(1)
F6Fh
(2)
FE6h POSTINC1(1)
FBFh
CCPR1H
F97h
(2)
FBEh
CCPR1L
F96h
TRISE(3)
F6Eh
(2)
F6Dh
(2)
FE5h
POSTDEC1(1)
FBDh
CCP1CON
F95h
TRISD(3)
FE4h
PREINC1(1)
FBCh
CCPR2H
F94h
TRISC
F6Ch
(2)
FE3h
PLUSW1(1)
FBBh
CCPR2L
F93h
TRISB
F6Bh
(2)
FE2h
FSR1H
FBAh
CCP2CON
F92h
TRISA
F6Ah
(2)
(2)
FE1h
FSR1L
FB9h
PSTRCON
F91h
F69h
(2)
FE0h
BSR
FB8h
BAUDCTL
F90h
(2)
F68h
(2)
FDFh
INDF2(1)
F67h
(2)
FDEh POSTINC2(1)
FB7h
PWM1CON
F8Fh
(2)
FB6h
ECCP1AS
F8Eh
(2)
F66h
(2)
F65h
(2)
FDDh
POSTDEC2(1)
FB5h
CVRCON
F8Dh
LATE(3)
FDCh
PREINC2(1)
FB4h
CVRCON2
F8Ch
LATD(3)
F64h
(2)
FDBh
PLUSW2(1)
FB3h
TMR3H
F8Bh
LATC
F63h
(2)
FDAh
FSR2H
FB2h
TMR3L
F8Ah
LATB
F62h
(2)
FD9h
FSR2L
FB1h
T3CON
F89h
LATA
F61h
(2)
FD8h
STATUS
FB0h
SPBRGH
F88h
(2)
F60h
(2)
Note 1:
2:
3:
4:
DS41303C-page 76
Preliminary
PIC18F2XK20/4XK20
TABLE 5-2:
File Name
TOSU
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Details
on page:
---0 0000
57, 64
TOSH
0000 0000
57, 64
TOSL
0000 0000
57, 64
00-0 0000
57, 65
STKPTR
PCLATU
STKFUL
STKUNF
Value on
POR, BOR
SP4
SP3
SP2
SP1
SP0
---0 0000
57, 64
PCLATH
0000 0000
57, 64
PCL
0000 0000
57, 64
--00 0000
57, 90
TBLPTRU
bit 21
TBLPTRH
0000 0000
57, 90
TBLPTRL
0000 0000
57, 90
TABLAT
0000 0000
57, 90
PRODH
xxxx xxxx
57, 103
PRODL
xxxx xxxx
57, 103
INTCON
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
0000 000x
57, 107
INTCON2
RBPU
INTEDG0
INTEDG1
INTEDG2
TMR0IP
RBIP
1111 -1-1
57, 108
INT2IP
INT1IP
INT2IE
INT1IE
INT2IF
INT1IF
11-0 0-00
57, 109
INTCON3
INDF0
Uses contents of FSR0 to address data memory value of FSR0 not changed (not a physical register)
N/A
57, 82
POSTINC0
Uses contents of FSR0 to address data memory value of FSR0 post-incremented (not a physical register)
N/A
57, 82
POSTDEC0
Uses contents of FSR0 to address data memory value of FSR0 post-decremented (not a physical register)
N/A
57, 82
PREINC0
Uses contents of FSR0 to address data memory value of FSR0 pre-incremented (not a physical register)
N/A
57, 82
PLUSW0
Uses contents of FSR0 to address data memory value of FSR0 pre-incremented (not a physical register)
value of FSR0 offset by W
N/A
57, 82
FSR0H
---- 0000
57, 82
FSR0L
xxxx xxxx
57, 82
WREG
Working Register
xxxx xxxx
57
INDF1
Uses contents of FSR1 to address data memory value of FSR1 not changed (not a physical register)
N/A
57, 82
POSTINC1
Uses contents of FSR1 to address data memory value of FSR1 post-incremented (not a physical register)
N/A
57, 82
POSTDEC1
Uses contents of FSR1 to address data memory value of FSR1 post-decremented (not a physical register)
N/A
57, 82
PREINC1
Uses contents of FSR1 to address data memory value of FSR1 pre-incremented (not a physical register)
N/A
57, 82
PLUSW1
Uses contents of FSR1 to address data memory value of FSR1 pre-incremented (not a physical register)
value of FSR1 offset by W
N/A
57, 82
---- 0000
58, 82
FSR1H
FSR1L
BSR
xxxx xxxx
58, 82
---- 0000
58, 69
INDF2
Uses contents of FSR2 to address data memory value of FSR2 not changed (not a physical register)
N/A
58, 82
POSTINC2
Uses contents of FSR2 to address data memory value of FSR2 post-incremented (not a physical register)
N/A
58, 82
POSTDEC2
Uses contents of FSR2 to address data memory value of FSR2 post-decremented (not a physical register)
N/A
58, 82
PREINC2
Uses contents of FSR2 to address data memory value of FSR2 pre-incremented (not a physical register)
N/A
58, 82
PLUSW2
Uses contents of FSR2 to address data memory value of FSR2 pre-incremented (not a physical register)
value of FSR2 offset by W
N/A
58, 82
---- 0000
58, 82
FSR2H
FSR2L
STATUS
Legend:
Note 1:
2:
3:
4:
5:
6:
7:
OV
DC
xxxx xxxx
58, 82
---x xxxx
58, 80
Preliminary
DS41303C-page 77
PIC18F2XK20/4XK20
TABLE 5-2:
File Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Details
on page:
TMR0H
0000 0000
58, 153
TMR0L
xxxx xxxx
58, 153
58, 151
T0CON
TMR0ON
T08BIT
T0CS
T0SE
PSA
T0PS2
T0PS1
T0PS0
1111 1111
OSCCON
IDLEN
IRCF2
IRCF1
IRCF0
OSTS
IOFS
SCS1
SCS0
0011 qq00
27, 58
HLVDCON
VDIRMAG
IRVST
HLVDEN
HLVDL3
HLVDL2
HLVDL1
HLVDL0
0-00 0101
58, 287
SWDTEN
--- ---0
58, 303
IPEN
SBOREN(1)
RI
TO
PD
POR
BOR
0q-1 11q0
49, 56,
116
WDTCON
RCON
TMR1H
xxxx xxxx
58, 161
TMR1L
xxxx xxxx
58, 161
T1CON
RD16
T1RUN
T1CKPS1
T1CKPS0
T1OSCEN
T1SYNC
0000 0000
58, 155
TMR2
Timer2 Register
0000 0000
58, 164
PR2
1111 1111
58, 164
-000 0000
58, 163
xxxx xxxx
58, 197,
198
T2CON
T2OUTPS3
T2OUTPS2
T2OUTPS1
T2OUTPS0
TMR2ON
TMR1CS
TMR1ON
T2CKPS1
T2CKPS0
SSPBUF
SSPADD
SSP Address Register in I2C Slave Mode. SSP Baud Rate Reload Register in I2C Master Mode.
0000 0000
58, 198
SSPSTAT
SMP
CKE
D/A
R/W
UA
BF
0000 0000
58, 190,
200
SSPCON1
WCOL
SSPOV
SSPEN
CKP
SSPM3
SSPM2
SSPM1
SSPM0
0000 0000
58, 191,
201
GCEN
ACKSTAT
ACKDT
ACKEN
RCEN
PEN
RSEN
SEN
SSPCON2
0000 0000
58, 202
ADRESH
xxxx xxxx
59, 271
ADRESL
xxxx xxxx
59, 271
ADCON0
CHS3
CHS2
CHS1
CHS0
GO/DONE
ADON
--00 0000
59, 265
ADCON1
VCFG1
VCFG0
--00 ----
59, 266
ADFM
ACQT2
ACQT1
ACQT0
ADCS2
ADCS1
ADCS0
ADCON2
0-00 0000
59, 267
CCPR1H
xxxx xxxx
59, 140
CCPR1L
xxxx xxxx
59, 140
0000 0000
59, 169
59, 140
CCP1CON
P1M1
P1M0
DC1B1
DC1B0
CCP1M3
CCP1M2
CCP1M1
CCP1M0
CCPR2H
xxxx xxxx
CCPR2L
xxxx xxxx
59, 140
CCP2M0
--00 0000
59, 139
CCP2CON
DC2B1
DC2B0
CCP2M3
CCP2M2
CCP2M1
PSTRCON
STRSYNC
STRD
STRC
STRB
STRA
---0 0001
59, 183
BAUDCTL
ABDOVF
RCIDL
DTRXP
CKTXP
BRG16
WUE
ABDEN
0100 0-00
59, 242
PWM1CON
PRSEN
PDC6
PDC5
PDC4
PDC3
PDC2
PDC1
PDC0
0000 0000
59, 182
ECCP1AS
ECCPASE
ECCPAS2
ECCPAS1
ECCPAS0
PSSAC1
PSSAC0
PSSBD1
PSSBD0
0000 0000
59, 179
CVRCON
CVREN
CVROE
CVRR
CVRSS
CVR3
CVR2
CVR1
CVR0
0000 0000
59, 285
CVRCON2
FVREN
FVRST
00-- ----
59, 286
TMR3H
xxxx xxxx
59, 168
TMR3L
xxxx xxxx
59, 168
0000 0000
59, 165
T3CON
RD16
Legend:
Note 1:
2:
3:
4:
5:
6:
7:
T3CCP2
T3CKPS1
T3CKPS0
T3CCP1
T3SYNC
TMR3CS
TMR3ON
DS41303C-page 78
Preliminary
PIC18F2XK20/4XK20
TABLE 5-2:
File Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Details
on page:
SPBRGH
0000 0000
59, 235
SPBRG
0000 0000
59, 235
RCREG
0000 0000
59, 232
TXREG
0000 0000
59, 231
TXSTA
CSRC
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
0000 0010
59, 240
RCSTA
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
0000 000x
59, 241
EEADR
EEADR7
EEADR6
EEADR5
EEADR4
EEADR3
EEADR2
EEADR1
EEADR0
EEADR9
EEADR8
EEADRH(7)
EEDATA
EECON2
EECON1
EEPGD
CFGS
FREE
WRERR
WREN
WR
RD
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
1111 1111
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
0000 0000
60, 111
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
0000 0000
60, 113
IPR1
PSPIP(2)
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
1111 1111
60, 114
PIR1
PSPIF(2)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
60, 110
PIE1
PSPIE(2)
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
0000 0000
60, 112
OSCTUNE
INTSRC
PLLEN(3)
TUN5
TUN4
TUN3
TUN2
TUN1
TUN0
0q00 0000
31, 60
IBF
OBF
IBOV
PSPMODE
TRISE2
TRISE1
TRISE0
0000 -111
60, 132
TRISE(2)
TRISD(2)
1111 1111
60, 128
TRISC
1111 1111
60, 125
TRISB
1111 1111
60, 122
TRISA
TRISA7(5)
TRISA6(5)
LATE(2)
1111 1111
60, 119
---- -xxx
60, 131
LATD(2)
xxxx xxxx
60, 128
LATC
xxxx xxxx
60, 125
LATB
xxxx xxxx
60, 122
LATA
PORTE
LATA7(5)
LATA6(5)
RE3(4)
xxxx xxxx
60, 119
RE2(2)
RE1(2)
RE0(2)
---- x000
60, 131
PORTD(2)
RD7
RD6
RD5
RD4
RD3
RD2
RD1
RD0
xxxx xxxx
60, 128
PORTC
RC7
RC6
RC5
RC4
RC3
RC2
RC1
RC0
xxxx xxxx
60, 125
PORTB
RB7
RB6
RB5
RB4
RB3
RB2
RB1
RB0
xxx0 0000
60, 122
PORTA
RA7(5)
RA6(5)
RA5
RA4
RA3
RA2
RA1
RA0
xx0x 0000
60, 119
ANS12
ANS11
ANS10
ANS9
ANS8
---1 1111
60, 135
ANSEL
ANS7(2)
ANS6(2)
ANS5(2)
ANS4
ANS3
ANS2
ANS1
ANS0
1111 1111
60, 134
IOCB
IOCB7
IOCB6
IOCB5
IOCB4
0000 ----
60, 122
WPUB
WPUB7
WPUB6
WPUB5
WPUB4
WPUB3
WPUB2
WPUB1
WPUB0
1111 1111
60, 122
CM1CON0
C1ON
C1OUT
C1OE
C1POL
C1SP
C1R
C1CH1
C1CH0
0000 0000
60, 278
CM2CON0
C2ON
C2OUT
C2OE
C2POL
C2SP
C2R
C2CH1
C2CH0
0000 0000
60, 279
CM2CON1
MC1OUT
MC2OUT
C1RSEL
C2RSEL
0000 ----
61, 281
ANSELH(6)
SLRCON
SLRE
SLRD
SLRC
SLRB
SLRA
---1 1111
61, 136
SSPMSK
MSK7
MSK6
MSK5
MSK4
MSK3
MSK2
MSK1
MSK0
1111 1111
61, 209
Legend:
Note 1:
2:
3:
4:
5:
6:
7:
Preliminary
DS41303C-page 79
PIC18F2XK20/4XK20
5.3.5
STATUS REGISTER
REGISTER 5-2:
U-0
U-0
R/W-x
N
R/W-x
OV
R/W-x
R/W-x
R/W-x
(1)
DC
bit 7
C(1)
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7-5
Unimplemented: Read as 0
bit 4
N: Negative bit
This bit is used for signed arithmetic (twos complement). It indicates whether the result was negative
(ALU MSB = 1).
1 = Result was negative
0 = Result was positive
bit 3
bit 2
Z: Zero bit
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
bit 1
bit 0
Note 1:
For Borrow, the polarity is reversed. A subtraction is executed by adding the twos complement of the
second operand. For rotate (RRF, RLF) instructions, this bit is loaded with either the high-order or low-order
bit of the source register.
DS41303C-page 80
Preliminary
PIC18F2XK20/4XK20
5.4
Note:
Inherent
Literal
Direct
Indirect
5.4.3
5.4.1
Many PIC18 control instructions do not need any argument at all; they either perform an operation that globally affects the device or they operate implicitly on one
register. This addressing mode is known as Inherent
Addressing. Examples include SLEEP, RESET and DAW.
Other instructions work in a similar way but require an
additional explicit argument in the opcode. This is
known as Literal Addressing mode because they
require some literal value as an argument. Examples
include ADDLW and MOVLW, which respectively, add or
move a literal value to the W register. Other examples
include CALL and GOTO, which include a 20-bit
program memory address.
EXAMPLE 5-5:
NEXT
5.4.2
INDIRECT ADDRESSING
LFSR
CLRF
DIRECT ADDRESSING
BTFSS
BRA
CONTINUE
In the core PIC18 instruction set, bit-oriented and byteoriented instructions use some version of direct
addressing by default. All of these instructions include
some 8-bit literal address as their Least Significant
Byte. This address specifies either a register address in
one of the banks of data RAM (Section 5.3.3 General
Purpose Register File) or a location in the Access
Bank (Section 5.3.2 Access Bank) as the data
source for the instruction.
Preliminary
DS41303C-page 81
PIC18F2XK20/4XK20
5.4.3.1
5.4.3.2
At the core of indirect addressing are three sets of registers: FSR0, FSR1 and FSR2. Each represents a pair
of 8-bit registers, FSRnH and FSRnL. Each FSR pair
holds a 12-bit value, therefore the four upper bits of the
FSRnH register are not used. The 12-bit FSR value can
address the entire range of the data memory in a linear
fashion. The FSR register pairs, then, serve as pointers
to data memory locations.
FIGURE 5-10:
INDIRECT ADDRESSING
000h
Bank 0
ADDWF, INDF1, 1
100h
Bank 1
200h
...uses the 12-bit address stored in
the FSR pair associated with that
register....
300h
FSR1H:FSR1L
7
x x x x 1 1 1 0
Bank 2
Bank 3
through
Bank 13
1 1 0 0 1 1 0 0
Bank 14
F00h
FFFh
Bank 15
Data Memory
DS41303C-page 82
Preliminary
PIC18F2XK20/4XK20
Operations on the FSRs with POSTDEC, POSTINC
and PREINC affect the entire register pair; that is, rollovers of the FSRnL register from FFh to 00h carry over
to the FSRnH register. On the other hand, results of
these operations do not change the value of any flags
in the STATUS register (e.g., Z, N, OV, etc.).
The PLUSW register can be used to implement a form
of indexed addressing in the data memory space. By
manipulating the value in the W register, users can
reach addresses that are fixed offsets from pointer
addresses. In some applications, this can be used to
implement some powerful program control structure,
such as software stacks, inside of data memory.
5.4.3.3
5.5
5.5.1
5.5.2
INSTRUCTIONS AFFECTED BY
INDEXED LITERAL OFFSET MODE
Preliminary
DS41303C-page 83
PIC18F2XK20/4XK20
FIGURE 5-11:
000h
060h
Bank 0
100h
00h
Bank 1
through
Bank 14
60h
Valid range
for f
Access RAM
F00h
FFh
Bank 15
F60h
SFRs
FFFh
Data Memory
000h
060h
Bank 0
100h
001001da ffffffff
Bank 1
through
Bank 14
FSR2H
FSR2L
F00h
Bank 15
F60h
SFRs
FFFh
Data Memory
BSR
00000000
000h
060h
Bank 0
100h
Bank 1
through
Bank 14
001001da ffffffff
F00h
Bank 15
F60h
SFRs
FFFh
DS41303C-page 84
Data Memory
Preliminary
PIC18F2XK20/4XK20
5.5.3
FIGURE 5-12:
Remapping of the Access Bank applies only to operations using the Indexed Literal Offset mode. Operations
that use the BSR (Access RAM bit is 1) will continue
to use direct addressing as before.
5.6
Example Situation:
ADDWF f, d, a
FSR2H:FSR2L = 120h
Locations in the region
from the FSR2 pointer
(120h) to the pointer plus
05Fh (17Fh) are mapped
to the bottom of the
Access RAM (000h-05Fh).
000h
Bank 0
100h
120h
17Fh
200h
Bank 1
Window
00h
Bank 1
Bank 1 Window
5Fh
60h
Bank 2
through
Bank 14
SFRs
FFh
Access Bank
F00h
Bank 15
F60h
FFFh
SFRs
Data Memory
Preliminary
DS41303C-page 85
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 86
Preliminary
PIC18F2XK20/4XK20
6.0
TABLE 6-1:
Erase Block
Size (bytes)
PIC18F43K20,
PIC18F23K20
64
PIC18F24K20,
PIC18F25K20,
PIC18F44K20,
PIC18F45K20
32
64
PIC18F26K20,
PIC18F46K20
64
64
Device
FIGURE 6-1:
6.1
Program Memory
Table Pointer(1)
TBLPTRU
TBLPTRH
TABLAT
Program Memory
(TBLPTR)
Preliminary
DS41303C-page 87
PIC18F2XK20/4XK20
FIGURE 6-2:
TBLPTRU
TBLPTRH
Holding Registers
Table Latch (8-bit)
TBLPTRL
TABLAT
Program Memory
(TBLPTR<MSBs>)
Note 1: During table writes the Table Pointer does not point directly to Program Memory. The LSBs of TBLPRTL
actually point to an address within the write block holding registers. The MSBs of the Table Pointer determine where the write block will eventually be written. The process for writing the holding registers to the
program memory array is discussed in Section 6.5 Writing to Flash Program Memory.
6.2
Control Registers
EECON1 register
EECON2 register
TABLAT register
TBLPTR registers
6.2.1
The FREE bit allows the program memory erase operation. When FREE is set, an erase operation is initiated
on the next WR command. When FREE is clear, only
writes are enabled.
The WREN bit, when set, will allow a write operation.
The WREN bit is clear on power-up.
DS41303C-page 88
Preliminary
PIC18F2XK20/4XK20
REGISTER 6-1:
R/W-x
R/W-x
U-0
R/W-0
R/W-x
R/W-0
R/S-0
R/S-0
EEPGD
CFGS
FREE
WRERR
WREN
WR
RD
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
0 = Bit is cleared
1 = Bit is set
x = Bit is unknown
bit 7
bit 6
bit 5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1:
When a WRERR occurs, the EEPGD and CFGS bits are not cleared. This allows tracing of the
error condition.
Preliminary
DS41303C-page 89
PIC18F2XK20/4XK20
6.2.2
6.2.3
When a TBLWT is executed the byte in the TABLAT register is written, not to Flash memory but, to a holding
register in preparation for a program memory write. The
holding registers constitute a write block which varies
depending on the device (See Table 6-1).The 3, 4, or 5
LSbs of the TBLPTRL register determine which specific
address within the holding register block is written to.
The MSBs of the Table Pointer have no effect during
TBLWT operations.
6.2.4
TABLE 6-2:
Example
TBLRD*
TBLWT*
TBLRD*+
TBLWT*+
TBLRD*TBLWT*-
TBLRD+*
TBLWT+*
FIGURE 6-3:
21
16
15
TBLPTRH
TABLE ERASE/WRITE
TBLPTR<21:n+1>(1)
TBLPTRL
TABLE WRITE
TBLPTR<n:0>(1)
DS41303C-page 90
Preliminary
PIC18F2XK20/4XK20
6.3
FIGURE 6-4:
Program Memory
TBLPTR = xxxxx1
Instruction Register
(IR)
EXAMPLE 6-1:
FETCH
TBLRD
TBLPTR = xxxxx0
TABLAT
Read Register
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
CODE_ADDR_UPPER
TBLPTRU
CODE_ADDR_HIGH
TBLPTRH
CODE_ADDR_LOW
TBLPTRL
READ_WORD
TBLRD*+
MOVF
MOVWF
TBLRD*+
MOVFW
MOVF
TABLAT, W
WORD_EVEN
TABLAT, W
WORD_ODD
Preliminary
DS41303C-page 91
PIC18F2XK20/4XK20
6.4
6.4.1
2.
3.
4.
5.
6.
7.
8.
EXAMPLE 6-2:
CODE_ADDR_UPPER
TBLPTRU
CODE_ADDR_HIGH
TBLPTRH
CODE_ADDR_LOW
TBLPTRL
BSF
BCF
BSF
BSF
BCF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
BSF
EECON1,
EECON1,
EECON1,
EECON1,
INTCON,
55h
EECON2
0AAh
EECON2
EECON1,
INTCON,
;
;
;
;
;
ERASE_BLOCK
Required
Sequence
DS41303C-page 92
EEPGD
CFGS
WREN
FREE
GIE
; write 55h
WR
GIE
; write 0AAh
; start erase (CPU stall)
; re-enable interrupts
Preliminary
PIC18F2XK20/4XK20
6.5
FIGURE 6-5:
The long write is necessary for programming the internal Flash. Instruction execution is halted during a long
write cycle. The long write will be terminated by the
internal programming timer.
The EEPROM on-chip timer controls the write time.
The write/erase voltages are generated by an on-chip
charge pump, rated to operate over the voltage range
of the device.
Note:
8
TBLPTR = xxxx00
TBLPTR = xxxx01
Holding Register
8
TBLPTR = xxxxYY(1)
TBLPTR = xxxx02
Holding Register
Holding Register
Holding Register
Program Memory
Note 1: YY = x7, xF, or 1F for 8, 16 or 32 byte write blocks, respectively.
6.5.1
8.
9.
10.
11.
12.
Disable interrupts.
Write 55h to EECON2.
Write 0AAh to EECON2.
Set the WR bit. This will begin the write cycle.
The CPU will stall for duration of the write (about
2 ms using internal timer).
13. Re-enable interrupts.
14. Repeat steps 6 to 13 for each block until all 64
bytes are written.
15. Verify the memory (table read).
This procedure will require about 6 ms to update each
write block of memory. An example of the required code
is given in Example 6-3.
Note:
Preliminary
DS41303C-page 93
PIC18F2XK20/4XK20
EXAMPLE 6-3:
D'64
COUNTER
BUFFER_ADDR_HIGH
FSR0H
BUFFER_ADDR_LOW
FSR0L
CODE_ADDR_UPPER
TBLPTRU
CODE_ADDR_HIGH
TBLPTRH
CODE_ADDR_LOW
TBLPTRL
TBLRD*+
MOVF
MOVWF
DECFSZ
BRA
TABLAT, W
POSTINC0
COUNTER
READ_BLOCK
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
BUFFER_ADDR_HIGH
FSR0H
BUFFER_ADDR_LOW
FSR0L
NEW_DATA_LOW
POSTINC0
NEW_DATA_HIGH
INDF0
; point to buffer
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
BCF
BSF
BSF
BCF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
BSF
TBLRD*MOVLW
MOVWF
MOVLW
MOVWF
CODE_ADDR_UPPER
TBLPTRU
CODE_ADDR_HIGH
TBLPTRH
CODE_ADDR_LOW
TBLPTRL
EECON1, EEPGD
EECON1, CFGS
EECON1, WREN
EECON1, FREE
INTCON, GIE
55h
EECON2
0AAh
EECON2
EECON1, WR
INTCON, GIE
MOVLW
MOVWF
MOVLW
MOVWF
BlockSize
COUNTER
D64/BlockSize
COUNTER2
MOVF
MOVWF
TBLWT+*
POSTINC0, W
TABLAT
; point to buffer
READ_BLOCK
;
;
;
;
;
MODIFY_WORD
ERASE_BLOCK
Required
Sequence
BUFFER_ADDR_HIGH
FSR0H
BUFFER_ADDR_LOW
FSR0L
;
;
;
;
;
; write 55h
;
;
;
;
;
write 0AAh
start erase (CPU stall)
re-enable interrupts
dummy read decrement
point to buffer
WRITE_BUFFER_BACK
; number of bytes in holding register
; number of write blocks in 64 bytes
WRITE_BYTE_TO_HREGS
DS41303C-page 94
Preliminary
;
;
;
;
PIC18F2XK20/4XK20
EXAMPLE 6-3:
COUNTER
WRITE_WORD_TO_HREGS
BSF
BCF
BSF
BCF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
DCFSZ
BRA
BSF
BCF
EECON1, EEPGD
EECON1, CFGS
EECON1, WREN
INTCON, GIE
55h
EECON2
0AAh
EECON2
EECON1, WR
COUNTER2
WRITE_BYTE_TO_HREGS
INTCON, GIE
EECON1, WREN
;
;
;
;
PROGRAM_MEMORY
Required
Sequence
6.5.2
WRITE VERIFY
UNEXPECTED TERMINATION OF
WRITE OPERATION
TABLE 6-3:
; write 55h
;
;
;
;
;
;
write 0AAh
start program (CPU stall)
repeat for remaining write blocks
re-enable interrupts
disable write to memory
6.5.4
6.5.3
PROTECTION AGAINST
SPURIOUS WRITES
6.6
Name
Bit 7
Bit 6
Bit 5
TBLPTRU
bit 21
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values on
page
57
57
57
TABLAT
INTCON
57
EECON2
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
59
EECON1
EEPGD
CFGS
FREE
WRERR
WREN
WR
RD
59
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
60
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
60
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
60
Legend: = unimplemented, read as 0. Shaded cells are not used during Flash/EEPROM access.
Preliminary
DS41303C-page 95
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 96
Preliminary
PIC18F2XK20/4XK20
7.0
The data EEPROM is a nonvolatile memory array, separate from the data RAM and program memory, which
is used for long-term storage of program data. It is not
directly mapped in either the register file or program
memory space but is indirectly addressed through the
Special Function Registers (SFRs). The EEPROM is
readable and writable during normal operation over the
entire VDD range.
Four SFRs are used to read and write to the data
EEPROM as well as the program memory. They are:
EECON1
EECON2
EEDATA
EEADR
EEADRH
7.2
7.1
The EECON1 register (Register 7-1) is the control register for data and program memory access. Control bit
EEPGD determines if the access will be to program or
data EEPROM memory. When the EEPGD bit is clear,
operations will access the data EEPROM memory.
When the EEPGD bit is set, program memory is
accessed.
Preliminary
DS41303C-page 97
PIC18F2XK20/4XK20
REGISTER 7-1:
R/W-x
R/W-x
U-0
R/W-0
R/W-x
R/W-0
R/S-0
R/S-0
EEPGD
CFGS
FREE
WRERR
WREN
WR
RD
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
0 = Bit is cleared
1 = Bit is set
x = Bit is unknown
bit 7
bit 6
bit 5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1:
When a WRERR occurs, the EEPGD and CFGS bits are not cleared. This allows tracing of the
error condition.
DS41303C-page 98
Preliminary
PIC18F2XK20/4XK20
7.3
7.4
7.5
EXAMPLE 7-1:
MOVLW
MOVWF
BCF
BCF
BSF
MOVF
EXAMPLE 7-2:
Required
Sequence
Write Verify
;
;
;
;
;
;
DATA_EE_ADDR_LOW
EEADR
DATA_EE_ADDR_HI
EEADRH
DATA_EE_DATA
EEDATA
EECON1, EEPGD
EECON1, CFGS
EECON1, WREN
INTCON, GIE
55h
EECON2
0AAh
EECON2
EECON1, WR
INTCON, GIE
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
BCF
EECON1, WREN
Preliminary
DS41303C-page 99
PIC18F2XK20/4XK20
7.6
7.7
7.8
EXAMPLE 7-3:
CLRF
BCF
BCF
BCF
BSF
EEADR
EECON1,
EECON1,
INTCON,
EECON1,
BSF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
BTFSC
BRA
INCFSZ
BRA
EECON1, RD
55h
EECON2
0AAh
EECON2
EECON1, WR
EECON1, WR
$-2
EEADR, F
LOOP
BCF
BSF
EECON1, WREN
INTCON, GIE
CFGS
EEPGD
GIE
WREN
Loop
DS41303C-page 100
;
;
;
;
;
;
;
;
;
;
;
;
;
Start at address 0
Set for memory
Set for Data EEPROM
Disable interrupts
Enable writes
Loop to refresh array
Read current address
Write 55h
Write 0AAh
Set WR bit to begin write
Wait for write to complete
; Increment address
; Not zero, do it again
; Disable writes
; Enable interrupts
Preliminary
PIC18F2XK20/4XK20
TABLE 7-1:
Name
Bit 6
INTCON
GIE/GIEH
PEIE/GIEL
EEADR
EEADR7
EEADR6
EEADRH
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
EEDATA
EECON2
EEADR9 EEADR8
Reset
Values
on page
57
59
59
59
59
EECON1
EEPGD
CFGS
FREE
WRERR
WREN
WR
RD
59
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
60
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
60
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
60
Legend: = unimplemented, read as 0. Shaded cells are not used during Flash/EEPROM access.
Preliminary
DS41303C-page 101
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 102
Preliminary
PIC18F2XK20/4XK20
8.0
8 x 8 HARDWARE MULTIPLIER
8.1
Introduction
EXAMPLE 8-1:
MOVF
MULWF
ARG1, W
ARG2
;
; ARG1 * ARG2 ->
; PRODH:PRODL
EXAMPLE 8-2:
8.2
8 x 8 UNSIGNED
MULTIPLY ROUTINE
8 x 8 SIGNED MULTIPLY
ROUTINE
MOVF
MULWF
ARG1, W
ARG2
BTFSC
SUBWF
ARG2, SB
PRODH, F
MOVF
BTFSC
SUBWF
ARG2, W
ARG1, SB
PRODH, F
;
;
;
;
;
Operation
TABLE 8-1:
Routine
8 x 8 unsigned
8 x 8 signed
16 x 16 unsigned
16 x 16 signed
Multiply Method
Program
Memory
(Words)
Cycles
(Max)
13
Hardware multiply
33
Hardware multiply
Time
@ 40 MHz
@ 10 MHz
@ 4 MHz
69
6.9 s
27.6 s
69 s
100 ns
400 ns
1 s
91
9.1 s
36.4 s
91 s
600 ns
2.4 s
6 s
21
242
24.2 s
96.8 s
242 s
28
28
2.8 s
11.2 s
28 s
52
254
25.4 s
102.6 s
254 s
Hardware multiply
35
40
4.0 s
16.0 s
40 s
Preliminary
DS41303C-page 103
PIC18F2XK20/4XK20
Example 8-3 shows the sequence to do a 16 x 16
unsigned multiplication. Equation 8-1 shows the
algorithm that is used. The 32-bit result is stored in four
registers (RES<3:0>).
EQUATION 8-1:
RES3:RES0
=
=
EXAMPLE 8-3:
16 x 16 UNSIGNED
MULTIPLICATION
ALGORITHM
ARG1H:ARG1L ARG2H:ARG2L
(ARG1H ARG2H 216) +
(ARG1H ARG2L 28) +
(ARG1L ARG2H 28) +
(ARG1L ARG2L)
EQUATION 8-2:
EXAMPLE 8-4:
16 x 16 UNSIGNED
MULTIPLY ROUTINE
MOVF
MULWF
ARG1L, W
ARG2L
MOVFF
MOVFF
PRODH, RES1
PRODL, RES0
MOVF
MULWF
ARG1H, W
ARG2H
MOVFF
MOVFF
PRODH, RES3
PRODL, RES2
MOVF
MULWF
ARG1L, W
ARG2H
MOVF
ADDWF
MOVF
ADDWFC
CLRF
ADDWFC
PRODL, W
RES1, F
PRODH, W
RES2, F
WREG
RES3, F
MOVF
MULWF
ARG1H, W
ARG2L
MOVF
ADDWF
MOVF
ADDWFC
CLRF
ADDWFC
PRODL, W
RES1, F
PRODH, W
RES2, F
WREG
RES3, F
; ARG1L * ARG2L->
; PRODH:PRODL
;
;
ARG1L * ARG2H->
PRODH:PRODL
Add cross
products
ARG1H * ARG2L->
PRODH:PRODL
Add cross
products
MOVFF
MOVFF
PRODH, RES1
PRODL, RES0
MOVF
MULWF
ARG1H, W
ARG2H
MOVFF
MOVFF
PRODH, RES3
PRODL, RES2
MOVF
MULWF
ARG1L, W
ARG2H
MOVF
ADDWF
MOVF
ADDWFC
CLRF
ADDWFC
PRODL, W
RES1, F
PRODH, W
RES2, F
WREG
RES3, F
MOVF
MULWF
ARG1H, W
ARG2L
MOVF
ADDWF
MOVF
ADDWFC
CLRF
ADDWFC
PRODL, W
RES1, F
PRODH, W
RES2, F
WREG
RES3, F
BTFSS
BRA
MOVF
SUBWF
MOVF
SUBWFB
ARG2H, 7
SIGN_ARG1
ARG1L, W
RES2
ARG1H, W
RES3
; ARG2H:ARG2L neg?
; no, check ARG1
;
;
;
ARG1H, 7
CONT_CODE
ARG2L, W
RES2
ARG2H, W
RES3
; ARG1H:ARG1L neg?
; no, done
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
DS41303C-page 104
ARG1L, W
ARG2L
;
;
;
;
;
;
;
;
;
;
MOVF
MULWF
;
;
;
;
;
;
;
;
;
16 x 16 SIGNED
MULTIPLY ROUTINE
;
; ARG1H * ARG2H->
; PRODH:PRODL
;
;
16 x 16 SIGNED
MULTIPLICATION
ALGORITHM
;
SIGN_ARG1
BTFSS
BRA
MOVF
SUBWF
MOVF
SUBWFB
;
CONT_CODE
:
Preliminary
PIC18F2XK20/4XK20
9.0
INTERRUPTS
9.2
RCON
INTCON
INTCON2
INTCON3
PIR1, PIR2
PIE1, PIE2
IPR1, IPR2
It is recommended that the Microchip header files supplied with MPLAB IDE be used for the symbolic bit
names in these registers. This allows the assembler/
compiler to automatically take care of the placement of
these bits within the specified register.
In general, interrupt sources have three bits to control
their operation. They are:
Flag bit to indicate that an interrupt event
occurred
Enable bit that allows program execution to
branch to the interrupt vector address when the
flag bit is set
Priority bit to select high priority or low priority
9.1
Mid-Range Compatibility
9.3
Interrupt Response
Interrupt Priority
Preliminary
DS41303C-page 105
PIC18F2XK20/4XK20
FIGURE 9-1:
TMR0IF
TMR0IE
TMR0IP
RBIF
RBIE
RBIP
INT0IF
INT0IE
Wake-up if in
Idle or Sleep modes
(1)
Interrupt to CPU
Vector to Location
0008h
INT1IF
INT1IE
INT1IP
INT2IF
INT2IE
INT2IP
SSPIF
SSPIE
SSPIP
GIEH/GIE
ADIF
ADIE
ADIP
IPEN
IPEN
GIEL/PEIE
RCIF
RCIE
RCIP
IPEN
Additional Peripheral Interrupts
High Priority Interrupt Generation
Low Priority Interrupt Generation
SSPIF
SSPIE
SSPIP
ADIF
ADIE
ADIP
RCIF
RCIE
RCIP
Interrupt to CPU
Vector to Location
0018h
TMR0IF
TMR0IE
TMR0IP
RBIF
RBIE
RBIP
(1)
GIEH/GIE
GIEL/PEIE
INT1IF
INT1IE
INT1IP
Additional Peripheral Interrupts
INT2IF
INT2IE
INT2IP
Note
1:
The RBIF interrupt also requires the individual pin IOCB enables.
DS41303C-page 106
Preliminary
PIC18F2XK20/4XK20
9.4
INTCON Registers
Note:
REGISTER 9-1:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-x
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1:
2:
x = Bit is unknown
A mismatch condition will continue to set the RBIF bit. Reading PORTB will end the
mismatch condition and allow the bit to be cleared.
RB port change interrupts also require the individual pin IOCB enables.
Preliminary
DS41303C-page 107
PIC18F2XK20/4XK20
REGISTER 9-2:
R/W-1
R/W-1
R/W-1
R/W-1
U-0
R/W-1
U-0
R/W-1
RBPU
INTEDG0
INTEDG1
INTEDG2
TMR0IP
RBIP
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
bit 4
bit 3
Unimplemented: Read as 0
bit 2
bit 1
Unimplemented: Read as 0
bit 0
Note:
DS41303C-page 108
Preliminary
PIC18F2XK20/4XK20
REGISTER 9-3:
R/W-1
R/W-1
U-0
R/W-0
R/W-0
U-0
R/W-0
R/W-0
INT2IP
INT1IP
INT2IE
INT1IE
INT2IF
INT1IF
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
Unimplemented: Read as 0
bit 1
bit 0
Note:
x = Bit is unknown
Preliminary
DS41303C-page 109
PIC18F2XK20/4XK20
9.5
PIR Registers
The PIR registers contain the individual flag bits for the
peripheral interrupts. Due to the number of peripheral
interrupt sources, there are two Peripheral Interrupt
Request Flag registers (PIR1 and PIR2).
REGISTER 9-4:
R/W-0
R/W-0
R-0
R-0
R/W-0
R/W-0
R/W-0
R/W-0
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1: The PSPIF bit is unimplemented on 28-pin devices and will read as 0.
DS41303C-page 110
Preliminary
PIC18F2XK20/4XK20
REGISTER 9-5:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
Preliminary
DS41303C-page 111
PIC18F2XK20/4XK20
9.6
PIE Registers
REGISTER 9-6:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
PSPIE(1)
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1:
x = Bit is unknown
DS41303C-page 112
Preliminary
PIC18F2XK20/4XK20
REGISTER 9-7:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
Preliminary
x = Bit is unknown
DS41303C-page 113
PIC18F2XK20/4XK20
9.7
IPR Registers
The IPR registers contain the individual priority bits for the
peripheral interrupts. Due to the number of peripheral
interrupt sources, there are two Peripheral Interrupt
Priority registers (IPR1 and IPR2). Using the priority bits
requires that the Interrupt Priority Enable (IPEN) bit be
set.
REGISTER 9-8:
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
PSPIP(1)
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5
bit 4
x = Bit is unknown
1 = High priority
0 = Low priority
bit 3
bit 2
bit 1
bit 0
Note 1: The PSPIF bit is unimplemented on 28-pin devices and will read as 0.
DS41303C-page 114
Preliminary
PIC18F2XK20/4XK20
REGISTER 9-9:
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
Preliminary
x = Bit is unknown
DS41303C-page 115
PIC18F2XK20/4XK20
9.8
RCON Register
REGISTER 9-10:
R/W-0
IPEN
SBOREN
U-0
(1)
R/W-1
R-1
RI
TO
R-1
R/W-0
PD
(1)
R/W-0
POR
bit 7
BOR
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1: Actual Reset values are determined by device configuration and the nature of the device Reset.
See Register 4-1 for additional information.
DS41303C-page 116
Preliminary
PIC18F2XK20/4XK20
9.9
9.10
TMR0 Interrupt
9.11
PORTB Interrupt-on-Change
9.12
EXAMPLE 9-1:
MOVWF
W_TEMP
MOVFF
STATUS, STATUS_TEMP
MOVFF
BSR, BSR_TEMP
;
; USER ISR CODE
;
MOVFF
BSR_TEMP, BSR
MOVF
W_TEMP, W
MOVFF
STATUS_TEMP, STATUS
; Restore BSR
; Restore WREG
; Restore STATUS
Preliminary
DS41303C-page 117
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 118
Preliminary
PIC18F2XK20/4XK20
10.0
I/O PORTS
FIGURE 10-1:
Q
I/O pin(1)
CK
Data Latch
D
WR TRIS
Note:
D
WR LAT
or Port
RD LAT
Data
Bus
CK
TRIS Latch
Input
Buffer
EXAMPLE 10-1:
RD TRIS
CLRF
PORTA
CLRF
LATA
MOVLW
MOVWF
MOVLW
E0h
ANSEL
0CFh
MOVWF
TRISA
ENEN
RD Port
Note 1:
10.1
INITIALIZING PORTA
;
;
;
;
;
;
;
;
;
;
;
;
;
Initialize PORTA by
clearing output
data latches
Alternate method
to clear output
data latches
Configure I/O
for digital inputs
Value used to
initialize data
direction
Set RA<3:0> as inputs
RA<5:4> as outputs
Preliminary
DS41303C-page 119
PIC18F2XK20/4XK20
TABLE 10-1:
Pin
Function
TRIS
Setting
I/O
I/O
Type
RA0/AN0/C12IN0-
RA0
DIG
TTL
AN0
ANA
C12IN0-
ANA
RA1
DIG
TTL
AN1
ANA
C12IN1-
ANA
RA2
DIG
TTL
AN2
ANA
C2IN+
ANA
RA1/AN1/C12IN1-
RA2/AN2/C2IN+
VREF-/CVREF
RA3/AN3/C1IN+/
VREF+
RA4/T0CKI/C1OUT
VREF-
ANA
CVREF
ANA
RA3
DIG
TTL
AN3
ANA
C1IN+
ANA
VREF+
ANA
RA4
DIG
ST
ST
T0CKI
RA5/AN4/SS/
HLVDIN/C2OUT
OSC2/CLKOUT/
RA6
Legend:
Description
C1OUT
DIG
RA5
DIG
TTL
AN4
ANA
SS
TTL
HLVDIN
ANA
C2OUT
DIG
RA6
DIG
LATA<6> data output. Enabled in RCIO, INTIO2 and ECIO modes only.
TTL
OSC2
ANA
CLKOUT
DIG
DIG = Digital level output; TTL = TTL input buffer; ST = Schmitt Trigger input buffer; ANA = Analog level input/output;
x = Dont care (TRIS bit does not affect port direction or is overridden for this option).
DS41303C-page 120
Preliminary
PIC18F2XK20/4XK20
TABLE 10-1:
Pin
Function
TRIS
Setting
I/O
I/O
Type
OSC1/CLKIN/RA7
RA7
DIG
Legend:
Description
LATA<7> data output. Disabled in external oscillator modes.
TTL
OSC1
ANA
CLKIN
ANA
DIG = Digital level output; TTL = TTL input buffer; ST = Schmitt Trigger input buffer; ANA = Analog level input/output;
x = Dont care (TRIS bit does not affect port direction or is overridden for this option).
TABLE 10-2:
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
RA7(1)
RA6(1)
RA5
RA4
RA3
RA2
RA1
RA0
60
LATA
LATA7(1)
LATA6(1)
TRISA
Name
PORTA
60
60
ANS7(2)
ANS6(2)
ANS5(2)
ANS4
ANS3
ANS2
ANS1
ANS0
60
SLRCON
SLRE
SLRD
SLRC
SLRB
SLRA
61
ANSEL
CM1CON
C1ON
C1OUT
C1OE
C1POL
C1SP
C1R
C1CH1
C1CH0
60
CM2CON
C2ON
C2OUT
C2OE
C2POL
C2SP
C2R
C2CH1
C2CH0
60
CVRCON
CVREN
CVROE
CVRR
CVRSS
CVR3
CVR2
CVR1
CVR0
59
Preliminary
DS41303C-page 121
PIC18F2XK20/4XK20
10.2
10.3.2
PORTB is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISB. Setting a
TRISB bit (= 1) will make the corresponding PORTB
pin an input (i.e., disable the output driver). Clearing a
TRISB bit (= 0) will make the corresponding PORTB
pin an output (i.e., enable the output driver and put the
contents of the output latch on the selected pin).
The Data Latch register (LATB) is also memory
mapped. Read-modify-write operations on the LATB
register read and write the latched output value for
PORTB.
EXAMPLE 10-2:
CLRF
CLRF
CLRF
MOVLW
MOVWF
10.3
INITIALIZING PORTB
PORTB
; Initialize PORTB by
; clearing output
; data latches
LATB
; Alternate method
; to clear output
; data latches
ANSELH ; Set RB<4:0> as
; digital I/O pins
;(required if config bit
; PBADEN is set)
0CFh
; Value used to
; initialize data
; direction
TRISB
; Set RB<3:0> as inputs
; RB<5:4> as outputs
; RB<7:6> as inputs
a)
Any read or write of PORTB to clear the mismatch condition (except when PORTB is the
source or destination of a MOVFF instruction).
Clear the flag bit, RBIF.
b)
WEAK PULL-UPS
10.3.1
DS41303C-page 122
INTERRUPT-ON-CHANGE
10.3.3
Preliminary
PIC18F2XK20/4XK20
TABLE 10-3:
Pin
RB0/INT0/FLT0/
AN12
RB1/INT1/AN10/
C12IN3-/P1C
RB2/INT2/AN8/
P1B
RB3/AN9/C12IN2-/
CCP2
RB4/KBI0/AN11/
P1D
RB5/KBI1/PGM
Legend:
Note 1:
2:
3:
TRIS
Setting
I/O
I/O
Type
RB0
DIG
TTL
INT0
ST
Description
FLT0
ST
AN12
ANA
RB1
DIG
TTL
INT1
ST
AN10
ANA
C12IN3-
ANA
P1C
DIG
RB2
DIG
TTL
INT2
ST
AN8
ANA
P1B
DIG
RB3
DIG
TTL
AN9
ANA
C12IN2-
ANA
CCP2(2)
DIG
ST
DIG
TTL
RB4
KBI0
TTL
Interrupt-on-pin change.
AN11
ANA
P1D
DIG
RB5
DIG
TTL
KBI1
TTL
Interrupt-on-pin change.
PGM
ST
DIG = Digital level output; TTL = TTL input buffer; ST = Schmitt Trigger input buffer; ANA = Analog level input/output;
x = Dont care (TRIS bit does not affect port direction or is overridden for this option).
Configuration on POR is determined by the PBADEN Configuration bit. Pins are configured as analog inputs by default
when PBADEN is set and digital inputs when PBADEN is cleared.
Alternate assignment for CCP2 when the CCP2MX Configuration bit is 0. Default assignment is RC1.
All other pin functions are disabled when ICSP or ICD are enabled.
Preliminary
DS41303C-page 123
PIC18F2XK20/4XK20
TABLE 10-3:
Pin
Function
TRIS
Setting
I/O
I/O
Type
RB6
DIG
RB6/KBI2/PGC
TTL
KBI2
TTL
Interrupt-on-pin change.
PGC
ST
Serial execution (ICSP) clock input for ICSP and ICD operation.(3)
RB7
DIG
TTL
KBI3
TTL
Interrupt-on-pin change.
PGD
DIG
ST
RB7/KBI3/PGD
Legend:
Note 1:
2:
3:
DIG = Digital level output; TTL = TTL input buffer; ST = Schmitt Trigger input buffer; ANA = Analog level input/output;
x = Dont care (TRIS bit does not affect port direction or is overridden for this option).
Configuration on POR is determined by the PBADEN Configuration bit. Pins are configured as analog inputs by default
when PBADEN is set and digital inputs when PBADEN is cleared.
Alternate assignment for CCP2 when the CCP2MX Configuration bit is 0. Default assignment is RC1.
All other pin functions are disabled when ICSP or ICD are enabled.
TABLE 10-4:
Name
PORTB
Description
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
RB7
RB6
RB5
RB4
RB3
RB2
RB1
RB0
LATB
TRISB
WPUB6
WPUB5
WPUB4
IOCB
IOCB7
IOCB6
IOCB5
IOCB4
SLRE
SLRD
TMR0IE
INT0IE
INTCON
GIE/GIEH PEIE/GIEL
INTCON2
RBPU
INTCON3
INT2IP
ANSELH
60
60
60
WPUB
SLRCON
Reset
Values
on page
WPUB3
WPUB2
WPUB1
WPUB0
60
60
SLRC
SLRB
SLRA
61
RBIE
TMR0IF
INT0IF
RBIF
57
TMR0IP
RBIP
57
INT1IP
INT2IE
INT1IE
INT2IF
INT1IF
57
ANS12
ANS11
ANS10
ANS9
ANS8
60
DS41303C-page 124
Preliminary
PIC18F2XK20/4XK20
10.4
EXAMPLE 10-3:
PORTC is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISC. Setting a
TRISC bit (= 1) will make the corresponding PORTC
pin an input (i.e., disable the output driver). Clearing a
TRISC bit (= 0) will make the corresponding PORTC
pin an output (i.e., enable the output driver and put the
contents of the output latch on the selected pin).
The Data Latch register (LATC) is also memory
mapped. Read-modify-write operations on the LATC
register read and write the latched output value for
PORTC.
CLRF
PORTC
CLRF
LATC
MOVLW
0CFh
MOVWF
TRISC
INITIALIZING PORTC
;
;
;
;
;
;
;
;
;
;
;
;
Initialize PORTC by
clearing output
data latches
Alternate method
to clear output
data latches
Value used to
initialize data
direction
Set RC<3:0> as inputs
RC<5:4> as outputs
RC<7:6> as inputs
Preliminary
DS41303C-page 125
PIC18F2XK20/4XK20
TABLE 10-5:
Pin
TRIS
Setting
I/O
I/O
Type
RC0
DIG
RC0/T1OSO/
T13CKI
RC1/T1OSI/CCP2
RC2/CCP1/P1A
ST
ANA
T13CKI
ST
RC1
DIG
ST
T1OSI
ANA
CCP2(1)
DIG
CCP2 compare and PWM output; takes priority over port data.
ST
DIG
ST
DIG
ST
P1A
DIG
RC3
DIG
ST
DIG
SPI clock output (MSSP module); takes priority over port data.
RC2
SCK
SCL
RC4/SDI/SDA
RC5/SDO
RC7/RX/DT
Legend:
Note 1:
RC4
ST
DIG
I2C clock output (MSSP module); takes priority over port data.
I C/SMB I2C clock input (MSSP module); input type depends on module setting.
DIG
ST
SDI
ST
SDA
DIG
I2C data output (MSSP module); takes priority over port data.
DIG
ST
SDO
DIG
SPI data output (MSSP module); takes priority over port data.
RC6
DIG
RC5
RC6/TX/CK
T1OSO
CCP1
RC3/SCK/SCL
Description
I2C/SMB I2C data input (MSSP module); input type depends on module setting.
LATC<5> data output.
ST
TX
DIG
CK
DIG
ST
DIG
ST
RX
ST
DT
DIG
ST
RC7
DIG = Digital level output; TTL = TTL input buffer; ST = Schmitt Trigger input buffer; ANA = Analog level input/output;
I2C/SMB = I2C/SMBus input buffer; x = Dont care (TRIS bit does not affect port direction or is overridden for this option).
Default assignment for CCP2 when the CCP2MX Configuration bit is set. Alternate assignment is RB3.
DS41303C-page 126
Preliminary
PIC18F2XK20/4XK20
TABLE 10-6:
Name
PORTC
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
RC7
RC6
RC5
RC4
RC3
RC2
RC1
RC0
LATC
TRISC
T3CON
RD16
TXSTA
CSRC
TX9
60
60
60
RD16
T1CON
Reset
Values
on page
SYNC
SENDB
T3SYNC
BRGH
TMR1CS TMR1ON
TMR3CS TMR3ON
TRMT
58
59
TX9D
59
RCSTA
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
59
SSPCON1
WCOL
SSPOV
SSPEN
CKP
SSPM3
SSPM2
SSPM1
SSPM0
58
CCP1CON
P1M1
P1M0
DC1B1
DC1B0
59
CCP2CON
DC2B1
DC2B0
59
ECCP1AS
SLRCON
SLRE
SLRD
Preliminary
PSSAC0
PSSBD1
PSSBD0
59
SLRC
SLRB
SLRA
61
DS41303C-page 127
PIC18F2XK20/4XK20
10.5
Note:
PORTD is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISD. Setting a
TRISD bit (= 1) will make the corresponding PORTD
pin an input (i.e., disable the output driver). Clearing a
TRISD bit (= 0) will make the corresponding PORTD
pin an output (i.e., enable the output driver and put the
contents of the output latch on the selected pin).
The Data Latch register (LATD) is also memory
mapped. Read-modify-write operations on the LATD
register read and write the latched output value for
PORTD.
All pins on PORTD are implemented with Schmitt Trigger input buffers. Each pin is individually configurable
as an input or output.
Three of the PORTD pins are multiplexed with outputs
P1B, P1C and P1D of the enhanced CCP module. The
operation of these additional PWM output pins is
covered in greater detail in Section 16.0 Enhanced
Capture/Compare/PWM (ECCP) Module.
Note:
PORTD can also be configured as an 8-bit wide microprocessor port (Parallel Slave Port) by setting control
bit, PSPMODE (TRISE<4>). In this mode, the input
buffers are TTL. See Section 10.9 Parallel Slave
Port for additional information on the Parallel Slave
Port (PSP).
Note:
EXAMPLE 10-4:
CLRF
PORTD
CLRF
LATD
MOVLW
0CFh
MOVWF
TRISD
INITIALIZING PORTD
;
;
;
;
;
;
;
;
;
;
;
;
Initialize PORTD by
clearing output
data latches
Alternate method
to clear output
data latches
Value used to
initialize data
direction
Set RD<3:0> as inputs
RD<5:4> as outputs
RD<7:6> as inputs
DS41303C-page 128
Preliminary
PIC18F2XK20/4XK20
TABLE 10-7:
Pin
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RD4/PSP4
RD5/PSP5/P1B
RD6/PSP6/P1C
TRIS
Setting
I/O
I/O
Type
RD0
DIG
ST
PSP0
DIG
PSP read data output (LATD<0>); takes priority over port data.
Legend:
TTL
RD1
DIG
ST
PSP1
DIG
PSP read data output (LATD<1>); takes priority over port data.
TTL
RD2
DIG
ST
PSP2
DIG
PSP read data output (LATD<2>); takes priority over port data.
TTL
RD3
DIG
ST
PSP3
DIG
PSP read data output (LATD<3>); takes priority over port data.
TTL
RD4
DIG
ST
PSP4
DIG
PSP read data output (LATD<4>); takes priority over port data.
TTL
RD5
DIG
ST
PSP5
DIG
PSP read data output (LATD<5>); takes priority over port data.
TTL
P1B
DIG
ECCP1 Enhanced PWM output, channel B; takes priority over port and
PSP data. May be configured for tri-state during Enhanced PWM
shutdown events.
RD6
DIG
ST
DIG
PSP read data output (LATD<6>); takes priority over port data.
TTL
P1C
DIG
ECCP1 Enhanced PWM output, channel C; takes priority over port and
PSP data. May be configured for tri-state during Enhanced PWM
shutdown events.
RD7
DIG
ST
PSP7
DIG
PSP read data output (LATD<7>); takes priority over port data.
TTL
P1D
DIG
ECCP1 Enhanced PWM output, channel D; takes priority over port and
PSP data. May be configured for tri-state during Enhanced PWM
shutdown events.
PSP6
RD7/PSP7/P1D
Description
DIG = Digital level output; TTL = TTL input buffer; ST = Schmitt Trigger input buffer; x = Dont care
(TRIS bit does not affect port direction or is overridden for this option).
Preliminary
DS41303C-page 129
PIC18F2XK20/4XK20
TABLE 10-8:
Name
PORTD
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
RD7
RD6
RD5
RD4
RD3
RD2
RD1
RD0
LATD
TRISD
Reset
Values
on page
60
60
60
IBF
OBF
IBOV
PSPMODE
TRISE2
TRISE1
TRISE0
60
CCP1CON
P1M1
P1M0
DC1B1
DC1B0
CCP1M3
CCP1M2
CCP1M1
CCP1M0
59
SLRCON
SLRE
SLRD
SLRC
SLRB
SLRA
61
TRISE
DS41303C-page 130
Preliminary
PIC18F2XK20/4XK20
10.6
10.6.1
EXAMPLE 10-5:
CLRF
CLRF
MOVLW
ANDWF
MOVLW
MOVWF
10.6.2
PORTE
;
;
;
LATE
;
;
;
1Fh
;
ANSEL,w ;
05h
;
;
;
TRISE
;
;
;
INITIALIZING PORTE
Initialize PORTE by
clearing output
data latches
Alternate method
to clear output
data latches
Configure analog pins
for digital only
Value used to
initialize data
direction
Set RE<0> as input
RE<1> as output
RE<2> as input
Preliminary
DS41303C-page 131
PIC18F2XK20/4XK20
REGISTER 10-1:
R-0
R-0
R/W-0
R/W-0
U-0
R/W-1
R/W-1
R/W-1
IBF
OBF
IBOV
PSPMODE
TRISE2
TRISE1
TRISE0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
bit 4
bit 3
Unimplemented: Read as 0
bit 2
bit 1
bit 0
DS41303C-page 132
Preliminary
PIC18F2XK20/4XK20
TABLE 10-9:
Pin
TRIS
Setting
I/O
I/O
Type
RE0
DIG
ST
RE0/RD/AN5
RE1/WR/AN6
RE2/CS/AN7
MCLR/VPP/
RE3(1,2)
Legend:
Note 1:
2:
Description
RD
TTL
AN5
ANA
RE1
DIG
ST
WR
TTL
AN6
ANA
RE2
DIG
ST
CS
TTL
AN7
ANA
MCLR
ST
VPP
ANA
RE3
(2)
ST
DIG = Digital level output; TTL = TTL input buffer; ST = Schmitt Trigger input buffer; ANA = Analog level input/output;
x = Dont care (TRIS bit does not affect port direction or is overridden for this option).
RE3 is available on both PIC18F2XK20 and PIC18F4XK20 devices. All other PORTE pins are only implemented on
PIC18F4XK20 devices.
RE3 does not have a corresponding TRIS bit to control data direction.
Bit 6
Bit 5
Bit 4
Bit 3
PORTE
RE3(1,2)
LATE(2)
TRISE
IBF
OBF
IBOV
PSPMODE
TRISE2
TRISE1
TRISE0
60
SLRCON
SLRE
SLRD
SLRC
SLRB
SLRA
61
ANS7
ANS6
ANS5
ANS4
ANS3
ANS2
ANS1
ANS0
60
ANSEL
Bit 2
Bit 1
Bit 0
RE2
RE1
RE0
Reset
Values
on page
Bit 7
60
60
Preliminary
DS41303C-page 133
PIC18F2XK20/4XK20
10.7
REGISTER 10-2:
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
ANS7(1)
ANS6(1)
ANS5(1)
ANS4
ANS3
ANS2
ANS1
ANS0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1:
x = Bit is unknown
DS41303C-page 134
Preliminary
PIC18F2XK20/4XK20
REGISTER 10-3:
U-0
U-0
U-0
R/W-1(1)
R/W-1(1)
R/W-1(1)
R/W-1(1)
R/W-1(1)
ANS12
ANS11
ANS10
ANS9
ANS8
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7-5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1:
x = Bit is unknown
Default state is determined by the PBADEN bit of CONFIG3H. The default state is 0 When
PBADEN = 0.
Preliminary
DS41303C-page 135
PIC18F2XK20/4XK20
10.8
REGISTER 10-4:
U-0
U-0
U-0
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
SLRE(1)
SLRD(1)
SLRC
SLRB
SLRA
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7-5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1:
2:
x = Bit is unknown
DS41303C-page 136
Preliminary
PIC18F2XK20/4XK20
10.9
Note:
FIGURE 10-2:
WR LATD
or
WR PORTD
Preliminary
Q
RDx pin
CK
Data Latch
Q
RD PORTD
TTL
D
ENEN
RD LATD
PORTE Pins
Read
TTL
RD
Chip Select
TTL
CS
Write
Note:
TTL
WR
DS41303C-page 137
PIC18F2XK20/4XK20
FIGURE 10-3:
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Q4
Q1
Q2
Q3
Q4
CS
WR
RD
PORTD<7:0>
IBF
OBF
PSPIF
FIGURE 10-4:
Q2
Q3
Q4
Q1
Q2
Q3
CS
WR
RD
PORTD<7:0>
IBF
OBF
PSPIF
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
RD7
RD6
RD5
RD4
RD3
RD2
RD1
RD0
LATD
TRISD
PORTE
Reset
Values
on page
60
60
60
RE3
RE2
RE1
RE0
60
TRISE1
TRISE0
60
LATE
TRISE
IBF
OBF
IBOV
PSPMODE
SLRE
SLRD
SLRC
SLRB
SLRA
61
TMR0IF
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
SLRCON
INTCON
GIE/GIEH PEIE/GIEL
60
PIR1
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
60
ANSEL
ANS7
ANS6
ANS5
ANS4
ANS3
ANS2
ANS1
ANS0
60
Legend: = unimplemented, read as 0. Shaded cells are not used by the Parallel Slave Port.
DS41303C-page 138
Preliminary
PIC18F2XK20/4XK20
11.0
CAPTURE/COMPARE/PWM
(CCP) MODULES
REGISTER 11-1:
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
DC2B1
DC2B0
CCP2M3
CCP2M2
CCP2M1
CCP2M0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7-6
Unimplemented: Read as 0
bit 5-4
DC2B<1:0>: PWM Duty Cycle bit 1 and bit 0 for CCP2 Module
Capture mode:
Unused.
Compare mode:
Unused.
PWM mode:
These bits are the two LSbs (bit 1 and bit 0) of the 10-bit PWM duty cycle. The eight MSbs
(DC2B<9:2>) of the duty cycle are found in CCPR2L.
bit 3-0
Preliminary
DS41303C-page 139
PIC18F2XK20/4XK20
11.1
11.1.1
11.1.2
TABLE 11-1:
CCP/ECCP Mode
Timer Resource
Capture
Timer1 or Timer3
Compare
Timer1 or Timer3
PWM
Timer2
TABLE 11-2:
Interaction
Capture
Capture
Each module can use TMR1 or TMR3 as the time base. The time base can be different
for each CCP.
Capture
Compare
CCP2 can be configured for the Special Event Trigger to reset TMR1 or TMR3
(depending upon which time base is used). Automatic A/D conversions on trigger event
can also be done. Operation of CCP1 could be affected if it is using the same timer as a
time base.
Compare
Capture
CCP1 can be configured for the Special Event Trigger to reset TMR1 or TMR3
(depending upon which time base is used). Operation of CCP2 could be affected if it is
using the same timer as a time base.
Compare
Compare
Either module can be configured for the Special Event Trigger to reset the time base.
Automatic A/D conversions on CCP2 trigger event can be done. Conflicts may occur if
both modules are using the same time base.
Capture
PWM
None
Compare
PWM
None
PWM(1)
Capture
None
PWM(1)
Compare
None
(1)
PWM
Note 1:
PWM
Both PWMs will have the same frequency and update rate (TMR2 interrupt).
DS41303C-page 140
Preliminary
PIC18F2XK20/4XK20
11.2
Capture Mode
EXAMPLE 11-1:
CLRF
MOVLW
MOVWF
CHANGING BETWEEN
CAPTURE PRESCALERS
(CCP2 SHOWN)
CCP2CON
; Turn CCP module off
NEW_CAPT_PS ; Load WREG with the
; new prescaler mode
; value and CCP ON
CCP2CON
; Load CCP2CON with
; this value
11.2.1
11.2.2
11.2.3
SOFTWARE INTERRUPT
11.2.4
CCP PRESCALER
Preliminary
DS41303C-page 141
PIC18F2XK20/4XK20
FIGURE 11-1:
Set CCP1IF
T3CCP2
CCP1 pin
Prescaler
1, 4, 16
and
Edge Detect
CCP1CON<3:0>
Q1:Q4
CCP2CON<3:0>
4
4
CCPR1L
TMR1
Enable
TMR1H
TMR1L
TMR3H
TMR3L
Set CCP2IF
4
T3CCP1
T3CCP2
CCP2 pin
Prescaler
1, 4, 16
TMR3
Enable
CCPR1H
T3CCP2
TMR3L
and
Edge Detect
TMR3
Enable
CCPR2H
CCPR2L
TMR1
Enable
T3CCP2
T3CCP1
DS41303C-page 142
Preliminary
TMR1H
TMR1L
PIC18F2XK20/4XK20
11.3
Compare Mode
11.3.2
11.3.3
driven high
driven low
toggled (high-to-low or low-to-high)
remain unchanged (that is, reflects the state of the
I/O latch)
11.3.4
11.3.1
FIGURE 11-2:
CCPR1H
Set CCP1IF
CCPR1L
Comparator
Output
Logic
Compare
Match
R
TRIS
Output Enable
4
CCP1CON<3:0>
0
TMR1H
TMR1L
TMR3H
TMR3L
T3CCP1
0
Special Event Trigger
(Timer1/Timer3 Reset, A/D Trigger)
1
T3CCP2
Set CCP2IF
Comparator
CCPR2H
CCP2 pin
Compare
Match
Output
Logic
4
CCPR2L
R
TRIS
Output Enable
CCP2CON<3:0>
Preliminary
DS41303C-page 143
PIC18F2XK20/4XK20
TABLE 11-3:
Name
INTCON
Bit 6
Bit 5
Reset
Values
on page
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
RI
TO
PD
POR
BOR
56
IPEN
SBOREN
PIR1
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
(1)
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR1
PSPIP(1)
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
60
RCON
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
60
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
60
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
60
TRISB
60
TRISC
60
TMR1L
58
TMR1H
T1CON
RD16
T1RUN
58
TMR1CS TMR1ON
58
TMR3H
59
TMR3L
59
T3CON
RD16
T3CCP2
T3CKPS1 T3CKPS0
T3CCP1
T3SYNC
TMR3CS TMR3ON
59
CCPR1L
59
CCPR1H
59
CCP1CON
P1M1
P1M0
DC1B1
DC1B0
CCPR2L
CCPR2H
CCP2CON
DC2B1
DC2B0
CCP1M3
CCP1M2
CCP1M1
CCP1M0
59
59
59
CCP2M3
CCP2M2
CCP2M1
CCP2M0
59
Legend: = unimplemented, read as 0. Shaded cells are not used by Capture/Compare, Timer1 or Timer3.
DS41303C-page 144
Preliminary
PIC18F2XK20/4XK20
11.4
PWM Mode
FIGURE 11-4:
Period
Pulse Width
PR2
T2CON
CCPRxL
CCPxCON
TMR2 = PR2
TMR2 = CCPRxL:DCxB<1:0>
TMR2 = 0
FIGURE 11-3:
CCPRxH(2) (Slave)
CCPx
R
Comparator
TMR2
(1)
S
TRIS
Comparator
PR2
Note 1:
2:
Clear Timer2,
toggle CCPx pin and
latch duty cycle
Preliminary
DS41303C-page 145
PIC18F2XK20/4XK20
11.4.1
PWM PERIOD
11.4.2
EQUATION 11-1:
PWM PERIOD
TMR2 is cleared
The CCPx pin is set. (Exception: If the PWM duty
cycle = 0%, the pin will not be set.)
The PWM duty cycle is latched from CCPRxL into
CCPRxH.
Note:
EQUATION 11-2:
PULSE WIDTH
EQUATION 11-3:
( CCPRxL:DCxB<1:0> )
Duty Cycle Ratio = ----------------------------------------------------------4 ( PR2 + 1 )
The CCPRxH register and a 2-bit internal latch are
used to double buffer the PWM duty cycle. This double
buffering is essential for glitchless PWM operation.
The 8-bit timer TMR2 register is concatenated with
either the 2-bit internal system clock (FOSC), or 2 bits of
the prescaler, to create the 10-bit time base. The system
clock is used if the Timer2 prescaler is set to 1:1.
When the 10-bit time base matches the CCPRxH and
2-bit latch, then the CCPx pin is cleared (see
Figure 11-3).
DS41303C-page 146
Preliminary
PIC18F2XK20/4XK20
11.4.3
PWM RESOLUTION
EQUATION 11-4:
TABLE 11-4:
Note:
2.44 kHz
9.77 kHz
39.06 kHz
156.25 kHz
312.50 kHz
416.67 kHz
16
FFh
FFh
FFh
3Fh
1Fh
17h
10
10
10
6.58
PWM Frequency
Timer Prescale (1, 4, 16)
PR2 Value
Maximum Resolution (bits)
TABLE 11-6:
log [ 4 ( PR2 + 1 ) ]
Resolution = ------------------------------------------ bits
log ( 2 )
PWM Frequency
TABLE 11-5:
PWM RESOLUTION
1.22 kHz
4.88 kHz
19.53 kHz
78.12 kHz
156.3 kHz
208.3 kHz
16
0xFF
0xFF
0xFF
0x3F
0x1F
0x17
10
10
10
6.6
PWM Frequency
Timer Prescale (1, 4, 16)
PR2 Value
Maximum Resolution (bits)
1.22 kHz
4.90 kHz
19.61 kHz
76.92 kHz
153.85 kHz
200.0 kHz
16
0x65
0x65
0x65
0x19
0x0C
0x09
Preliminary
DS41303C-page 147
PIC18F2XK20/4XK20
11.4.4
OPERATION IN POWER-MANAGED
MODES
11.4.7
3.
4.
11.4.5
5.
11.4.6
6.
EFFECTS OF RESET
Any Reset will force all ports to Input mode and the
CCP registers to their Reset states.
DS41303C-page 148
7.
Preliminary
PIC18F2XK20/4XK20
TABLE 11-7:
Name
INTCON
Bit 6
GIE/GIEH PEIE/GIEL
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
RI
TO
PD
POR
BOR
56
RCON
IPEN
SBOREN
PIR1
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
60
TRISB
60
TRISC
60
TMR2
Timer2 Register
58
PR2
58
T2CON
CCPR1L
CCPR1H
CCP1CON
P1M1
P1M0
DC1B1
DC1B0
58
59
59
CCP1M3
CCP1M2
CCP1M1
CCP1M0
59
CCPR2L
59
CCPR2H
59
CCP2CON
ECCP1AS
PWM1CON
ECCPASE ECCPAS2
PRSEN
PDC6
DC2B1
DC2B0
CCP2M3
CCP2M2
CCP2M1
CCP2M0
59
ECCPAS1
ECCPAS0
PSSAC1
PSSAC0
PSSBD1
PSSBD0
59
PDC5
PDC4
PDC3
PDC2
PDC
PDC0
59
Legend: = unimplemented, read as 0. Shaded cells are not used by PWM or Timer2.
Preliminary
DS41303C-page 149
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 150
Preliminary
PIC18F2XK20/4XK20
12.0
TIMER0 MODULE
REGISTER 12-1:
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
TMR0ON
T08BIT
T0CS
T0SE
PSA
T0PS2
T0PS1
T0PS0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2-0
Preliminary
DS41303C-page 151
PIC18F2XK20/4XK20
12.1
Timer0 Operation
12.2
FIGURE 12-1:
0
0
1
T0CKI pin
T0SE
T0CS
Programmable
Prescaler
Sync with
Internal
Clocks
Set
TMR0IF
on Overflow
(2 TCY Delay)
8
T0PS<2:0>
PSA
Note:
TMR0L
Upon Reset, Timer0 is enabled in 8-bit mode with clock input from T0CKI max. prescale.
DS41303C-page 152
Preliminary
PIC18F2XK20/4XK20
FIGURE 12-2:
FOSC/4
0
0
Sync with
Internal
Clocks
1
Programmable
Prescaler
T0CKI pin
T0SE
T0CS
TMR0
High Byte
TMR0L
Set
TMR0IF
on Overflow
(2 TCY Delay)
Read TMR0L
T0PS<2:0>
Write TMR0L
PSA
TMR0H
8
8
Internal Data Bus
Note:
12.3
Upon Reset, Timer0 is enabled in 8-bit mode with clock input from T0CKI max. prescale.
Prescaler
12.3.1
TABLE 12-1:
Name
SWITCHING PRESCALER
ASSIGNMENT
12.4
Timer0 Interrupt
The TMR0 interrupt is generated when the TMR0 register overflows from FFh to 00h in 8-bit mode, or from
FFFFh to 0000h in 16-bit mode. This overflow sets the
TMR0IF flag bit. The interrupt can be masked by clearing the TMR0IE bit of the INTCON register. Before
re-enabling the interrupt, the TMR0IF bit must be
cleared by software in the Interrupt Service Routine.
Since Timer0 is shut down in Sleep mode, the TMR0
interrupt cannot awaken the processor from Sleep.
Bit 6
Bit 5
TMR0L
TMR0H
INTCON
T0CON
TMR0ON
T08BIT
TRISA
RA7(1)
RA6(1)
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
58
58
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
T0CS
T0SE
PSA
T0PS2
T0PS1
T0PS0
58
RA5
RA4
RA3
RA2
RA1
RA0
60
Preliminary
DS41303C-page 153
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 154
Preliminary
PIC18F2XK20/4XK20
13.0
TIMER1 MODULE
REGISTER 13-1:
R/W-0
R-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
RD16
T1RUN
T1CKPS1
T1CKPS0
T1OSCEN
T1SYNC
TMR1CS
TMR1ON
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5-4
bit 3
bit 2
bit 1
bit 0
Preliminary
DS41303C-page 155
PIC18F2XK20/4XK20
13.1
Timer1 Operation
FIGURE 13-1:
On/Off
T1OSO/T13CKI
1
FOSC/4
Internal
Clock
T1OSI
Synchronize
Prescaler
1, 2, 4, 8
Detect
0
2
T1OSCEN(1)
Sleep Input
TMR1CS
Timer1
On/Off
T1CKPS<1:0>
T1SYNC
TMR1ON
Clear TMR1
(CCP Special Event Trigger)
Set
TMR1IF
on Overflow
TMR1
High Byte
TMR1L
Note 1: When enable bit, T1OSCEN, is cleared, the inverter and feedback resistor are turned off to eliminate power drain.
FIGURE 13-2:
T1OSO/T13CKI
1
FOSC/4
Internal
Clock
T1OSI
Synchronize
Prescaler
1, 2, 4, 8
Detect
0
2
T1OSCEN(1)
T1CKPS<1:0>
T1SYNC
TMR1ON
Sleep Input
TMR1CS
Clear TMR1
(CCP Special Event Trigger)
Timer1
On/Off
TMR1
High Byte
TMR1L
Set
TMR1IF
on Overflow
Read TMR1L
Write TMR1L
8
TMR1H
8
8
Internal Data Bus
Note 1: When enable bit, T1OSCEN, is cleared, the inverter and feedback resistor are turned off to eliminate power drain.
DS41303C-page 156
Preliminary
PIC18F2XK20/4XK20
13.2
13.2.3
13.2.1
13.2.2
13.3
Timer1 Prescaler
13.4
Timer1 Operation in
Asynchronous Counter Mode
FIGURE 13-3:
T1CKI = 1
when TMR1
Enabled
T1CKI = 0
when TMR1
Enabled
Note 1:
2:
Preliminary
DS41303C-page 157
PIC18F2XK20/4XK20
13.5
TABLE 13-1:
Osc Type
LP
13.6
Timer1 Oscillator
FIGURE 13-4:
EXTERNAL
COMPONENTS FOR THE
TIMER1 LP OSCILLATOR
C1
27 pF
PIC MCU
Freq
C1
32 kHz
27 pF
C2
(1)
27 pF(1)
13.6.1
USING TIMER1 AS A
CLOCK SOURCE
T1OSI
XTAL
32.768 kHz
T1OSO
C2
27 pF
Note:
DS41303C-page 158
Preliminary
PIC18F2XK20/4XK20
13.6.2
13.7
13.6.3
FIGURE 13-5:
Timer1 Interrupt
13.8
OSCILLATOR CIRCUIT
WITH GROUNDED
GUARD RING
VDD
VSS
OSC1
OSC2
RC0
RC1
RC2
Note: Not drawn to scale.
Preliminary
DS41303C-page 159
PIC18F2XK20/4XK20
13.9
EXAMPLE 13-1:
RTCinit
MOVLW
MOVWF
CLRF
MOVLW
MOVWF
CLRF
CLRF
MOVLW
MOVWF
BSF
RETURN
80h
TMR1H
TMR1L
b00001111
T1CON
secs
mins
.12
hours
PIE1, TMR1IE
BSF
BCF
INCF
MOVLW
CPFSGT
RETURN
CLRF
INCF
MOVLW
CPFSGT
RETURN
CLRF
INCF
MOVLW
CPFSGT
RETURN
CLRF
RETURN
TMR1H, 7
PIR1, TMR1IF
secs, F
.59
secs
RTCisr
DS41303C-page 160
secs
mins, F
.59
mins
mins
hours, F
.23
hours
hours
;
;
;
;
;
;
;
;
No, done
Clear seconds
Increment minutes
60 minutes elapsed?
;
;
;
;
No, done
clear minutes
Increment hours
24 hours elapsed?
; No, done
; Reset hours
; Done
Preliminary
PIC18F2XK20/4XK20
TABLE 13-2:
Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
INTCON
GIE/GIEH PEIE/GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
PIR1
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
(1)
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR1
PSPIP(1)
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
60
TMR1L
58
TMR1H
58
T1CON
RD16
T1RUN
TMR1CS
TMR1ON
58
Preliminary
DS41303C-page 161
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 162
Preliminary
PIC18F2XK20/4XK20
14.0
TIMER2 MODULE
14.1
Timer2 Operation
REGISTER 14-1:
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
T2OUTPS3
T2OUTPS2
T2OUTPS1
T2OUTPS0
TMR2ON
T2CKPS1
T2CKPS0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7
Unimplemented: Read as 0
bit 6-3
bit 2
bit 1-0
Preliminary
x = Bit is unknown
DS41303C-page 163
PIC18F2XK20/4XK20
14.2
Timer2 Interrupt
14.3
Timer2 Output
FIGURE 14-1:
T2OUTPS<3:0>
1:1 to 1:16
Postscaler
Set TMR2IF
T2CKPS<1:0>
TMR2/PR2
Match
Reset
FOSC/4
TMR2
TMR2 Output
(to PWM or MSSP)
Comparator
PR2
8
TABLE 14-1:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
PIR1
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
PSPIE(1)
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR1
PSPIP(1)
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
TMR2
T2CON
PR2
Timer2 Register
60
58
T2CKPS1 T2CKPS0
58
58
Legend: = unimplemented, read as 0. Shaded cells are not used by the Timer2 module.
Note 1: These bits are unimplemented on 28-pin devices; always maintain these bits clear.
DS41303C-page 164
Preliminary
PIC18F2XK20/4XK20
15.0
TIMER3 MODULE
REGISTER 15-1:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
RD16
T3CCP2
T3CKPS1
T3CKPS0
T3CCP1
T3SYNC
TMR3CS
TMR3ON
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6,3
bit 5-4
bit 2
bit 1
bit 0
Preliminary
DS41303C-page 165
PIC18F2XK20/4XK20
15.1
Timer3 Operation
FIGURE 15-1:
T1OSO/T13CKI
1
FOSC/4
Internal
Clock
T1OSI
Synchronize
Prescaler
1, 2, 4, 8
Detect
0
2
T1OSCEN(1)
Sleep Input
TMR3CS
T3CKPS<1:0>
Timer3
On/Off
T3SYNC
TMR3ON
Clear TMR3
TMR3L
TMR3
High Byte
Set
TMR3IF
on Overflow
Note 1: When enable bit, T1OSCEN, is cleared, the inverter and feedback resistor are turned off to eliminate power drain.
DS41303C-page 166
Preliminary
PIC18F2XK20/4XK20
FIGURE 15-2:
T13CKI/T1OSO
1
FOSC/4
Internal
Clock
T1OSI
Synchronize
Prescaler
1, 2, 4, 8
Detect
0
2
T1OSCEN(1)
Sleep Input
TMR3CS
Timer3
On/Off
T3CKPS<1:0>
T3SYNC
TMR3ON
CCP1/CCP2 Special Event Trigger
CCP1/CCP2 Select from T3CON<6,3>
Clear TMR3
Set
TMR3IF
on Overflow
TMR3
High Byte
TMR3L
Read TMR1L
Write TMR1L
8
TMR3H
8
8
Internal Data Bus
Note 1: When enable bit, T1OSCEN, is cleared, the inverter and feedback resistor are turned off to eliminate power drain.
15.2
15.3
15.4
Timer3 Interrupt
Preliminary
DS41303C-page 167
PIC18F2XK20/4XK20
15.5
TABLE 15-1:
Name
INTCON
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
Bit 6
GIE/GIEH PEIE/GIEL
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
60
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
60
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
60
TMR3L
TMR3H
59
59
T1CON
RD16
T1RUN
TMR1CS
TMR1ON
58
T3CON
RD16
T3CCP2
T3CKPS1 T3CKPS0
TMR3CS
TMR3ON
59
T3CCP1
T3SYNC
Legend: = unimplemented, read as 0. Shaded cells are not used by the Timer3 module.
DS41303C-page 168
Preliminary
PIC18F2XK20/4XK20
16.0
ENHANCED
CAPTURE/COMPARE/PWM
(ECCP) MODULE
REGISTER 16-1:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
P1M1
P1M0
DC1B1
DC1B0
CCP1M3
CCP1M2
CCP1M1
CCP1M0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7-6
bit 5-4
bit 3-0
Preliminary
DS41303C-page 169
PIC18F2XK20/4XK20
In addition to the expanded range of modes available
through the CCP1CON register and ECCP1AS
register, the ECCP module has two additional registers
associated with Enhanced PWM operation and
auto-shutdown features. They are:
PWM1CON (Dead-band delay)
PSTRCON (output steering)
16.1
16.3
16.1.1
16.2
16.2.1
DS41303C-page 170
Preliminary
PIC18F2XK20/4XK20
16.4
The PWM outputs are multiplexed with I/O pins and are
designated P1A, P1B, P1C and P1D. The polarity of the
PWM pins is configurable and is selected by setting the
CCP1M bits in the CCP1CON register appropriately.
Single PWM
Half-Bridge PWM
Full-Bridge PWM, Forward mode
Full-Bridge PWM, Reverse mode
FIGURE 16-1:
DC1B<1:0>
CCP1M<3:0>
4
P1M<1:0>
2
CCPR1L
CCP1/P1A
CCP1/P1A
TRIS
CCPR1H (Slave)
P1B
R
Comparator
Output
Controller
P1B
TRIS
P1C
TMR2
(1)
Clear Timer2,
toggle PWM pin and
latch duty cycle
PR2
1:
S
P1D
Comparator
Note
P1C
TRIS
P1D
TRIS
PWM1CON
The 8-bit timer TMR2 register is concatenated with the 2-bit internal Q clock, or 2 bits of the prescaler to create the 10-bit
time base.
Note 1: The TRIS register value for each PWM output must be configured appropriately.
2: Clearing the CCPxCON register will relinquish ECCP control of all PWM output pins.
3: Any pin not used by an Enhanced PWM mode is available for alternate pin functions.
TABLE 16-1:
ECCP Mode
P1M<1:0>
CCP1/P1A
P1B
P1C
P1D
Single
00
Yes(1)
Yes(1)
Yes(1)
Yes(1)
Half-Bridge
10
Yes
Yes
No
No
Full-Bridge, Forward
01
Yes
Yes
Yes
Yes
Full-Bridge, Reverse
11
Yes
Yes
Yes
Yes
Note 1:
Outputs are enabled by pulse steering in Single mode. See Register 16-4.
Preliminary
DS41303C-page 171
PIC18F2XK20/4XK20
FIGURE 16-2:
P1M<1:0>
Signal
PR2+1
Pulse
Width
Period
00
(Single Output)
P1A Modulated
Delay(1)
Delay(1)
P1A Modulated
10
(Half-Bridge)
P1B Modulated
P1A Active
01
(Full-Bridge,
Forward)
P1B Inactive
P1C Inactive
P1D Modulated
P1A Inactive
11
(Full-Bridge,
Reverse)
P1B Modulated
P1C Active
P1D Inactive
Relationships:
Period = 4 * TOSC * (PR2 + 1) * (TMR2 Prescale Value)
Pulse Width = TOSC * (CCPR1L<7:0>:CCP1CON<5:4>) * (TMR2 Prescale Value)
Delay = 4 * TOSC * (PWM1CON<6:0>)
Note 1: Dead-band delay is programmed using the PWM1CON register (Section 16.4.6 Programmable Dead-Band Delay
mode).
DS41303C-page 172
Preliminary
PIC18F2XK20/4XK20
FIGURE 16-3:
P1M<1:0>
PR2+1
Pulse
Width
Period
00
(Single Output)
P1A Modulated
P1A Modulated
10
(Half-Bridge)
Delay(1)
Delay(1)
P1B Modulated
P1A Active
01
(Full-Bridge,
Forward)
P1B Inactive
P1C Inactive
P1D Modulated
P1A Inactive
11
(Full-Bridge,
Reverse)
P1B Modulated
P1C Active
P1D Inactive
Relationships:
Period = 4 * TOSC * (PR2 + 1) * (TMR2 Prescale Value)
Pulse Width = TOSC * (CCPR1L<7:0>:CCP1CON<5:4>) * (TMR2 Prescale Value)
Delay = 4 * TOSC * (PWM1CON<6:0>)
Note
1:
Dead-band delay is programmed using the PWM1CON register (Section 16.4.6 Programmable Dead-Band Delay
mode).
Preliminary
DS41303C-page 173
PIC18F2XK20/4XK20
16.4.1
HALF-BRIDGE MODE
FIGURE 16-4:
Period
Period
Pulse Width
P1A(2)
td
td
P1B(2)
(1)
(1)
(1)
td = Dead-Band Delay
Note 1:
2:
FIGURE 16-5:
EXAMPLE OF
HALF-BRIDGE PWM
OUTPUT
P1A
Load
FET
Driver
P1B
FET
Driver
FET
Driver
P1A
FET
Driver
Load
FET
Driver
P1B
DS41303C-page 174
Preliminary
PIC18F2XK20/4XK20
16.4.2
FULL-BRIDGE MODE
FIGURE 16-6:
FET
Driver
QC
QA
FET
Driver
P1A
Load
P1B
FET
Driver
P1C
FET
Driver
QD
QB
VP1D
Preliminary
DS41303C-page 175
PIC18F2XK20/4XK20
FIGURE 16-7:
Forward Mode
Period
P1A
(2)
Pulse Width
P1B(2)
P1C(2)
P1D(2)
(1)
(1)
Reverse Mode
Period
Pulse Width
P1A(2)
P1B(2)
P1C(2)
P1D(2)
(1)
Note 1:
2:
(1)
DS41303C-page 176
Preliminary
PIC18F2XK20/4XK20
16.4.2.1
FIGURE 16-8:
Signal
Period
P1A (Active-High)
P1B (Active-High)
Pulse Width
P1C (Active-High)
(2)
P1D (Active-High)
Pulse Width
Note 1:
2:
The direction bit P1M1 of the CCP1CON register is written any time during the PWM cycle.
When changing directions, the P1A and P1C signals switch before the end of the current PWM cycle. The
modulated P1B and P1D signals are inactive at this time. The length of this time is (1/FOSC) TMR2 prescale
value.
Preliminary
DS41303C-page 177
PIC18F2XK20/4XK20
FIGURE 16-9:
t1
Reverse Period
P1A
P1B
PW
P1C
P1D
PW
TON
External Switch C
TOFF
External Switch D
Potential
Shoot-Through Current
Note 1:
16.4.3
T = TOFF TON
2:
3:
TOFF is the turn off delay of power switch QD and its driver.
START-UP CONSIDERATIONS
DS41303C-page 178
Preliminary
PIC18F2XK20/4XK20
16.4.4
ENHANCED PWM
AUTO-SHUTDOWN MODE
REGISTER 16-2:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
ECCPASE
ECCPAS2
ECCPAS1
ECCPAS0
PSSAC1
PSSAC0
PSSBD1
PSSBD0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6-4
bit 3-2
bit 1-0
Preliminary
DS41303C-page 179
PIC18F2XK20/4XK20
Note 1: The auto-shutdown condition is a
level-based signal, not an edge-based
signal. As long as the level is present, the
auto-shutdown will persist.
2: Writing to the ECCPASE bit is disabled
while an auto-shutdown condition
persists.
3: Once the auto-shutdown condition has
been removed and the PWM restarted
(either through firmware or auto-restart)
the PWM signal will always restart at the
beginning of the next PWM period.
FIGURE 16-10:
Shutdown Event
ECCPASE bit
PWM Activity
Normal PWM
ECCPASE
Cleared by
Shutdown
Shutdown Firmware PWM
Event Occurs Event Clears
Resumes
Start of
PWM Period
16.4.5
AUTO-RESTART MODE
The Enhanced PWM can be configured to automatically restart the PWM signal once the auto-shutdown
condition has been removed. Auto-restart is enabled by
setting the PRSEN bit in the PWM1CON register.
If auto-restart is enabled, the ECCPASE bit will remain
set as long as the auto-shutdown condition is active.
When the auto-shutdown condition is removed, the
ECCPASE bit will be cleared via hardware and normal
operation will resume.
FIGURE 16-11:
Shutdown Event
ECCPASE bit
PWM Activity
Normal PWM
Start of
PWM Period
DS41303C-page 180
Shutdown
Shutdown
Event Occurs Event Clears
Preliminary
PWM
Resumes
PIC18F2XK20/4XK20
16.4.6
PROGRAMMABLE DEAD-BAND
DELAY MODE
FIGURE 16-12:
Period
Period
Pulse Width
P1A(2)
td
td
P1B(2)
(1)
(1)
(1)
td = Dead-Band Delay
Note 1:
FIGURE 16-13:
EXAMPLE OF
HALF-BRIDGE PWM
OUTPUT
2:
+
V
-
P1A
Load
FET
Driver
+
V
-
P1B
V-
Preliminary
DS41303C-page 181
PIC18F2XK20/4XK20
REGISTER 16-3:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
PRSEN
PDC6
PDC5
PDC4
PDC3
PDC2
PDC1
PDC0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6-0
DS41303C-page 182
Preliminary
PIC18F2XK20/4XK20
16.4.7
REGISTER 16-4:
Note:
U-0
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-1
STRSYNC
STRD
STRC
STRB
STRA
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7-5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1:
The PWM Steering mode is available only when the CCP1CON register bits CCP1M<3:2> = 11 and
P1M<1:0> = 00.
Preliminary
DS41303C-page 183
PIC18F2XK20/4XK20
FIGURE 16-14:
SIMPLIFIED STEERING
BLOCK DIAGRAM
STRA
P1A Signal
CCP1M1
PORT Data
STRB
CCP1M0
PORT Data
PORT Data
PORT Data
P1B pin
TRIS
P1C pin
1
0
TRIS
STRD
CCP1M0
TRIS
STRC
CCP1M1
P1A pin
P1D pin
1
0
TRIS
Note 1:
2:
DS41303C-page 184
Preliminary
PIC18F2XK20/4XK20
16.4.7.1
Steering Synchronization
FIGURE 16-15:
PWM
STRn
P1<D:A>
PORT Data
PORT Data
P1n = PWM
FIGURE 16-16:
PWM
STRn
P1<D:A>
PORT Data
PORT Data
P1n = PWM
Preliminary
DS41303C-page 185
PIC18F2XK20/4XK20
16.4.8
OPERATION IN POWER-MANAGED
MODES
16.4.8.1
16.4.9
EFFECTS OF A RESET
DS41303C-page 186
Preliminary
PIC18F2XK20/4XK20
TABLE 16-2:
Name
INTCON
Bit 6
GIE/GIEH PEIE/GIEL
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
RCON
IPEN
SBOREN
RI
TO
PD
POR
BOR
56
PIR1
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
60
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
60
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
60
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
60
TRISB
60
TRISC
60
TRISD
60
TMR1L
58
TMR1H
58
T1CON
TMR2
T2CON
RD16
T1RUN
T1CKPS1
T1CKPS0
T1OSCEN
T1SYNC
TMR1CS
TMR1ON
Timer2 Register
58
58
58
PR2
58
TMR3L
59
TMR3H
T3CON
RD16
T3CCP2
59
T3CKPS1
T3CKPS0
T3CCP1
T3SYNC
TMR3CS
TMR3ON
59
CCPR1L
59
CCPR1H
59
CCP1CON
ECCP1AS
PWM1CON
Legend:
Note 1:
P1M1(1)
P1M0(1)
ECCPASE ECCPAS2
PRSEN
PDC6(1)
DC1B1
DC1B0
CCP1M3
CCP1M2
CCP1M1
(1)
CCP1M0
(1)
59
ECCPAS1
ECCPAS0
PSSAC1
PSSAC0
PSSBD1
PSSBD0
59
PDC5(1)
PDC4(1)
PDC3(1)
PDC2(1)
PDC1(1)
PDC0(1)
59
= unimplemented, read as 0. Shaded cells are not used during ECCP operation.
These bits are unimplemented on 28-pin devices; always maintain these bits clear.
Preliminary
DS41303C-page 187
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 188
Preliminary
PIC18F2XK20/4XK20
17.0
17.1
MASTER SYNCHRONOUS
SERIAL PORT (MSSP)
MODULE
17.3
SPI Mode
FIGURE 17-1:
Internal
Data Bus
Read
Master mode
Multi-Master mode
Slave mode
17.2
SSPBUF Reg
Control Registers
SDI/SDA
Write
SSPSR Reg
Shift
Clock
SDO
bit 0
SS
SS Control
Enable
Edge
Select
The use of these registers and their individual Configuration bits differ significantly depending on whether the
MSSP module is operated in SPI or I2C mode.
2
Clock Select
SSPM<3:0>
SMP:CKE 4
TMR2 Output
2
2
Edge
Select
Prescaler TOSC
4, 16, 64
Preliminary
DS41303C-page 189
PIC18F2XK20/4XK20
17.3.1
REGISTERS
REGISTER 17-1:
During
transmission,
the
SSPBUF
is
not
double-buffered. A write to SSPBUF will write to both
SSPBUF and SSPSR.
R/W-0
R/W-0
R-0
R-0
R-0
R-0
R-0
R-0
SMP
CKE
D/A
R/W
UA
BF
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
bit 4
P: Stop bit
Used in I2C mode only. This bit is cleared when the MSSP module is disabled, SSPEN is cleared.
bit 3
S: Start bit
Used in I2C mode only.
bit 2
bit 1
bit 0
Note 1:
Polarity of clock state is set by the CKP bit of the SSPCON1 register.
DS41303C-page 190
Preliminary
PIC18F2XK20/4XK20
REGISTER 17-2:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
WCOL
SSPOV
SSPEN
CKP
SSPM3
SSPM2
SSPM1
SSPM0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
bit 4
bit 3-0
Note 1:
2:
3:
In Master mode, the overflow bit is not set since each new reception (and transmission) is initiated by
writing to the SSPBUF register.
When enabled, these pins must be properly configured as input or output.
Bit combinations not specifically listed here are either reserved or implemented in I2C mode only.
Preliminary
DS41303C-page 191
PIC18F2XK20/4XK20
17.3.2
OPERATION
EXAMPLE 17-1:
LOOP
BTFSS
BRA
MOVF
SSPSTAT, BF
LOOP
SSPBUF, W
MOVWF
RXDATA
MOVF
MOVWF
TXDATA, W
SSPBUF
DS41303C-page 192
Preliminary
PIC18F2XK20/4XK20
17.3.3
17.3.4
TYPICAL CONNECTION
FIGURE 17-2:
SDI
SDI
Shift Register
(SSPSR)
MSb
SDO
LSb
MSb
SCK
Serial Clock
Processor 1
Shift Register
(SSPSR)
LSb
SCK
Processor 2
Preliminary
DS41303C-page 193
PIC18F2XK20/4XK20
17.3.5
MASTER MODE
FIGURE 17-3:
Write to
SSPBUF
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
4 Clock
Modes
SCK
(CKP = 0
CKE = 1)
SCK
(CKP = 1
CKE = 1)
SDO
(CKE = 0)
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
SDO
(CKE = 1)
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
SDI
(SMP = 0)
bit 0
bit 7
Input
Sample
(SMP = 0)
SDI
(SMP = 1)
bit 0
bit 7
Input
Sample
(SMP = 1)
SSPIF
Next Q4 Cycle
after Q2
SSPSR to
SSPBUF
DS41303C-page 194
Preliminary
PIC18F2XK20/4XK20
17.3.6
SLAVE MODE
17.3.7
SLAVE SELECT
SYNCHRONIZATION
FIGURE 17-4:
SS
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
Write to
SSPBUF
SDO
SDI
(SMP = 0)
bit 7
bit 6
bit 7
bit 0
bit 0
bit 7
bit 7
Input
Sample
(SMP = 0)
SSPIF
Interrupt
Flag
Next Q4 Cycle
after Q2
SSPSR to
SSPBUF
Preliminary
DS41303C-page 195
PIC18F2XK20/4XK20
FIGURE 17-5:
SS
Optional
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
Write to
SSPBUF
SDO
SDI
(SMP = 0)
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
bit 0
bit 7
Input
Sample
(SMP = 0)
SSPIF
Interrupt
Flag
Next Q4 Cycle
after Q2
SSPSR to
SSPBUF
FIGURE 17-6:
SS
Not Optional
SCK
(CKP = 0
CKE = 1)
SCK
(CKP = 1
CKE = 1)
Write to
SSPBUF
SDO
bit 7
SDI
(SMP = 0)
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
bit 0
Input
Sample
(SMP = 0)
SSPIF
Interrupt
Flag
Next Q4 Cycle
after Q2
SSPSR to
SSPBUF
DS41303C-page 196
Preliminary
PIC18F2XK20/4XK20
17.3.8
OPERATION IN POWER-MANAGED
MODES
17.3.9
17.3.10
EFFECTS OF A RESET
TABLE 17-1:
CKP
CKE
0, 0
0, 1
1, 0
1, 1
TABLE 17-2:
Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
INTCON
PIR1
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
PSPIE(1)
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR1
PSPIP(1)
ADIP
60
TRISA
TRISA7(2) TRISA6(2)
TRISC
SSPBUF
TRISC7
TRISC6
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
TRISA5
TRISA4
TRISA3
TRISA2
TRISA1
TRISA0
60
TRISC5
TRISC4
TRISC3
TRISC2
TRISC1
TRISC0
60
58
SSPCON1
WCOL
SSPOV
SSPEN
CKP
SSPM3
SSPM2
SSPM1
SSPM0
58
SSPSTAT
SMP
CKE
D/A
R/W
UA
BF
58
Legend: Shaded cells are not used by the MSSP in SPI mode.
Note 1: These bits are unimplemented in 28-pin devices; always maintain these bits clear.
2: PORTA<7:6> and their direction bits are individually configured as port pins based on various primary
oscillator modes. When disabled, these bits read as 0.
Preliminary
DS41303C-page 197
PIC18F2XK20/4XK20
17.4
I2C Mode
17.4.1
FIGURE 17-7:
Write
SSPSR Reg
MSb
LSb
Addr Match
SSPADD Reg
Start and
Stop bit Detect
DS41303C-page 198
SSPMSK Reg
Match Detect
Shift
Clock
SDI/SDA
SSPBUF Reg
SCK/SCL
REGISTERS
Set, Reset
S, P bits
(SSPSTAT Reg)
During
transmission,
the
SSPBUF
is
not
double-buffered. A write to SSPBUF will write to both
SSPBUF and SSPSR.
Preliminary
PIC18F2XK20/4XK20
REGISTER 17-3:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
ADD7
ADD6
ADD5
ADD4
ADD3
ADD2
ADD1
ADD0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
Master mode
bit 7
bit 6-0
Not used: Unused for most significant address byte. Bit state of this register is a dont care. Bit pattern
sent by master is fixed by I2C specification and must be equal to 11110. However, those bits are
compared by hardware and are not affected by the value in this register.
bit 2-1
bit 0
bit 0
Preliminary
DS41303C-page 199
PIC18F2XK20/4XK20
REGISTER 17-4:
R/W-0
SMP
CKE
R-0
R-0
R-0
D/A
(1)
(1)
R-0
R/W
(2, 3)
R-0
R-0
UA
BF
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
bit 4
P: Stop bit(1)
1 = Indicates that a Stop bit has been detected last
0 = Stop bit was not detected last
bit 3
S: Start bit(1)
1 = Indicates that a Start bit has been detected last
0 = Start bit was not detected last
bit 2
bit 1
bit 0
Note 1:
2:
3:
DS41303C-page 200
Preliminary
PIC18F2XK20/4XK20
REGISTER 17-5:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
WCOL
SSPOV
SSPEN
CKP
SSPM3
SSPM2
SSPM1
SSPM0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
bit 4
bit 3-0
Preliminary
DS41303C-page 201
PIC18F2XK20/4XK20
REGISTER 17-6:
R/W-0
GCEN
ACKSTAT
R/W-0
(2)
ACKDT
R/W-0
(1)
ACKEN
R/W-0
(1)
RCEN
R/W-0
(1)
PEN
R/W-0
(1)
RSEN
R/W-0
SEN(1)
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1:
2:
For bits ACKEN, RCEN, PEN, RSEN, SEN: If the I2C module is not in the Idle mode, these bits may not
be set (no spooling) and the SSPBUF may not be written (or writes to the SSPBUF are disabled).
Value that will be transmitted when the user initiates an Acknowledge sequence at the end of a receive.
DS41303C-page 202
Preliminary
PIC18F2XK20/4XK20
17.4.2
OPERATION
17.4.3.1
17.4.3
SLAVE MODE
In Slave mode, the SCL and SDA pins must be configured as inputs. The MSSP module will override the
input state with the output data when required
(slave-transmitter).
The I 2C Slave mode hardware will always generate an
interrupt on an address match. Through the mode
select bits, the user can also choose to interrupt on
Start and Stop bits
When an address is matched, or the data transfer after
an address match is received, the hardware
automatically will generate the Acknowledge (ACK)
pulse and load the SSPBUF register with the received
value currently in the SSPSR register.
Any combination of the following conditions will cause
the MSSP module not to give this ACK pulse:
The Buffer Full bit, BF bit of the SSPSTAT register, is set before the transfer is received.
The overflow bit, SSPOV bit of the SSPCON1
register, is set before the transfer is received.
3.
4.
5.
6.
Addressing
7.
8.
9.
Preliminary
DS41303C-page 203
PIC18F2XK20/4XK20
17.4.3.2
Reception
17.4.3.3
Transmission
DS41303C-page 204
Preliminary
Preliminary
CKP
A6
A4
A3
Receiving Address
A5
A2
SSPOV (SSPCON1<6>)
BF (SSPSTAT<0>)
(PIR1<3>)
SSPIF
SCL
A7
A1
ACK
R/W = 0
D7
D4
D3
Receiving Data
D5
Cleared by software
SSPBUF is read
D6
D2
D1
D0
ACK
D7
D6
D4
D3
Receiving Data
D5
D2
D1
D0
Bus master
terminates
transfer
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
ACK
FIGURE 17-8:
SDA
PIC18F2XK20/4XK20
DS41303C-page 205
DS41303C-page 206
Preliminary
CKP
A6
Data in
sampled
BF (SSPSTAT<0>)
SSPIF (PIR1<3>)
A7
A4
A3
A2
Receiving Address
A5
A1
R/W = 0
ACK
D7
D5
D3
D2
Transmitting Data
D4
Cleared by software
D6
D0
D1
ACK
D7
D4
D3
Cleared by software
D5
D2
D6
D0
ACK
D1
Transmitting Data
FIGURE 17-9:
SCL
SDA
PIC18F2XK20/4XK20
I2C SLAVE MODE TIMING (TRANSMISSION, 7-BIT ADDRESS)
Preliminary
A8
A9
UA (SSPSTAT<1>)
SSPOV (SSPCON1<6>)
CKP
Cleared by software
BF (SSPSTAT<0>)
(PIR1<3>)
SSPIF
SCL
ACK
R/W = 0
A7
A4
A3
A2
A0 ACK
Cleared by hardware
when SSPADD is updated
with low byte of address
A1
Cleared by software
A5
A6
D7
Cleared by software
9
1
D1 D0
Cleared by software
D3 D2
D3 D2
P
Bus master
terminates
transfer
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
ACK
FIGURE 17-10:
SDA
PIC18F2XK20/4XK20
DS41303C-page 207
DS41303C-page 208
Preliminary
CKP (SSPCON1<4>)
UA (SSPSTAT<1>)
BF (SSPSTAT<0>)
(PIR1<3>)
SSPIF
SCL
A9 A8
ACK
R/W = 0
Cleared by software
A6 A5 A4 A3 A2 A1
A0
A7
ACK
Cleared by software
ACK
R/W=1
ACK
Bus master
terminates
transfer
Completion of
data transmission
clears BF flag
D4 D3 D2 D1 D0
Cleared by software
D7 D6 D5
Write of SSPBUF
BF flag is clear
initiates transmit
at the end of the
third address sequence
A9 A8
Sr
FIGURE 17-11:
SDA
PIC18F2XK20/4XK20
I2C SLAVE MODE TIMING (TRANSMISSION, 10-BIT ADDRESS)
PIC18F2XK20/4XK20
17.4.3.4
REGISTER 17-7:
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
MSK7
MSK6
MSK5
MSK4
MSK3
MSK2
MSK1
MSK0(1)
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7-1
bit 0
Note 1: The MSK0 bit is used only in 10-bit slave mode. In all other modes, this bit has no effect.
Preliminary
DS41303C-page 209
PIC18F2XK20/4XK20
17.4.4
CLOCK STRETCHING
17.4.4.3
17.4.4.1
17.4.4.2
17.4.4.4
In 10-bit Slave Transmit mode, clock stretching is controlled during the first two address sequences by the
state of the UA bit, just as it is in 10-bit Slave Receive
mode. The first two addresses are followed by a third
address sequence which contains the high-order bits
of the 10-bit address and the R/W bit set to 1. After
the third address sequence is performed, the UA bit is
not set, the module is now configured in Transmit
mode and clock stretching is controlled by the BF flag
as in 7-bit Slave Transmit mode (see Figure 17-11).
DS41303C-page 210
Preliminary
PIC18F2XK20/4XK20
17.4.4.5
FIGURE 17-12:
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
SDA
DX
DX 1
SCL
CKP
Master device
asserts clock
Master device
deasserts clock
WR
SSPCON1
Preliminary
DS41303C-page 211
DS41303C-page 212
Preliminary
CKP
SSPOV (SSPCON1<6>)
BF (SSPSTAT<0>)
(PIR1<3>)
SSPIF
SCL
A7
A6
A4
A3
A2
Receiving Address
A5
A1
ACK
R/W = 0
D4
D3
Receiving Data
D5
Cleared by software
D6
If BF is cleared
prior to the falling
edge of the 9th clock,
CKP will not be reset
to 0 and no clock
stretching will occur
SSPBUF is read
D7
D2
D1
ACK
D7
D0
D4
D3
Receiving Data
D5
CKP
written
to 1 in
software
D6
D2
D1
D0
Bus master
terminates
transfer
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
ACK
FIGURE 17-13:
SDA
PIC18F2XK20/4XK20
I2C SLAVE MODE TIMING WITH SEN = 1 (RECEPTION, 7-BIT ADDRESS)
Preliminary
UA (SSPSTAT<1>)
SSPOV (SSPCON1<6>)
CKP
A9 A8
Cleared by software
BF (SSPSTAT<0>)
(PIR1<3>)
SSPIF
SCL
ACK
R/W = 0
A7
A4
A3
A2
Cleared by software
A5
A1
A0
A6
ACK
ACK
ACK
Bus master
terminates
transfer
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
D1 D0
Cleared by software
CKP written to 1
by software
D3 D2
D1 D0
Cleared by software
D3 D2
D7 D6 D5 D4
FIGURE 17-14:
SDA
PIC18F2XK20/4XK20
DS41303C-page 213
PIC18F2XK20/4XK20
17.4.5
FIGURE 17-15:
SDA
SCL
S
Receiving Data
ACK
D6
D5
D4
D3
D2
D1
D0
SSPIF
BF (SSPSTAT<0>)
Cleared by software
SSPBUF is read
SSPOV (SSPCON1<6>)
GCEN (SSPCON2<7>)
1
DS41303C-page 214
Preliminary
PIC18F2XK20/4XK20
MASTER MODE
Note:
FIGURE 17-16:
Start condition
Stop condition
Data transfer byte transmitted/received
Acknowledge transmit
Repeated Start
SSPM<3:0>
SSPADD<6:0>
Write
SSPBUF
SDA
Baud
Rate
Generator
Shift
Clock
SDA In
SCL In
Bus Collision
LSb
Preliminary
Clock Cntl
SCL
Receive Enable
SSPSR
MSb
17.4.6
DS41303C-page 215
PIC18F2XK20/4XK20
17.4.6.1
DS41303C-page 216
1.
Preliminary
PIC18F2XK20/4XK20
17.4.7
BAUD RATE
FIGURE 17-17:
SSPM<3:0>
Reload
SCL
Control
CLKOUT
Reload
FOSC/2
TABLE 17-3:
Note 1:
SSPADD<7:0>
FOSC
FCY
BRG Value
FSCL
(2 Rollovers of BRG)
64 MHz
16 MHz
27h
400 kHz(1)
64 MHz
16 MHz
32h
313.7 kHz
64 MHz
16 MHz
3Fh
250 kHz
40 MHz
10 MHz
18h
400 kHz(1)
40 MHz
10 MHz
1Fh
312.5 kHz
40 MHz
10 MHz
63h
100 kHz
16 MHz
4 MHz
09h
400 kHz(1)
16 MHz
4 MHz
0Ch
308 kHz
16 MHz
4 MHz
27h
100 kHz
4 MHz
1 MHz
02h
333 kHz(1)
4 MHz
1 MHz
09h
100 kHz
4 MHz
1 MHz
00h
1 MHz(1)
I2C
I2C
The
interface does not conform to the 400 kHz
specification (which applies to rates greater than
100 kHz) in all details, but may be used with care where higher rates are required by the application.
Preliminary
DS41303C-page 217
PIC18F2XK20/4XK20
17.4.7.1
Clock Arbitration
FIGURE 17-18:
SDA
DX
DX 1
SCL
BRG decrements on
Q2 and Q4 cycles
BRG
Value
03h
02h
01h
03h
02h
DS41303C-page 218
Preliminary
PIC18F2XK20/4XK20
17.4.8
Note:
FIGURE 17-19:
17.4.8.1
SDA
2nd bit
TBRG
SCL
TBRG
S
Preliminary
DS41303C-page 219
PIC18F2XK20/4XK20
17.4.9
17.4.9.1
FIGURE 17-20:
TBRG
TBRG
TBRG
1st bit
SDA
RSEN bit set by hardware
on falling edge of ninth clock,
end of Xmit
SCL
TBRG
Sr = Repeated Start
DS41303C-page 220
Preliminary
PIC18F2XK20/4XK20
17.4.10
17.4.10.3
17.4.10.1
BF Status Flag
17.4.10.2
17.4.11
17.4.11.1
BF Status Flag
17.4.11.2
17.4.11.3
Preliminary
DS41303C-page 221
DS41303C-page 222
S
Preliminary
R/W
PEN
SEN
BF (SSPSTAT<0>)
SSPIF
SCL
SDA
A6
A5
A4
A3
A2
A1
Cleared by software
SSPBUF written
D7
1
SCL held low
while CPU
responds to SSPIF
ACK = 0
R/W = 0
A7
D5
D4
D3
D2
D1
D0
D6
Cleared by software
ACK
ACKSTAT in
SSPCON2 = 1
FIGURE 17-21:
SEN = 0
PIC18F2XK20/4XK20
I 2C MASTER MODE WAVEFORM (TRANSMISSION, 7 OR 10-BIT ADDRESS)
Preliminary
ACKEN
SSPOV
BF
(SSPSTAT<0>)
SDA = 0, SCL = 1
while CPU
responds to SSPIF
SSPIF
SCL
SDA
A7
4
5
Cleared by software
A6 A5 A4 A3 A2
A1
R/W = 0
ACK
D0
ACK
Cleared by software
D7 D6 D5 D4 D3 D2 D1
Cleared in
software
ACK
P
Set SSPIF interrupt
at end of Acknowledge sequence
Bus master
terminates
transfer
Set P bit
(SSPSTAT<4>)
and SSPIF
PEN bit = 1
written here
D0
RCEN cleared
automatically
RCEN = 1, start
next receive
Cleared by software
Cleared by software
D7 D6 D5 D4 D3 D2 D1
RCEN cleared
automatically
FIGURE 17-22:
SEN = 0
Write to SSPBUF occurs here,
start XMIT
Write to SSPCON2<4>
to start Acknowledge sequence
SDA = ACKDT (SSPCON2<5>) = 0
PIC18F2XK20/4XK20
DS41303C-page 223
PIC18F2XK20/4XK20
17.4.12
ACKNOWLEDGE SEQUENCE
TIMING
17.4.13
17.4.12.1
17.4.13.1
FIGURE 17-23:
TBRG
SDA
ACK
D0
SCL
SSPIF
SSPIF set at
the end of receive
Cleared in
software
SSPIF set at the end
of Acknowledge sequence
Cleared in
software
FIGURE 17-24:
Write to SSPCON2,
set PEN
Falling edge of
9th clock
TBRG
SCL
SDA
ACK
P
TBRG
TBRG
TBRG
DS41303C-page 224
Preliminary
PIC18F2XK20/4XK20
17.4.14
SLEEP OPERATION
17.4.17
17.4.15
EFFECTS OF A RESET
17.4.16
MULTI-MASTER MODE
Address Transfer
Data Transfer
A Start Condition
A Repeated Start Condition
An Acknowledge Condition
Multi-Master mode support is achieved by bus arbitration. When the master outputs address/data bits onto
the SDA pin, arbitration takes place when the master
outputs a 1 on SDA, by letting SDA float high and
another master asserts a 0. When the SCL pin floats
high, data should be stable. If the expected data on
SDA is a 1 and the data sampled on the SDA pin = 0,
then a bus collision has taken place. The master will set
the Bus Collision Interrupt Flag, BCLIF and reset the
I2C port to its Idle state (Figure 17-25).
If a transmit was in progress when the bus collision
occurred, the transmission is halted, the BF flag is
cleared, the SDA and SCL lines are deasserted and the
SSPBUF can be written to. When the user services the
bus collision Interrupt Service Routine and if the I2C
bus is free, the user can resume communication by
asserting a Start condition.
If a Start, Repeated Start, Stop or Acknowledge condition was in progress when the bus collision occurred, the
condition is aborted, the SDA and SCL lines are deasserted and the respective control bits in the SSPCON2
register are cleared. When the user services the bus collision Interrupt Service Routine and if the I2C bus is free,
the user can resume communication by asserting a Start
condition.
The master will continue to monitor the SDA and SCL
pins. If a Stop condition occurs, the SSPIF bit will be set.
A write to the SSPBUF will start the transmission of
data at the first data bit, regardless of where the
transmitter left off when the bus collision occurred.
In Multi-Master mode, the interrupt generation on the
detection of Start and Stop conditions allows the determination of when the bus is free. Control of the I2C bus
can be taken when the P bit is set in the SSPSTAT
register, or the bus is Idle and the S and P bits are
cleared.
FIGURE 17-25:
SDA
SCL
BCLIF
Preliminary
DS41303C-page 225
PIC18F2XK20/4XK20
17.4.17.1
FIGURE 17-26:
SDA
SCL
Set SEN, enable Start
condition if SDA = 1, SCL = 1
SEN
BCLIF
SSPIF
SSPIF and BCLIF are
cleared by software
DS41303C-page 226
Preliminary
PIC18F2XK20/4XK20
FIGURE 17-27:
TBRG
SDA
Set SEN, enable Start
sequence if SDA = 1, SCL = 1
SCL
SEN
SCL = 0 before BRG time-out,
bus collision occurs. Set BCLIF.
BCLIF
Interrupt cleared
by software
S
SSPIF
FIGURE 17-28:
SDA
Set SSPIF
TBRG
SCL
S
SCL pulled low after BRG
time-out
SEN
BCLIF
SSPIF
SDA = 0, SCL = 1,
set SSPIF
Preliminary
Interrupts cleared
by software
DS41303C-page 227
PIC18F2XK20/4XK20
17.4.17.2
FIGURE 17-29:
If, at the end of the BRG time-out, both SCL and SDA
are still high, the SDA pin is driven low and the BRG is
reloaded and begins counting. At the end of the count,
regardless of the status of the SCL pin, the SCL pin is
driven low and the Repeated Start condition is
complete.
SDA
SCL
Sample SDA when SCL goes high.
If SDA = 0, set BCLIF and release SDA and SCL.
RSEN
BCLIF
Cleared by software
0
SSPIF
FIGURE 17-30:
TBRG
SDA
SCL
BCLIF
RSEN
0
S
SSPIF
DS41303C-page 228
Preliminary
PIC18F2XK20/4XK20
17.4.17.3
b)
FIGURE 17-31:
TBRG
TBRG
SDA
SDA sampled
low after TBRG,
set BCLIF
SSPIF
FIGURE 17-32:
TBRG
TBRG
SDA
SCL goes low before SDA goes high,
set BCLIF
Assert SDA
SCL
PEN
BCLIF
P
SSPIF
Preliminary
DS41303C-page 229
PIC18F2XK20/4XK20
TABLE 17-4:
Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values on
page
60
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
PIR1
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR2
BCLIP
60
PIR2
BCLIF
60
PIE2
BCLIE
60
SSPADD
SSP Address Register in I2C Slave Mode. SSP Baud Rate Reload Register in I2C Master Mode.
58
SSPBUF
58
SSPCON1
WCOL
SSPOV
SSPEN
CKP
SSPM3
SSPM2
SSPM1
SSPM0
58
SSPCON2
GCEN
ACKSTAT
ACKDT
ACKEN
RCEN
PEN
RSEN
SEN
58
SSPMSK
MSK7
MSK6
MSK5
MSK4
MSK3
MSK2
MSK1
MSK0
61
SSPSTAT
TRISC
Legend:
SMP
CKE
D/A
R/W
UA
BF
58
TRISC7
TRISC6
TRISC5
TRISC4
TRISC3
TRISC2
TRISC1
TRISC0
60
DS41303C-page 230
Preliminary
PIC18F2XK20/4XK20
18.0
ENHANCED UNIVERSAL
SYNCHRONOUS
ASYNCHRONOUS RECEIVER
TRANSMITTER (EUSART)
FIGURE 18-1:
TXIE
Interrupt
TXIF
TXREG Register
8
TX/CK pin
MSb
LSb
(8)
Pin Buffer
and Control
TRMT
SPEN
Transmit Shift Register (TSR)
TXEN
Baud Rate Generator
FOSC
TX9
BRG16
+1
SPBRGH
SPBRG
Multiplier
x4
x16 x64
SYNC
1 X 0 0
BRGH
X 1 1 0
BRG16
X 1 0 1
TX9D
Preliminary
DS41303C-page 231
PIC18F2XK20/4XK20
FIGURE 18-2:
CREN
RX/DT pin
Data
Recovery
FOSC
SPBRGH
SPBRG
x4
x16 x64
SYNC
1 X 0 0
BRGH
X 1 1 0
BRG16
X 1 0 1
(8)
LSb
0 START
RX9
BRG16
Multiplier
Stop
RCIDL
RSR Register
MSb
Pin Buffer
and Control
+1
OERR
FERR
RX9D
RCREG Register
8
FIFO
Data Bus
RCIF
RCIE
Interrupt
DS41303C-page 232
Preliminary
PIC18F2XK20/4XK20
18.1
18.1.1
EUSART ASYNCHRONOUS
TRANSMITTER
18.1.1.2
Transmitting Data
18.1.1.3
18.1.1.1
Note 1: When the SPEN bit is set the RX/DT I/O pin
is automatically configured as an input,
regardless of the state of the corresponding
TRIS bit and whether or not the EUSART
receiver is enabled. The RX/DT pin data
can be read via a normal PORT read but
PORT latch data output is precluded.
18.1.1.4
Preliminary
DS41303C-page 233
PIC18F2XK20/4XK20
18.1.1.5
TSR Status
18.1.1.7
18.1.1.6
1.
2.
3.
5.
8.
FIGURE 18-3:
Write to TXREG
BRG Output
(Shift Clock)
RC4/C2OUT/TX/CK
pin
TXIF bit
(Transmit Buffer
Reg. Empty Flag)
TRMT bit
(Transmit Shift
Reg. Empty Flag)
DS41303C-page 234
6.
7.
ASYNCHRONOUS TRANSMISSION
Word 1
Start bit
bit 0
bit 1
bit 7/8
Stop bit
Word 1
1 TCY
Word 1
Transmit Shift Reg
Preliminary
PIC18F2XK20/4XK20
FIGURE 18-4:
Write to TXREG
Word 1
BRG Output
(Shift Clock)
RC4/C2OUT/TX/CK
pin
Start bit
bit 1
Word 1
bit 7/8
Stop bit
Start bit
bit 0
Word 2
1 TCY
TRMT bit
(Transmit Shift
Reg. Empty Flag)
Word 1
Transmit Shift Reg
Word 2
Transmit Shift Reg
TABLE 18-1:
Name
bit 0
1 TCY
TXIF bit
(Interrupt Reg. Flag)
Note:
Word 2
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
INTCON
GIE/GIEH PEIE/GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
PIR1
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
PSPIE(1)
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR1
PSPIP(1)
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
60
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
59
RCSTA
TXREG
TXSTA
59
CSRC
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
59
BAUDCTL
ABDOVF
RCIDL
DTRXP
CKTXP
BRG16
WUE
ABDEN
59
SPBRGH
59
SPBRG
59
Legend: = unimplemented locations read as 0. Shaded cells are not used for asynchronous transmission.
Note 1: Reserved in PIC18F2XK20 devices; always maintain these bits clear.
Preliminary
DS41303C-page 235
PIC18F2XK20/4XK20
18.1.2
EUSART ASYNCHRONOUS
RECEIVER
18.1.2.2
18.1.2.1
DS41303C-page 236
Receiving Data
18.1.2.3
Preliminary
PIC18F2XK20/4XK20
18.1.2.4
Receive Interrupts
18.1.2.7
18.1.2.5
18.1.2.8
Address Detection
18.1.2.6
Preliminary
DS41303C-page 237
PIC18F2XK20/4XK20
18.1.2.9
18.1.2.10
1.
FIGURE 18-5:
Rcv Shift
Reg
Rcv Buffer Reg
RCIDL
ASYNCHRONOUS RECEPTION
Start
bit
bit 0
RX/DT pin
bit 1
Start
bit
bit 0
Word 1
RCREG
Start
bit
Word 2
RCREG
Read Rcv
Buffer Reg
RCREG
RCIF
(Interrupt Flag)
OERR bit
CREN
Note:
This timing diagram shows three words appearing on the RX input. The RCREG (receive buffer) is read after the third word,
causing the OERR (overrun) bit to be set.
DS41303C-page 238
Preliminary
PIC18F2XK20/4XK20
TABLE 18-2:
Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
INTCON
GIE/GIEH PEIE/GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
PIR1
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
PSPIE(1)
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR1
PSPIP(1)
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
60
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
RCSTA
RCREG
59
59
TRISC
TRISC7
TRISC6
TRISC5
TRISC4
TRISC3
TRISC2
TRISC1
TRISC0
60
TXSTA
CSRC
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
59
BAUDCTL
ABDOVF
RCIDL
DTRXP
CKTXP
BRG16
WUE
ABDEN
SPBRGH
59
SPBRG
59
59
Legend: = unimplemented locations read as 0. Shaded cells are not used for asynchronous reception.
Note 1: Reserved in PIC18F2XK20 devices; always maintain these bits clear.
Preliminary
DS41303C-page 239
PIC18F2XK20/4XK20
18.2
The factory calibrates the internal oscillator block output (HFINTOSC). However, the HFINTOSC frequency
may drift as VDD or temperature changes, and this
directly affects the asynchronous baud rate. Two methods may be used to adjust the baud rate clock, but both
require a reference clock source of some kind.
REGISTER 18-1:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R-1
R/W-0
CSRC
TX9
TXEN(1)
SYNC
SENDB
BRGH
TRMT
TX9D
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1:
DS41303C-page 240
Preliminary
PIC18F2XK20/4XK20
REGISTER 18-2:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R-0
R-0
R-x
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
Preliminary
DS41303C-page 241
PIC18F2XK20/4XK20
REGISTER 18-3:
R-0
R-1
R/W-0
R/W-0
R/W-0
U-0
R/W-0
R/W-0
ABDOVF
RCIDL
DTRXP
CKTXP
BRG16
WUE
ABDEN
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
Unimplemented: Read as 0
bit 1
bit 0
DS41303C-page 242
Preliminary
PIC18F2XK20/4XK20
18.3
EXAMPLE 18-1:
F OS C
Desired Baud Rate = --------------------------------------------------------------------64 ( [SPBRGH:SPBRG] + 1 )
16000000
-----------------------9600
= ------------------------ 1
64
= [ 25.042 ] = 25
16000000
Calculated Baud Rate = --------------------------64 ( 25 + 1 )
= 9615
TABLE 18-3:
CALCULATING BAUD
RATE ERROR
Configuration Bits
BRG/EUSART Mode
8-bit/Asynchronous
FOSC/[64 (n+1)]
8-bit/Asynchronous
16-bit/Asynchronous
16-bit/Asynchronous
8-bit/Synchronous
16-bit/Synchronous
SYNC
BRG16
BRGH
1
Legend:
FOSC/[4 (n+1)]
TABLE 18-4:
Name
FOSC/[16 (n+1)]
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Reset Values
on page
Bit 0
TXSTA
CSRC
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
59
RCSTA
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
59
BAUDCTL
ABDOVF
RCIDL
DTRXP
CKTXP
BRG16
WUE
ABDEN
59
SPBRGH
59
SPBRG
59
Legend: = unimplemented, read as 0. Shaded cells are not used by the BRG.
Preliminary
DS41303C-page 243
PIC18F2XK20/4XK20
TABLE 18-5:
BAUD
RATE
Actual
Rate
%
Error
SPBRG
value
(decimal)
300
1200
1200
0.00
239
1202
0.16
207
1200
0.00
143
Actual
Rate
%
Error
SPBRG
value
(decimal)
Actual
Rate
%
Error
SPBRG
value
(decimal)
Actual
Rate
%
Error
SPBRG
value
(decimal)
2400
2400
0.00
119
2404
0.16
103
2400
0.00
71
9600
9615
0.16
103
9600
0.00
29
9615
0.16
25
9600
0.00
17
10417
10417
0.00
95
10286
-1.26
27
10417
0.00
23
10165
-2.42
16
19.2k
19.23k
0.16
51
19.20k
0.00
14
19.23k
0.16
12
19.20k
0.00
57.6k
58.82k
2.12
16
57.60k
0.00
57.60k
0.00
115.2k
111.11k
-3.55
%
Error
SPBRG
value
(decimal)
%
Error
SPBRG
value
(decimal)
%
Error
SPBRG
value
(decimal)
Actual
Rate
%
Error
SPBRG
value
(decimal)
300
300
0.16
207
300
0.00
191
300
0.16
51
1200
1202
0.16
103
1202
0.16
51
1200
0.00
47
1202
0.16
12
2400
2404
0.16
51
2404
0.16
25
2400
0.00
23
9600
9615
0.16
12
9600
0.00
10417
10417
0.00
11
10417
0.00
19.2k
19.20k
0.00
57.6k
57.60k
0.00
115.2k
%
Error
SPBRG
value
(decimal)
%
Error
SPBRG
value
(decimal)
%
Error
SPBRG
value
(decimal)
Actual
Rate
%
Error
SPBRG
value
(decimal)
300
1200
2400
9600
9600
0.00
119
9615
0.16
103
9600
0.00
71
10417
10378
-0.37
110
10417
0.00
95
10473
0.53
65
19.2k
19.23k
0.16
207
19.20k
0.00
59
19.23k
0.16
51
19.20k
0.00
35
57.6k
57.97k
0.64
68
57.60k
0.00
19
58.82k
2.12
16
57.60k
0.00
11
115.2k
114.29k
-0.79
34
115.2k
0.00
111.1k
-3.55
115.2k
0.00
DS41303C-page 244
Preliminary
PIC18F2XK20/4XK20
TABLE 18-5:
BAUD
RATE
%
Error
SPBRG
value
(decimal)
%
Error
SPBRG
value
(decimal)
%
Error
SPBRG
value
(decimal)
Actual
Rate
%
Error
SPBRG
value
(decimal)
300
1200
1202
0.16
207
1200
0.00
191
300
1202
0.16
0.16
207
51
2400
2404
0.16
207
2404
0.16
103
2400
0.00
95
2404
0.16
25
9600
9615
0.16
51
9615
0.16
25
9600
0.00
23
10417
10417
0.00
47
10417
0.00
23
10473
0.53
21
10417
0.00
19.2k
19231
0.16
25
19.23k
0.16
12
19.2k
0.00
11
57.6k
55556
-3.55
57.60k
0.00
115.2k
115.2k
0.00
%
Error
SPBRGH
:SPBRG
(decimal)
Actual
Rate
%
Error
SPBRGH
:SPBRG
(decimal)
%
Error
SPBRGH
:SPBRG
(decimal)
Actual
Rate
%
Error
SPBRGH
:SPBRG
(decimal)
300
300.0
0.00
13332
300.0
0.00
3839
300.03
0.01
3332
300.0
0.00
2303
1200
1200.1
0.01
3332
1200
0.00
959
1200.5
0.04
832
1200
0.00
575
2400
2399
-0.02
1666
2400
0.00
479
2398
-0.08
416
2400
0.00
287
9600
9592
-0.08
416
9600
0.00
119
9615
0.16
103
9600
0.00
71
10417
10417
0.00
383
10378
-0.37
110
10417
0.00
95
10473
0.53
65
19.2k
19.23k
0.16
207
19.20k
0.00
59
19.23k
0.16
51
19.20k
0.00
35
57.6k
57.97k
0.64
68
57.60k
0.00
19
58.82k
2.12
16
57.60k
0.00
11
115.2k
114.29k
-0.79
34
115.2k
0.00
111.11k
-3.55
115.2k
0.00
%
Error
SPBRGH
:SPBRG
(decimal)
%
Error
SPBRGH
:SPBRG
(decimal)
Actual
Rate
%
Error
SPBRGH
:SPBRG
(decimal)
Actual
Rate
%
Error
SPBRGH
:SPBRG
(decimal)
300
299.9
-0.02
1666
300.1
0.04
832
300.0
0.00
767
300.5
0.16
207
1200
1199
-0.08
416
1202
0.16
207
1200
0.00
191
1202
0.16
51
2400
2404
0.16
207
2404
0.16
103
2400
0.00
95
2404
0.16
25
9600
9615
0.16
51
9615
0.16
25
9600
0.00
23
10417
10417
0.00
47
10417
0.00
23
10473
0.53
21
10417
0.00
19.2k
19.23k
0.16
25
19.23k
0.16
12
19.20k
0.00
11
57.6k
55556
-3.55
57.60k
0.00
115.2k
115.2k
0.00
Preliminary
DS41303C-page 245
PIC18F2XK20/4XK20
TABLE 18-5:
BAUD
RATE
Actual
Rate
%
Error
SPBRGH
:SPBRG
(decimal)
300
1200
300
1200
0.00
0.00
53332
13332
300.0
1200
0.00
0.00
15359
3839
300.0
1200.1
0.00
0.01
13332
3332
300.0
1200
0.00
0.00
9215
2303
2400
2400
0.00
6666
2400
0.00
1919
2399.5
-0.02
1666
2400
0.00
1151
Actual
Rate
%
Error
SPBRGH
:SPBRG
(decimal)
Actual
Rate
%
Error
SPBRGH
:SPBRG
(decimal)
Actual
Rate
%
Error
SPBRGH
:SPBRG
(decimal)
9600
9598.1
-0.02
1666
9600
0.00
479
9592
-0.08
416
9600
0.00
287
10417
10417
0.00
1535
10425
0.08
441
10417
0.00
383
10433
0.16
264
19.2k
19.21k
0.04
832
19.20k
0.00
239
19.23k
0.16
207
19.20k
0.00
143
57.6k
57.55k
-0.08
277
57.60k
0.00
79
57.97k
0.64
68
57.60k
0.00
47
115.2k
115.11k
-0.08
138
115.2k
0.00
39
114.29k
-0.79
34
115.2k
0.00
23
%
Error
SPBRGH
:SPBRG
(decimal)
Actual
Rate
%
Error
SPBRGH
:SPBRG
(decimal)
Actual
Rate
%
Error
SPBRGH
:SPBRG
(decimal)
Actual
Rate
%
Error
SPBRGH
:SPBRG
(decimal)
832
300
300.0
0.00
6666
300.0
0.01
3332
300.0
0.00
3071
300.1
0.04
1200
1200
-0.02
1666
1200
0.04
832
1200
0.00
767
1202
0.16
207
2400
2401
0.04
832
2398
0.08
416
2400
0.00
383
2404
0.16
103
9600
9615
0.16
207
9615
0.16
103
9600
0.00
95
9615
0.16
25
10417
10417
0.00
191
10417
0.00
95
10473
0.53
87
10417
0.00
23
19.2k
19.23k
0.16
103
19.23k
0.16
51
19.20k
0.00
47
19.23k
0.16
12
57.6k
57.14k
-0.79
34
58.82k
2.12
16
57.60k
0.00
15
115.2k
117.6k
2.12
16
111.1k
-3.55
115.2k
0.00
DS41303C-page 246
Preliminary
PIC18F2XK20/4XK20
18.3.1
AUTO-BAUD DETECT
TABLE 18-6:
FIGURE 18-6:
BRG16
BRGH
BRG Base
Clock
BRG ABD
Clock
FOSC/64
FOSC/512
FOSC/16
FOSC/128
FOSC/16
FOSC/128
FOSC/4
FOSC/32
1
Note:
BRG Value
RX pin
0000h
001Ch
Start
Edge #1
bit 1
bit 0
Edge #2
bit 3
bit 2
Edge #3
bit 5
bit 4
Edge #4
bit 7
bit 6
Edge #5
Stop bit
BRG Clock
Auto Cleared
Set by User
ABDEN bit
RCIDL
RCIF bit
(Interrupt)
Read
RCREG
SPBRG
XXh
1Ch
SPBRGH
XXh
00h
Note 1:
The ABD sequence requires the EUSART module to be configured in Asynchronous mode.
Preliminary
DS41303C-page 247
PIC18F2XK20/4XK20
18.3.2
AUTO-WAKE-UP ON BREAK
18.3.2.1
Special Considerations
Break Character
To avoid character errors or character fragments during
a wake-up event, the wake-up character must be all
zeros.
When the wake-up is enabled the function works
independent of the low time on the data stream. If the
WUE bit is set and a valid non-zero character is
received, the low time from the Start bit to the first rising
edge will be interpreted as the wake-up event. The
remaining bits in the character will be received as a
fragmented character and subsequent characters can
result in framing or overrun errors.
Therefore, the initial character in the transmission must
be all 0s. This must be 10 or more bit times, 13-bit
times recommended for LIN bus, or any number of bit
times for standard RS-232 devices.
Oscillator Startup Time
Oscillator start-up time must be considered, especially
in applications using oscillators with longer start-up
intervals (i.e., LP, XT or HS/PLL mode). The Sync
Break (or wake-up signal) character must be of
sufficient length, and be followed by a sufficient
interval, to allow enough time for the selected oscillator
to start and provide proper initialization of the EUSART.
WUE Bit
The wake-up event causes a receive interrupt by
setting the RCIF bit. The WUE bit is cleared by
hardware by a rising edge on RX/DT. The interrupt
condition is then cleared by software by reading the
RCREG register and discarding its contents.
To ensure that no actual data is lost, check the RCIDL
bit to verify that a receive operation is not in process
before setting the WUE bit. If a receive operation is not
occurring, the WUE bit may then be set just prior to
entering the Sleep mode.
FIGURE 18-7:
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
OSC1
Auto Cleared
WUE bit
RX/DT Line
RCIF
Note 1:
DS41303C-page 248
Preliminary
PIC18F2XK20/4XK20
FIGURE 18-8:
Q1
Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1Q2 Q3 Q4
OSC1
Auto Cleared
Note 1
RCIF
Sleep Command Executed
Note 1:
2:
18.3.3
If the wake-up event requires long oscillator warm-up time, the automatic clearing of the WUE bit can occur while the stposc signal is
still active. This sequence should not depend on the presence of Q clocks.
The EUSART remains in Idle while the WUE bit is set.
18.3.3.1
Sleep Ends
18.3.4
Preliminary
DS41303C-page 249
PIC18F2XK20/4XK20
FIGURE 18-9:
Write to TXREG
BRG Output
(Shift Clock)
TX (pin)
Start bit
bit 0
bit 1
bit 11
Stop bit
Break
TXIF bit
(Transmit
interrupt Flag)
TRMT bit
(Transmit Shift
Reg. Empty Flag)
SENDB
(send Break
control bit)
DS41303C-page 250
Preliminary
Auto Cleared
PIC18F2XK20/4XK20
18.4
18.4.1.2
18.4.1
SYNC = 1
CSRC = 1
SREN = 0 (for transmit); SREN = 1 (for receive)
CREN = 0 (for transmit); CREN = 1 (for receive)
SPEN = 1
Clock Polarity
18.4.1.3
Note:
18.4.1.4
Data Polarity
18.4.1.1
Master Clock
Preliminary
DS41303C-page 251
PIC18F2XK20/4XK20
18.4.1.5
1.
2.
3.
4.
5.
6.
FIGURE 18-10:
7.
8.
SYNCHRONOUS TRANSMISSION
RX/DT
pin
bit 0
bit 1
Word 1
bit 2
bit 7
bit 0
bit 1
Word 2
bit 7
TX/CK pin
(SCKP = 0)
TX/CK pin
(SCKP = 1)
Write to
TXREG Reg
Write Word 1
Write Word 2
TXIF bit
(Interrupt Flag)
TRMT bit
TXEN bit
Note:
1
Sync Master mode, SPBRG = 0, continuous transmission of two 8-bit words.
FIGURE 18-11:
bit 0
bit 1
bit 2
bit 6
bit 7
TX/CK pin
Write to
TXREG reg
TXIF bit
TRMT bit
TXEN bit
DS41303C-page 252
Preliminary
PIC18F2XK20/4XK20
TABLE 18-7:
Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
INTCON
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
PIR1
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
(1)
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR1
PSPIP(1)
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
60
RCSTA
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
59
TRISC
TRISC7
TRISC6
TRISC5
TRISC4
TRISC3
TRISC2
TRISC1
TRISC0
60
TXREG
59
CSRC
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
59
BAUDCTL
ABDOVF
RCIDL
DTRXP
CKTXP
BRG16
WUE
ABDEN
59
SPBRGH
59
SPBRG
59
TXSTA
Legend: = unimplemented, read as 0. Shaded cells are not used for synchronous master transmission.
Note 1: Reserved in PIC18F2XK20 devices; always maintain these bits clear.
Preliminary
DS41303C-page 253
PIC18F2XK20/4XK20
18.4.1.6
18.4.1.8
18.4.1.7
18.4.1.9
18.4.1.10
1.
Slave Clock
DS41303C-page 254
Preliminary
PIC18F2XK20/4XK20
FIGURE 18-12:
RX/DT
pin
bit 0
bit 1
bit 2
bit 3
bit 4
bit 5
bit 6
bit 7
TX/CK pin
(SCKP = 0)
TX/CK pin
(SCKP = 1)
Write to
bit SREN
SREN bit
CREN bit 0
RCIF bit
(Interrupt)
Read
RXREG
Note:
Timing diagram demonstrates Sync Master mode with bit SREN = 1 and bit BRGH = 0.
TABLE 18-8:
Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
INTCON
GIE/GIEH PEIE/GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
PIR1
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
PSPIE(1)
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR1
PSPIP(1)
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
60
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
RCSTA
RCREG
TXSTA
BAUDCTL
59
59
CSRC
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
59
ABDOVF
RCIDL
DTRXP
CKTXP
BRG16
WUE
ABDEN
59
SPBRGH
59
SPBRG
59
Legend: = unimplemented, read as 0. Shaded cells are not used for synchronous master reception.
Note 1: Reserved in 28-pin devices; always maintain these bits clear.
Preliminary
DS41303C-page 255
PIC18F2XK20/4XK20
18.4.2
SYNC = 1
CSRC = 0
SREN = 0 (for transmit); SREN = 1 (for receive)
CREN = 0 (for transmit); CREN = 1 (for receive)
SPEN = 1
1.
2.
3.
4.
18.4.2.1
5.
18.4.2.2
1.
2.
3.
4.
5.
6.
7.
TABLE 18-9:
Name
INTCON
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
PIR1
PSPIF
(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
PSPIE(1)
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR1
PSPIP(1)
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
60
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
59
TRISC7
TRISC6
TRISC5
TRISC4
TRISC3
TRISC2
TRISC1
TRISC0
RCSTA
TRISC
TXREG
TXSTA
BAUDCTL
60
59
CSRC
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
59
ABDOVF
RCIDL
DTRXP
CKTXP
BRG16
WUE
ABDEN
59
SPBRGH
59
SPBRG
59
Legend: = unimplemented, read as 0. Shaded cells are not used for synchronous master transmission.
Note 1: Reserved in PIC18F2XK20 devices; always maintain these bits clear.
DS41303C-page 256
Preliminary
PIC18F2XK20/4XK20
18.4.2.3
18.4.2.4
1.
Sleep
CREN bit is always set, therefore the receiver is
never Idle
SREN bit, which is a don't care in Slave mode
2.
3.
4.
5.
6.
7.
8.
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
INTCON
PIR1
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
PSPIE(1)
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR1
PSPIP(1)
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
60
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
59
RCSTA
RCREG
TXSTA
59
CSRC
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
BAUDCTL
ABDOVF
RCIDL
DTRXP
CKTXP
BRG16
WUE
ABDEN
SPBRGH
59
SPBRG
59
59
59
Legend: = unimplemented, read as 0. Shaded cells are not used for synchronous slave reception.
Note 1: Reserved in 28-pin devices; always maintain these bits clear.
Preliminary
DS41303C-page 257
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 258
Preliminary
PIC18F2XK20/4XK20
19.0
ANALOG-TO-DIGITAL
CONVERTER (ADC) MODULE
FIGURE 19-1:
AVSS
VREF-
VCFG1 = 1
AVDD
VCFG0 = 0
VREF+
AN0
0000
AN1
0001
AN2
0010
AN3
0011
AN4
0100
AN5
0101
AN6
0110
AN7
0111
AN8
1000
AN9
1001
AN10
1010
AN11
1011
AN12
1100
Unused
1101
Unused
1110
VCFG0 = 1
ADC
10
GO/DONE
ADFM
0 = Left Justify
1 = Right Justify
ADON
10
VSS
ADRESH
ADRESL
1111
FVR
CHS<3:0>
Preliminary
DS41303C-page 259
PIC18F2XK20/4XK20
19.1
ADC Configuration
19.1.4
Port configuration
Channel selection
ADC voltage reference selection
ADC conversion clock source
Interrupt control
Results formatting
19.1.1
PORT CONFIGURATION
The ANSEL, ANSELH, TRISA, TRISB and TRISE registers all configure the A/D port pins. Any port pin
needed as an analog input should have its corresponding ANSx bit set to disable the digital input buffer and
TRISx bit set to disable the digital output driver. If the
TRISx bit is cleared, the digital output level (VOH or
VOL) will be converted.
The A/D operation is independent of the state of the
ANSx bits and the TRIS bits.
Note 1: When reading the PORT register, all pins
with their corresponding ANSx bit set
read as cleared (a low level). However,
analog conversion of pins configured as
digital inputs (ANSx bit cleared and
TRISx bit set) will be accurately
converted.
19.1.2
19.1.5
19.1.3
2: Analog levels on any pin with the corresponding ANSx bit cleared may cause the
digital input buffer to consume current out
of the devices specification limits.
CHANNEL SELECTION
DS41303C-page 260
CONVERSION CLOCK
The source of the conversion clock is software selectable via the ADCS bits of the ADCON2 register. There
are seven possible clock options:
FOSC/2
FOSC/4
FOSC/8
FOSC/16
FOSC/32
FOSC/64
FRC (dedicated internal oscillator)
Preliminary
PIC18F2XK20/4XK20
19.1.6
INTERRUPTS
TABLE 19-1:
ADCS<2:0>
FOSC/2
64 MHz
000
FOSC/4
100
31.25
ns(2)
62.5
ns(2)
ns(2)
FOSC/8
001
400
FOSC/16
101
250 ns(2)
FOSC/32
010
ns(2)
FOSC/64
110
FRC
Legend:
Note 1:
2:
3:
4:
19.1.7
500
16 MHz
1-4
250
ns(2)
1.0 s
4.0 s(3)
500
ns(2)
2.0 s
8.0 s(3)
1.0 s
4.0 s(3)
16.0 s(3)
2.0 s
s(3)
32.0 s(3)
16.0 s(3)
64.0 s(3)
s(1,4)
1-4 s(1,4)
500
8.0
s(1,4)
1-4
s(1,4)
1-4
ns(2)
1 MHz
125
4.0 s(3)
1.0 s
x11
4 MHz
ns(2)
2.0 s
RESULT FORMATTING
FIGURE 19-2:
(ADFM = 0)
ADRESL
MSB
LSB
bit 7
bit 0
bit 7
bit 0
Unimplemented: Read as 0
MSB
bit 7
LSB
bit 0
Unimplemented: Read as 0
bit 7
bit 0
10-bit A/D Result
Preliminary
DS41303C-page 261
PIC18F2XK20/4XK20
19.2
ADC Operation
19.2.1
STARTING A CONVERSION
FIGURE 19-3:
TCY - TAD TAD1 TAD2 TAD3 TAD4 TAD5 TAD6 TAD7 TAD8 TAD9 TAD10 TAD11 2 TAD
b4
b1
b0
b6
b7
b2
b9
b8
b3
b5
Conversion starts
Discharge
FIGURE 19-4:
TAD Cycles
TACQT Cycles
1
Automatic
Acquisition
Time
b9
b8
b7
b6
6
b5
10
11
b4
b3
b2
b1
b0
Conversion starts
(Holding capacitor is disconnected from analog input)
Set GO bit
(Holding capacitor continues
acquiring input)
DS41303C-page 262
2 TAD
Discharge
Preliminary
PIC18F2XK20/4XK20
19.2.2
COMPLETION OF A CONVERSION
19.2.3
DISCHARGE
19.2.4
TERMINATING A CONVERSION
19.2.5
19.2.7
19.2.8
19.2.6
Preliminary
DS41303C-page 263
PIC18F2XK20/4XK20
19.2.9
EXAMPLE 19-1:
2.
3.
4.
5.
6.
7.
8.
Configure Port:
Disable pin output driver (See TRIS register)
Configure pin as analog
Configure the ADC module:
Select ADC conversion clock
Configure voltage reference
Select ADC input channel
Select result format
Select acquisition delay
Turn on ADC module
Configure ADC interrupt (optional):
Clear ADC interrupt flag
Enable ADC interrupt
Enable peripheral interrupt
Enable global interrupt(1)
Wait the required acquisition time(2).
Start conversion by setting the GO/DONE bit.
Wait for ADC conversion to complete by one of
the following:
Polling the GO/DONE bit
Waiting for the ADC interrupt (interrupts
enabled)
Read ADC Result
Clear the ADC interrupt flag (required if interrupt
is enabled).
A/D CONVERSION
DS41303C-page 264
Preliminary
PIC18F2XK20/4XK20
19.2.10
The following registers are used to control the operation of the ADC.
Note:
REGISTER 19-1:
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
CHS3
CHS2
CHS1
CHS0
GO/DONE
ADON
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7-6
Unimplemented: Read as 0
bit 5-2
bit 1
bit 0
Note 1:
2:
Preliminary
DS41303C-page 265
PIC18F2XK20/4XK20
REGISTER 19-2:
U-0
U-0
R/W-0
R/W-0
U-0
U-0
U-0
U-0
VCFG1
VCFG0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7-6
Unimplemented: Read as 0
bit 5
bit 4
bit 3-0
Unimplemented: Read as 0
DS41303C-page 266
Preliminary
x = Bit is unknown
PIC18F2XK20/4XK20
REGISTER 19-3:
R/W-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
ADFM
ACQT2
ACQT1
ACQT0
ADCS2
ADCS1
ADCS0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7
x = Bit is unknown
bit 6
Unimplemented: Read as 0
bit 5-3
ACQT<2:0>: A/D Acquisition time select bits. Acquisition time is the duration that the A/D charge holding capacitor remains connected to A/D channel from the instant the GO/DONE bit is set until conversions begins.
000 = 0(1)
001 = 2 TAD
010 = 4 TAD
011 = 6 TAD
100 = 8 TAD
101 = 12 TAD
110 = 16 TAD
111 = 20 TAD
bit 2-0
Note 1:
When the A/D clock source is selected as FRC then the start of conversion is delayed by one instruction
cycle after the GO/DONE bit is set to allow the SLEEP instruction to be executed.
Preliminary
DS41303C-page 267
PIC18F2XK20/4XK20
REGISTER 19-4:
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
ADRES9
ADRES8
ADRES7
ADRES6
ADRES5
ADRES4
ADRES3
ADRES2
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7-0
x = Bit is unknown
REGISTER 19-5:
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
ADRES1
ADRES0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7-6
bit 5-0
REGISTER 19-6:
x = Bit is unknown
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
ADRES9
ADRES8
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7-2
bit 1-0
REGISTER 19-7:
x = Bit is unknown
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
ADRES7
ADRES6
ADRES5
ADRES4
ADRES3
ADRES2
ADRES1
ADRES0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7-0
x = Bit is unknown
DS41303C-page 268
Preliminary
PIC18F2XK20/4XK20
19.3
EQUATION 19-1:
Assumptions:
T ACQ = Amplifier Settling Time + Hold Capacitor Charging Time + Temperature Coefficient
= T AMP + T C + T COFF
= 5s + T C + [ ( Temperature - 25C ) ( 0.05s/C ) ]
The value for TC can be approximated with the following equations:
1
V AP PLIE D 1 ------------ = V CHOLD
2047
TC
----------
RC
V AP P LI ED 1 e = V CHOLD
Tc
---------
1
RC
V AP P LIED 1 e = V A P PLIE D 1 ------------
2047
T C = C HOLD ( R IC + R SS + R S ) ln(1/2047)
= 13.5pF ( 1k + 700 + 10k ) ln(0.0004885)
= 1.20 s
Therefore:
T ACQ = 5S + 1.20S + [ ( 50C- 25C ) ( 0.05S /C ) ]
= 7.45S
Note 1: The reference voltage (VREF) has no effect on the equation, since it cancels itself out.
2: The charge holding capacitor (CHOLD) is discharged after each conversion.
3: The maximum recommended impedance for analog sources is 10 k. This is required to meet the pin
leakage specification.
Preliminary
DS41303C-page 269
PIC18F2XK20/4XK20
FIGURE 19-5:
Rs
CPIN
5 pF
VA
VT = 0.6V
VT = 0.6V
RIC 1k
Sampling
Switch
SS Rss
CHOLD = 13.5 pF
I LEAKAGE(1)
Discharge
Switch
Note 1:
VDD
Legend: CPIN
= Input Capacitance
= Threshold Voltage
VT
I LEAKAGE = Leakage current at the pin due to
various junctions
RIC
= Interconnect Resistance
SS
= Sampling Switch
CHOLD
= Sample/Hold Capacitance
VSS/VREF-
3.5V
3.0V
2.5V
2.0V
1.5V
.1
1
10
Rss (k)
100
FIGURE 19-6:
Full-Scale Range
3FFh
3FEh
ADC Output Code
3FDh
3FCh
3FBh
Full-Scale
Transition
004h
003h
002h
001h
000h
VSS/VREF-
DS41303C-page 270
Zero-Scale
Transition
VDD/VREF+
Preliminary
PIC18F2XK20/4XK20
TABLE 19-2:
Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
INTCON
GIE/GIEH PEIE/GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
PIR1
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
60
PIE1
(1)
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
60
IPR1
PSPIP(1)
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
60
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
60
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
60
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
60
IPR2
ADRESH
59
ADRESL
59
ADCON0
CHS3
CHS2
CHS1
CHS0
GO/DONE
ADON
59
ADCON1
VCFG1
VCFG0
59
ADCON2
ADFM
ACQT2
ACQT1
ACQT0
ADCS2
ADCS1
ADCS0
59
ANS7(1)
ANS6(1)
ANS5(1)
ANS4
ANS3
ANS2
ANS1
ANS0
60
ANS12
ANS11
ANS10
ANS9
ANS8
60
PORTA
RA7(2)
RA6(2)
RA5
RA4
RA3
RA2
RA1
RA0
60
TRISA
TRISA7(2)
TRISA6(2)
PORTB
RB7
RB6
RB1
RB0
60
ANSEL
ANSELH
RB4
RB3
RB2
60
TRISB
60
LATB
60
PORTE(4)
RE3(3)
RE2
RE1
RE0
60
TRISE(4)
IBF
OBF
IBOV
PSPMODE
TRISE2
TRISE1
TRISE0
60
LATE(4)
60
Legend: = unimplemented, read as 0. Shaded cells are not used for A/D conversion.
Note 1: These bits are unimplemented on PIC18F2XK20 devices; always maintain these bits clear.
2: PORTA<7:6> and their direction bits are individually configured as port pins based on various primary
oscillator modes. When disabled, these bits read as 0.
3: RE3 port bit is available only as an input pin when the MCLRE Configuration bit is 0.
4: These registers are not implemented on PIC18F2XK20 devices.
Preliminary
DS41303C-page 271
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 272
Preliminary
PIC18F2XK20/4XK20
20.0
COMPARATOR MODULE
FIGURE 20-1:
20.1
SINGLE COMPARATOR
VIN+
VIN-
Output
VINVIN+
Output
Note:
Comparator Overview
Preliminary
DS41303C-page 273
PIC18F2XK20/4XK20
FIGURE 20-2:
C1CH<1:0>
2
D
Q1
C12IN0-
C12IN1C12IN2-
1
MUX
2
C12IN3-
To
Data Bus
EN
RD_CM1CON0
D
Q3*RD_CM1CON0
Set C1IF
EN
CL
To PWM Logic
Reset
C1ON(1)
C1R
C1OE
C1VIN-
C1IN+
FVR
0
MUX
1
0
MUX
C1VREF
1
CVREF
C1RSEL
Note 1:
2:
3:
4:
FIGURE 20-3:
C1VIN+ C1
+
C1OUT
C1OUT pin(2)
C1SP
C1POL
When C1ON = 0, the C1 comparator will produce a 0 output to the XOR Gate.
Output shown for reference only. See I/O port pin block diagram for more detail.
Q1 and Q3 are phases of the four-phase system clock (FOSC).
Q1 is held high during Sleep mode.
To
Data Bus
EN
RD_CM2CON0
C2CH<1:0>
2
C12IN0-
C12IN1C12IN2-
1
MUX
2
C12IN3-
C2R
C2IN+
FVR
CVREF
C2RSEL
C2ON(1)
Q3*RD_CM2CON0
Set C2IF
EN
CL
NRESET
To PWM Logic
C2OE
C2VINC2VIN+
C2OUT
C2
C2OUT pin(2)
C2SP
C2POL
0
MUX
1
0
MUX
C2VREF
1
Note 1:
2:
3:
4:
DS41303C-page 274
When C2ON = 0, the C2 comparator will produce a 0 output to the XOR Gate.
Output shown for reference only. See I/O port pin block diagram for more detail.
Q1 and Q3 are phases of the four-phase system clock (FOSC).
Q1 is held high during Sleep mode.
Preliminary
PIC18F2XK20/4XK20
20.2
Comparator Control
Each comparator has a separate control and Configuration register: CM1CON0 for Comparator C1 and
CM2CON0 for Comparator C2. In addition, Comparator
C2 has a second control register, CM2CON1, for controlling the interaction with Timer1 and simultaneous
reading of both comparator outputs.
The CM1CON0 and CM2CON0 registers (see Registers 20-1 and 20-2, respectively) contain the control
and Status bits for the following:
20.2.5
Enable
Input selection
Reference selection
Output selection
Output polarity
Speed selection
20.2.1
TABLE 20-1:
COMPARATOR ENABLE
COMPARATOR OUTPUT
STATE VS. INPUT
CONDITIONS
Input Condition
CxPOL
CxOUT
20.2.2
20.2.3
COMPARATOR REFERENCE
SELECTION
20.2.4
COMPARATOR OUTPUT
SELECTION
20.2.6
The trade-off between speed or power can be optimized during program execution with the CxSP control
bit. The default state for this bit is 1 which selects the
normal speed mode. Device power consumption can
be optimized at the cost of slower comparator propagation delay by clearing the CxSP bit to 0.
20.3
Preliminary
DS41303C-page 275
PIC18F2XK20/4XK20
20.4
20.4.1
FIGURE 20-4:
COMPARATOR
INTERRUPT TIMING W/O
CMxCON0 READ
Q1
Q3
CxIN+
TRT
CxOUT
Set CxIF (edge)
CxIF
reset by software
FIGURE 20-5:
DS41303C-page 276
COMPARATOR
INTERRUPT TIMING WITH
CMxCON0 READ
Q1
Q3
CxIN+
TRT
CxOUT
CxIF
cleared by CMxCON0 read
reset by software
Preliminary
PIC18F2XK20/4XK20
20.5
20.6
Effects of a Reset
Preliminary
DS41303C-page 277
PIC18F2XK20/4XK20
REGISTER 20-1:
R/W-0
R-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
C1ON
C1OUT
C1OE
C1POL
C1SP
C1R
C1CH1
C1CH0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1-0
Note 1:
x = Bit is unknown
Comparator output requires the following three conditions: C1OE = 1, C1ON = 1 and corresponding port
TRIS bit = 0.
DS41303C-page 278
Preliminary
PIC18F2XK20/4XK20
REGISTER 20-2:
R/W-0
R-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
C2ON
C2OUT
C2OE
C2POL
C2SP
C2R
C2CH1
C2CH0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1-0
Note 1:
x = Bit is unknown
Comparator output requires the following three conditions: C2OE = 1, C2ON = 1 and corresponding port
TRIS bit = 0.
Preliminary
DS41303C-page 279
PIC18F2XK20/4XK20
20.7
FIGURE 20-6:
Rs < 10K
AIN
VA
CPIN
5 pF
VT 0.6V
RIC
ILEAKAGE(1)
Vss
Legend: CPIN
= Input Capacitance
ILEAKAGE = Leakage Current at the pin due to various junctions
RIC
= Interconnect Resistance
= Source Impedance
RS
= Analog Voltage
VA
VT
= Threshold Voltage
Note 1: See Section 26.0 Electrical Characteristics.
DS41303C-page 280
Preliminary
PIC18F2XK20/4XK20
20.8
20.8.1
SIMULTANEOUS COMPARATOR
OUTPUT READ
20.8.2
INTERNAL REFERENCE
SELECTION
REGISTER 20-3:
R-0
R-0
R/W-0
R/W-0
U-0
U-0
U-0
U-0
MC1OUT
MC2OUT
C1RSEL
C2RSEL
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5
bit 4
bit 3-0
Unimplemented: Read as 0
Preliminary
x = Bit is unknown
DS41303C-page 281
PIC18F2XK20/4XK20
TABLE 20-2:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
CM1CON0
C1ON
C1OUT
C1OE
C1POL
C1SP
C1R
C1CH1
C1CH0
60
CM2CON0
C2ON
C2OUT
C2OE
C2POL
C2SP
C2R
C2CH1
C2CH0
60
CM2CON1
MC1OUT
MC2OUT
C1RSEL
C2RSEL
61
CVRCON
CVREN
CVROE
CVRR
CVRSS
CVR3
CVR2
CVR1
CVR0
59
FVREN
FVRST
CVRCON2
INTCON
GIE/GIEH PEIE/GIEL
59
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
60
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
60
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
60
RA7(1)
RA6(1)
RA5
RA4
RA3
RA2
RA1
RA0
60
LATA
LATA7(1)
LATA6(1)
TRISA
TRISA7(1)
PORTA
60
60
Legend: = unimplemented, read as 0. Shaded cells are unused by the comparator module.
Note 1: PORTA<7:6> and their direction and latch bits are individually configured as port pins based on various
primary oscillator modes. When disabled, these bits read as 0.
DS41303C-page 282
Preliminary
PIC18F2XK20/4XK20
21.0
VOLTAGE REFERENCES
21.1.3
21.1
INDEPENDENT OPERATION
21.1.2
EQUATION 21-1:
21.1.4
21.1.1
21.1.5
21.1.6
21.1.7
EFFECTS OF A RESET
CV RR = 1 (low range):
CVREF = (CVRSRC/24) X CVR<3:0> + VREFCV RR = 0 (high range):
CVREF = (CVRSRC/32) X (8 + CVR<3:0>) + VREFCV RSRC = V DD or [(VREF+) - (VREF-)]
Preliminary
DS41303C-page 283
PIC18F2XK20/4XK20
21.2
21.2.1
FIGURE 21-1:
VREF+
VDD
8R
CVRSS = 0
CVR<3:0>
CVREN
R
R
16-to-1 MUX
R
16 Steps
CVREF
R
R
CVRR
8R
CVRSS = 1
VREF-
CVRSS = 0
FVREN
From HVLD and
BOR circuits
DS41303C-page 284
EN
Preliminary
FVR
FVRST
PIC18F2XK20/4XK20
FIGURE 21-2:
R(1)
Voltage
Reference
Output
Impedance
Note 1:
CVREF
R is dependent upon the voltage reference Configuration bits, CVR<3:0> and CVRR.
REGISTER 21-1:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
CVREN
CVROE(1)
CVRR
CVRSS
CVR3
CVR2
CVR1
CVR0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5
bit 4
bit 3-0
Note 1:
Preliminary
DS41303C-page 285
PIC18F2XK20/4XK20
REGISTER 21-2:
R/W-0
R-0
U-0
U-0
U-0
U-0
U-0
U-0
FVREN
FVRST
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
bit 5-0
Unimplemented: Read as 0.
TABLE 21-1:
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
CVRCON
CVREN
CVROE
CVRR
CVRSS
CVR3
CVR2
CVR1
CVR0
60
CVRCON2
FVREN
FVRST
59
CM1CON0
C1ON
C1OUT
C1OE
C1POL
C1SP
C1R
C1CH1
C1CH0
60
CM2CON0
C2ON
C2OUT
C2OE
C2POL
C2SP
C2R
C2CH1
C2CH0
60
61
Name
CM2CON1
TRISA
60
Legend: Shaded cells are not used with the comparator voltage reference.
Note 1: PORTA pins are enabled based on oscillator configuration.
DS41303C-page 286
Preliminary
PIC18F2XK20/4XK20
22.0
HIGH/LOW-VOLTAGE
DETECT (HLVD)
REGISTER 22-1:
R/W-0
VDIRMAG
R-0
IRVST
R/W-0
R/W-0
R/W-1
R/W-0
R/W-1
HLVDEN
HLVDL3(1)
HLVDL2(1)
HLVDL1(1)
HLVDL0(1)
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
U = Unimplemented
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6
Unimplemented: Read as 0
bit 5
bit 4
bit 3-0
Note 1:
Preliminary
DS41303C-page 287
PIC18F2XK20/4XK20
22.1
Operation
FIGURE 22-1:
VDD
Externally Generated
Trip Point
VDD
HLVDL<3:0>
HLVDCON
Register
HLVDEN
HLVDIN
16-to-1 MUX
HLVDIN
VDIRMAG
Set
HLVDIF
HLVDEN
Internal Voltage
Reference
BOREN
DS41303C-page 288
Preliminary
PIC18F2XK20/4XK20
22.2
HLVD Setup
5.
22.3
22.4
Current Consumption
FIGURE 22-2:
CASE 1:
Enable HLVD
TIVRST
IRVST
CASE 2:
VDD
VHLVD
HLVDIF
Enable HLVD
TIVRST
IRVST
Internal Reference is stable
Preliminary
DS41303C-page 289
PIC18F2XK20/4XK20
FIGURE 22-3:
CASE 1:
Enable HLVD
TIVRST
IRVST
IRVST
Internal Reference is stable
DS41303C-page 290
Preliminary
PIC18F2XK20/4XK20
Applications
FIGURE 22-4:
VA
VB
TABLE 22-1:
TYPICAL LOW-VOLTAGE
DETECT APPLICATION
Voltage
22.5
Time
TA
TB
Name
Bit 7
Bit 6
HLVDCON
VDIRMAG
INTCON
GIE/GIEH PEIE/GIEL
Reset
Values
on Page
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
IRVST
HLVDEN
HLVDL3
HLVDL2
HLVDL1
HLVDL0
58
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
57
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
60
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
60
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
60
Legend: = unimplemented, read as 0. Shaded cells are unused by the HLVD module.
Preliminary
DS41303C-page 291
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 292
Preliminary
PIC18F2XK20/4XK20
23.0
SPECIAL FEATURES OF
THE CPU
Preliminary
DS41303C-page 293
PIC18F2XK20/4XK20
23.1
Configuration Bits
TABLE 23-1:
File Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
300001h
CONFIG1H
IESO
FCMEN
FOSC3
FOSC2
300002h
CONFIG2L
BORV1
BORV0
BOREN1
WDTPS3
WDTPS2
Bit 1
Bit 0
FOSC1
FOSC0
BOREN0 PWRTEN
Default/
Unprogrammed
Value
00-- 0111
---1 1111
WDTPS1 WDTPS0
WDTEN
CCP2MX
1--- 1011
STVREN
10-- -1-1
CP2(1)
CP1
CP0
---- 1111
11-- ----
WRT3(1)
WRT2(1)
WRT1
WRT0
---- 1111
111- ----
300003h
CONFIG2H
300005h
CONFIG3H MCLRE
300006h
CONFIG4L
DEBUG
XINST
LVP
300008h
CONFIG5L
CP3(1)
300009h
CONFIG5H
CPD
CPB
30000Ah
CONFIG6L
30000Bh
CONFIG6H
WRTD
WRTB
WRTC
(1)
(1)
---1 1111
30000Ch
CONFIG7L
EBTR1
EBTR0
---- 1111
30000Dh
CONFIG7H
EBTRB
-1-- ----
DEV2
DEV1
DEV0
REV4
REV3
REV2
REV1
REV0
qqqq qqqq(2)
DEV10
DEV9
DEV8
DEV7
DEV6
DEV5
DEV4
DEV3
0000 1100
3FFFFEh DEVID1(2)
(2)
EBTR3
EBTR2
3FFFFFh
DEVID2
Legend:
Note 1:
2:
DS41303C-page 294
Preliminary
PIC18F2XK20/4XK20
REGISTER 23-1:
R/P-0
R/P-0
U-0
U-0
R/P-0
R/P-1
R/P-1
R/P-1
IESO
FCMEN
FOSC3
FOSC2
FOSC1
FOSC0
bit 7
bit 0
Legend:
R = Readable bit
P = Programmable bit
bit 7
bit 6
bit 5-4
Unimplemented: Read as 0
bit 3-0
Preliminary
DS41303C-page 295
PIC18F2XK20/4XK20
REGISTER 23-2:
U-0
U-0
U-0
R/P-1
R/P-1
R/P-1
R/P-1
R/P-1
BORV1(1)
BORV0(1)
BOREN1(2)
BOREN0(2)
PWRTEN(2)
bit 7
bit 0
Legend:
R = Readable bit
P = Programmable bit
x = Bit is unknown
bit 7-5
Unimplemented: Read as 0
bit 4-3
bit 2-1
bit 0
Note
1:
2:
REGISTER 23-3:
U-0
U-0
U-0
R/P-1
R/P-1
R/P-1
R/P-1
R/P-1
WDTPS3
WDTPS2
WDTPS1
WDTPS0
WDTEN
bit 7
bit 0
Legend:
R = Readable bit
P = Programmable bit
bit 7-5
Unimplemented: Read as 0
bit 4-1
bit 0
DS41303C-page 296
Preliminary
PIC18F2XK20/4XK20
REGISTER 23-4:
R/P-1
U-0
U-0
U-0
R/P-1
R/P-0
R/P-1
R/P-1
MCLRE
HFOFST
LPT1OSC
PBADEN
CCP2MX
bit 7
bit 0
Legend:
R = Readable bit
P = Programmable bit
bit 7
bit 6-4
Unimplemented: Read as 0
bit 3
bit 2
bit 1
bit 0
REGISTER 23-5:
R/P-1
R/P-0
U-0
U-0
U-0
R/P-1
U-0
R/P-1
DEBUG
XINST
LVP
STVREN
bit 0
bit 7
Legend:
R = Readable bit
P = Programmable bit
x = Bit is unknown
bit 7
bit 6
bit 5-3
Unimplemented: Read as 0
bit 2
bit 1
Unimplemented: Read as 0
bit 0
Preliminary
DS41303C-page 297
PIC18F2XK20/4XK20
REGISTER 23-6:
U-0
U-0
U-0
R/C-1
R/C-1
(1)
(1)
CP3
CP2
R/C-1
R/C-1
CP1
CP0
bit 7
bit 0
Legend:
R = Readable bit
bit 7-4
Unimplemented: Read as 0
bit 3
bit 2
bit 1
bit 0
Note 1:
REGISTER 23-7:
R/C-1
R/C-1
U-0
U-0
U-0
U-0
U-0
U-0
CPD
CPB
bit 7
bit 0
Legend:
R = Readable bit
bit 7
bit 6
bit 5-0
Unimplemented: Read as 0
DS41303C-page 298
Preliminary
PIC18F2XK20/4XK20
REGISTER 23-8:
U-0
U-0
U-0
U-0
R/C-1
R/C-1
R/C-1
R/C-1
WRT3(1)
WRT2(1)
WRT1
WRT0
bit 7
bit 0
Legend:
R = Readable bit
bit 7-4
Unimplemented: Read as 0
bit 3
bit 2
bit 1
bit 0
Note 1:
REGISTER 23-9:
R/C-1
WRTD
R-1
U-0
U-0
U-0
U-0
U-0
WRTB
WRTC(1)
bit 7
bit 0
Legend:
R = Readable bit
bit 7
bit 6
bit 5
bit 4-0
Unimplemented: Read as 0
Note 1:
This bit is read-only in normal execution mode; it can be written only in Program mode.
Preliminary
DS41303C-page 299
PIC18F2XK20/4XK20
REGISTER 23-10: CONFIG7L: CONFIGURATION REGISTER 7 LOW
U-0
U-0
U-0
U-0
R/C-1
R/C-1
R/C-1
R/C-1
EBTR3(1)
EBTR2(1)
EBTR1
EBTR0
bit 7
bit 0
Legend:
R = Readable bit
bit 7-4
Unimplemented: Read as 0
bit 3
bit 2
bit 1
bit 0
Note 1:
R/C-1
U-0
U-0
U-0
U-0
U-0
U-0
EBTRB
bit 7
bit 0
Legend:
R = Readable bit
bit 7
Unimplemented: Read as 0
bit 6
bit 5-0
Unimplemented: Read as 0
DS41303C-page 300
Preliminary
PIC18F2XK20/4XK20
REGISTER 23-12: DEVID1: DEVICE ID REGISTER 1 FOR PIC18F2XK20/4XK20
R
DEV2
DEV1
DEV0
REV4
REV3
REV2
REV1
REV0
bit 7
bit 0
Legend:
R = Readable bit
bit 7-5
bit 4-0
DEV10
DEV9
DEV8
DEV7
DEV6
DEV5
DEV4
DEV3
bit 7
bit 0
Legend:
R = Readable bit
bit 7-0
Note 1:
Preliminary
DS41303C-page 301
PIC18F2XK20/4XK20
23.2
FIGURE 23-1:
SWDTEN
WDTEN
Enable WDT
WDT Counter
LFINTOSC Source
Wake-up
from Power
Managed Modes
128
CLRWDT
Reset
WDT
Reset
Sleep
DS41303C-page 302
Preliminary
PIC18F2XK20/4XK20
23.2.1
CONTROL REGISTER
U-0
U-0
U-0
U-0
U-0
U-0
R/W-0
SWDTEN(1)
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7-1
Unimplemented: Read as 0
bit 0
x = Bit is unknown
Note 1: This bit has no effect if the Configuration bit, WDTEN, is enabled.
TABLE 23-2:
Name
RCON
WDTCON
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Reset
Values
on page
IPEN
SBOREN
RI
TO
PD
POR
BOR
56
SWDTEN
58
WDTEN
296
CONFIG2H
Legend: = unimplemented, read as 0. Shaded cells are not used by the Watchdog Timer.
Preliminary
DS41303C-page 303
PIC18F2XK20/4XK20
23.3
Each of the blocks has three code protection bits associated with them. They are:
FIGURE 23-2:
8 Kbytes
(PIC18FX3K20)
16 Kbytes
(PIC18FX4K20)
32 Kbytes
(PIC18FX5K20)
64 Kbytes
(PIC18FX6K20)
Boot Block
(000h-1FFh)
Boot Block
(000h-7FFh)
Boot Block
(000h-7FFh)
Boot Block
(000h-7FFh)
Block 0
(200h-FFFh)
Block 0
(800h-1FFFh)
Block 0
(800h-1FFFh)
Block 0
(800h-3FFFh)
Block 1
(1000h-1FFFh)
Block 1
(2000h-3FFFh)
Block 1
(2000h-3FFFh)
Block 1
(4000h-7FFFh)
Block 2
(4000h-5FFFh)
Block 2
(8000h-BFFFh)
Block 3
(6000h-7FFFh)
Block 3
(C000h-FFFFh)
Unimplemented
Read 0s
(2000h-1FFFFFh)
Unimplemented
Read 0s
(4000h-1FFFFFh)
Unimplemented
Unimplemented
Read 0s
Read 0s
(8000h-1FFFFFh) (10000h-1FFFFFh)
TABLE 23-3:
(Unimplemented
Memory Space)
File Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
CP3(1)
CP2(1)
CP1
CP0
300008h
CONFIG5L
300009h
CONFIG5H
CPD
CPB
30000Ah
CONFIG6L
WRT3(1)
WRT2(1)
WRT1
WRT0
30000Bh
CONFIG6H
WRTD
WRTB
WRTC
30000Ch
CONFIG7L
EBTR3(1)
EBTR2(1)
EBTR1
EBTR0
30000Dh
CONFIG7H
EBTRB
DS41303C-page 304
Preliminary
PIC18F2XK20/4XK20
23.3.1
PROGRAM MEMORY
CODE PROTECTION
FIGURE 23-3:
Register Values
Program Memory
TBLPTR = 0008FFh
PC = 001FFEh
WRTB, EBTRB = 11
WRT0, EBTR0 = 01
TBLWT*
001FFFh
002000h
WRT1, EBTR1 = 11
003FFFh
004000h
PC = 005FFEh
WRT2, EBTR2 = 11
TBLWT*
005FFFh
006000h
WRT3, EBTR3 = 11
007FFFh
Results: All table writes disabled to Blockn whenever WRTn = 0.
Preliminary
DS41303C-page 305
PIC18F2XK20/4XK20
FIGURE 23-4:
Register Values
Program Memory
TBLPTR = 0008FFh
WRTB, EBTRB = 11
WRT0, EBTR0 = 10
001FFFh
002000h
PC = 003FFEh
TBLRD*
WRT1, EBTR1 = 11
003FFFh
004000h
WRT2, EBTR2 = 11
005FFFh
006000h
WRT3, EBTR3 = 11
007FFFh
Results: All table reads from external blocks to Blockn are disabled whenever EBTRn = 0.
TABLAT register returns a value of 0.
FIGURE 23-5:
Register Values
Program Memory
TBLPTR = 0008FFh
PC = 001FFEh
WRTB, EBTRB = 11
WRT0, EBTR0 = 10
TBLRD*
001FFFh
002000h
WRT1, EBTR1 = 11
003FFFh
004000h
WRT2, EBTR2 = 11
005FFFh
006000h
WRT3, EBTR3 = 11
007FFFh
DS41303C-page 306
Preliminary
PIC18F2XK20/4XK20
23.3.2
DATA EEPROM
CODE PROTECTION
23.3.3
ID Locations
23.5
23.6
MCLR/VPP/RE3
VDD
VSS
RB7
RB6
CONFIGURATION REGISTER
PROTECTION
23.4
To use the In-Circuit Debugger function of the microcontroller, the design must implement In-Circuit Serial
Programming connections to the following pins:
23.7
In-Circuit Debugger
TABLE 23-4:
DEBUGGER RESOURCES
I/O pins:
RB6, RB7
Stack:
2 levels
Program Memory:
512 bytes
Data Memory:
10 bytes
Preliminary
DS41303C-page 307
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 308
Preliminary
PIC18F2XK20/4XK20
24.0
24.1
Byte-oriented operations
Bit-oriented operations
Literal operations
Control operations
Preliminary
DS41303C-page 309
PIC18F2XK20/4XK20
TABLE 24-1:
Field
Description
bbb
BSR
C, DC, Z, OV, N
dest
Destination: either the WREG register or the specified register file location.
8-bit Register file address (00h to FFh) or 2-bit FSR designator (0h to 3h).
fs
12-bit Register file address (000h to FFFh). This is the source address.
fd
12-bit Register file address (000h to FFFh). This is the destination address.
GIE
Literal field, constant data or label (may be either an 8-bit, 12-bit or a 20-bit value).
label
Label name.
mm
The mode of the TBLPTR register for the table read and table write instructions.
Only used with table read and table write instructions:
*+
*-
+*
n
The relative address (2s complement number) for relative branch instructions or the direct address for
CALL/BRANCH and RETURN instructions.
PC
Program Counter.
PCL
PCH
PCLATH
PCLATU
PD
Power-down bit.
PRODH
PRODL
TBLPTR
TABLAT
TO
Time-out bit.
TOS
Top-of-Stack.
Unused or unchanged.
WDT
Watchdog Timer.
WREG
Dont care (0 or 1). The assembler will generate code with x = 0. It is the recommended form of use for
compatibility with all Microchip software tools.
zs
zd
{
Optional argument.
[text]
(text)
[expr]<n>
Assigned to.
< >
italics
DS41303C-page 310
Preliminary
PIC18F2XK20/4XK20
FIGURE 24-1:
10
9 8 7
OPCODE d
a
Example Instruction
0
f (FILE #)
ADDWF MYREG, W, B
0
f (Source FILE #)
12 11
f (Destination FILE #)
1111
12 11
9 8 7
OPCODE b (BIT #) a
0
BSF MYREG, bit, B
f (FILE #)
OPCODE
0
k (literal)
MOVLW 7Fh
8 7
OPCODE
15
0
n<7:0> (literal)
12 11
GOTO Label
0
n<19:8> (literal)
1111
8 7
OPCODE
15
0
CALL MYFUNC
n<7:0> (literal)
12 11
0
n<19:8> (literal)
1111
S = Fast bit
15
OPCODE
15
OPCODE
11 10
0
BRA MYFUNC
n<10:0> (literal)
8 7
n<7:0> (literal)
Preliminary
BC MYFUNC
DS41303C-page 311
PIC18F2XK20/4XK20
TABLE 24-2:
Mnemonic,
Operands
Description
Cycles
LSb
Status
Affected
Notes
BYTE-ORIENTED OPERATIONS
ADDWF
ADDWFC
ANDWF
CLRF
COMF
CPFSEQ
CPFSGT
CPFSLT
DECF
DECFSZ
DCFSNZ
INCF
INCFSZ
INFSNZ
IORWF
MOVF
MOVFF
f, d, a
f, d, a
f, d, a
f, a
f, d, a
f, a
f, a
f, a
f, d, a
f, d, a
f, d, a
f, d, a
f, d, a
f, d, a
f, d, a
f, d, a
fs, fd
MOVWF
MULWF
NEGF
RLCF
RLNCF
RRCF
RRNCF
SETF
SUBFWB
f, a
f, a
f, a
f, d, a
f, d, a
f, d, a
f, d, a
f, a
f, d, a
SUBWF
SUBWFB
f, d, a
f, d, a
SWAPF
TSTFSZ
XORWF
f, d, a
f, a
f, d, a
Note 1:
When a PORT register is modified as a function of itself (e.g., MOVF PORTB, 1, 0), the value used will be that value
present on the pins themselves. For example, if the data latch is 1 for a pin configured as input and is driven low by an
external device, the data will be written back with a 0.
If this instruction is executed on the TMR0 register (and where applicable, d = 1), the prescaler will be cleared if
assigned.
If Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is
executed as a NOP.
Some instructions are two-word instructions. The second word of these instructions will be executed as a NOP unless the
first word of the instruction retrieves the information embedded in these 16 bits. This ensures that all program memory
locations have a valid instruction.
2:
3:
4:
DS41303C-page 312
1
1
1
1
1
1 (2 or 3)
1 (2 or 3)
1 (2 or 3)
1
1 (2 or 3)
1 (2 or 3)
1
1 (2 or 3)
1 (2 or 3)
1
1
2
C, DC, Z, OV, N
C, DC, Z, OV, N
Z, N
Z
Z, N
None
None
None
C, DC, Z, OV, N
None
None
C, DC, Z, OV, N
None
None
Z, N
Z, N
None
1, 2
1, 2
1,2
2
1, 2
4
4
1, 2
1, 2, 3, 4
1, 2, 3, 4
1, 2
1, 2, 3, 4
4
1, 2
1, 2
1
1
1
1
1
1
1
1
1
1
0010 01da0
0010 0da
0001 01da
0110 101a
0001 11da
0110 001a
0110 010a
0110 000a
0000 01da
0010 11da
0100 11da
0010 10da
0011 11da
0100 10da
0001 00da
0101 00da
1100 ffff
1111 ffff
0110 111a
0000 001a
0110 110a
0011 01da
0100 01da
0011 00da
0100 00da
0110 100a
0101 01da
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
1
1
0101
0101
11da
10da
ffff
ffff
1, 2
1
1 (2 or 3)
1
0011
0110
0001
10da
011a
10da
ffff
ffff
ffff
ffff None
ffff None
ffff Z, N
4
1, 2
Preliminary
None
None
C, DC, Z, OV, N
C, Z, N
Z, N
C, Z, N
Z, N
None
C, DC, Z, OV, N
1, 2
1, 2
1, 2
PIC18F2XK20/4XK20
TABLE 24-2:
Mnemonic,
Operands
Description
Cycles
LSb
Status
Affected
Notes
BIT-ORIENTED OPERATIONS
BCF
BSF
BTFSC
BTFSS
BTG
f, b, a
f, b, a
f, b, a
f, b, a
f, d, a
Bit Clear f
Bit Set f
Bit Test f, Skip if Clear
Bit Test f, Skip if Set
Bit Toggle f
1
1
1 (2 or 3)
1 (2 or 3)
1
1001
1000
1011
1010
0111
bbba
bbba
bbba
bbba
bbba
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
None
None
None
None
None
1 (2)
1 (2)
1 (2)
1 (2)
1 (2)
1 (2)
1 (2)
2
1 (2)
2
0010
0110
0011
0111
0101
0001
0100
0nnn
0000
110s
kkkk
0000
0000
1111
kkkk
0000
xxxx
0000
0000
1nnn
0000
0000
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
kkkk
kkkk
0000
0000
kkkk
kkkk
0000
xxxx
0000
0000
nnnn
1111
0001
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
kkkk
kkkk
0100
0111
kkkk
kkkk
0000
xxxx
0110
0101
nnnn
1111
000s
None
None
None
None
None
None
None
None
None
None
1
1
1
1
2
1
2
1110
1110
1110
1110
1110
1110
1110
1101
1110
1110
1111
0000
0000
1110
1111
0000
1111
0000
0000
1101
0000
0000
2
2
1
0000
0000
0000
1100
0000
0000
kkkk
0001
0000
1, 2
1, 2
3, 4
3, 4
1, 2
CONTROL OPERATIONS
BC
BN
BNC
BNN
BNOV
BNZ
BOV
BRA
BZ
CALL
n
n
n
n
n
n
n
n
n
n, s
CLRWDT
DAW
GOTO
NOP
NOP
POP
PUSH
RCALL
RESET
RETFIE
n
s
Branch if Carry
Branch if Negative
Branch if Not Carry
Branch if Not Negative
Branch if Not Overflow
Branch if Not Zero
Branch if Overflow
Branch Unconditionally
Branch if Zero
Call subroutine 1st word
2nd word
Clear Watchdog Timer
Decimal Adjust WREG
Go to address 1st word
2nd word
No Operation
No Operation
Pop top of return stack (TOS)
Push top of return stack (TOS)
Relative Call
Software device Reset
Return from interrupt enable
RETLW
RETURN
SLEEP
k
s
Note 1:
When a PORT register is modified as a function of itself (e.g., MOVF PORTB, 1, 0), the value used will be that value
present on the pins themselves. For example, if the data latch is 1 for a pin configured as input and is driven low by an
external device, the data will be written back with a 0.
If this instruction is executed on the TMR0 register (and where applicable, d = 1), the prescaler will be cleared if
assigned.
If Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is
executed as a NOP.
Some instructions are two-word instructions. The second word of these instructions will be executed as a NOP unless the
first word of the instruction retrieves the information embedded in these 16 bits. This ensures that all program memory
locations have a valid instruction.
2:
3:
4:
1
1
2
Preliminary
TO, PD
C
None
None
None
None
None
None
All
GIE/GIEH,
PEIE/GIEL
kkkk None
001s None
0011 TO, PD
DS41303C-page 313
PIC18F2XK20/4XK20
TABLE 24-2:
Mnemonic,
Operands
Description
Cycles
LSb
Status
Affected
Notes
LITERAL OPERATIONS
ADDLW
ANDLW
IORLW
LFSR
k
k
k
f, k
MOVLB
MOVLW
MULLW
RETLW
SUBLW
XORLW
k
k
k
k
k
k
1
1
1
2
1
1
1
2
1
1
0000
0000
0000
1110
1111
0000
0000
0000
0000
0000
0000
1111
1011
1001
1110
0000
0001
1110
1101
1100
1000
1010
kkkk
kkkk
kkkk
00ff
kkkk
0000
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
C, DC, Z, OV, N
Z, N
Z, N
None
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
1000
1001
1010
1011
1100
1101
1110
1111
None
None
None
None
None
None
None
None
None
None
None
None
C, DC, Z, OV, N
Z, N
2:
3:
4:
Table Read
Table Read with post-increment
Table Read with post-decrement
Table Read with pre-increment
Table Write
Table Write with post-increment
Table Write with post-decrement
Table Write with pre-increment
When a PORT register is modified as a function of itself (e.g., MOVF PORTB, 1, 0), the value used will be that value
present on the pins themselves. For example, if the data latch is 1 for a pin configured as input and is driven low by an
external device, the data will be written back with a 0.
If this instruction is executed on the TMR0 register (and where applicable, d = 1), the prescaler will be cleared if
assigned.
If Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is
executed as a NOP.
Some instructions are two-word instructions. The second word of these instructions will be executed as a NOP unless the
first word of the instruction retrieves the information embedded in these 16 bits. This ensures that all program memory
locations have a valid instruction.
DS41303C-page 314
Preliminary
PIC18F2XK20/4XK20
24.1.1
ADDLW
ADD literal to W
ADDWF
ADD W to f
Syntax:
ADDLW
Syntax:
ADDWF
Operands:
0 f 255
d [0,1]
a [0,1]
Operation:
Status Affected:
N, OV, C, DC, Z
Operands:
0 k 255
Operation:
(W) + k W
Status Affected:
N, OV, C, DC, Z
Encoding:
0000
1111
kkkk
kkkk
Description:
Words:
Cycles:
Encoding:
0010
Q1
Q2
Q3
Q4
Read
literal k
Process
Data
Write to W
Example:
ADDLW
25h
ffff
Words:
Cycles:
Before Instruction
ffff
15h
W
= 10h
After Instruction
01da
Description:
Q Cycle Activity:
Decode
f {,d {,a}}
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
Example:
ADDWF
REG, 0, 0
Before Instruction
W
=
REG
=
After Instruction
W
REG
Note:
=
=
17h
0C2h
0D9h
0C2h
All PIC18 instructions may take an optional label argument preceding the instruction mnemonic for use in
symbolic addressing. If a label is used, the instruction format then becomes: {label} instruction argument(s).
Preliminary
DS41303C-page 315
PIC18F2XK20/4XK20
ADDWFC
ANDLW
Syntax:
ADDWFC
Syntax:
ANDLW
Operands:
0 f 255
d [0,1]
a [0,1]
Operands:
0 k 255
Operation:
(W) .AND. k W
Status Affected:
N, Z
f {,d {,a}}
Operation:
Status Affected:
N,OV, C, DC, Z
Encoding:
0010
Description:
00da
Encoding:
ffff
ffff
Add W, the CARRY flag and data memory location f. If d is 0, the result is
placed in W. If d is 1, the result is
placed in data memory location f.
If a is 0, the Access Bank is selected.
If a is 1, the BSR is used to select the
GPR bank.
If a is 0 and the extended instruction
set is enabled, this instruction operates
in Indexed Literal Offset Addressing
mode whenever f 95 (5Fh). See
Section 24.2.3 Byte-Oriented and
Bit-Oriented Instructions in Indexed
Literal Offset Mode for details.
Words:
Cycles:
0000
1011
kkkk
kkkk
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read literal
k
Process
Data
Write to W
Example:
ANDLW
05Fh
Before Instruction
W
=
After Instruction
W
A3h
03h
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
Example:
ADDWFC
Before Instruction
CARRY bit =
REG
=
W
=
After Instruction
CARRY bit =
REG
=
W
=
DS41303C-page 316
REG, 0, 1
1
02h
4Dh
0
02h
50h
Preliminary
PIC18F2XK20/4XK20
ANDWF
AND W with f
BC
Branch if Carry
Syntax:
ANDWF
Syntax:
BC
Operands:
0 f 255
d [0,1]
a [0,1]
Operands:
-128 n 127
Operation:
if CARRY bit is 1
(PC) + 2 + 2n PC
Status Affected:
None
f {,d {,a}}
Operation:
Status Affected:
N, Z
Encoding:
0001
Description:
Encoding:
01da
ffff
ffff
Words:
Cycles:
Q Cycle Activity:
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
ANDWF
REG, 0, 0
Before Instruction
W
=
REG
=
After Instruction
W
REG
=
=
Description:
0010
nnnn
nnnn
Words:
Cycles:
1(2)
Q Cycle Activity:
If Jump:
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
No
operation
No
operation
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
No
operation
Example:
HERE
Before Instruction
PC
After Instruction
If CARRY
PC
If CARRY
PC
17h
C2h
02h
C2h
1110
If No Jump:
Q1
Example:
Preliminary
BC
address (HERE)
=
=
=
=
1;
address (HERE + 12)
0;
address (HERE + 2)
DS41303C-page 317
PIC18F2XK20/4XK20
BCF
Bit Clear f
BN
Branch if Negative
Syntax:
BCF
Syntax:
BN
Operands:
0 f 255
0b7
a [0,1]
Operands:
-128 n 127
Operation:
if NEGATIVE bit is 1
(PC) + 2 + 2n PC
Status Affected:
None
f, b {,a}
Operation:
0 f<b>
Status Affected:
None
Encoding:
Encoding:
1001
Description:
bbba
ffff
ffff
Words:
Cycles:
1
Q1
Q2
Q3
Q4
Read
register f
Process
Data
Write
register f
Example:
BCF
Before Instruction
FLAG_REG =
After Instruction
FLAG_REG =
DS41303C-page 318
FLAG_REG,
1110
Description:
0110
nnnn
nnnn
Words:
Cycles:
1(2)
Q Cycle Activity:
If Jump:
Q Cycle Activity:
Decode
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
No
operation
No
operation
If No Jump:
7, 0
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
No
operation
C7h
47h
Example:
HERE
Before Instruction
PC
After Instruction
If NEGATIVE
PC
If NEGATIVE
PC
Preliminary
BN
Jump
address (HERE)
=
=
=
=
1;
address (Jump)
0;
address (HERE + 2)
PIC18F2XK20/4XK20
BNC
BNN
Syntax:
BNC
Syntax:
BNN
Operands:
-128 n 127
Operands:
-128 n 127
Operation:
if CARRY bit is 0
(PC) + 2 + 2n PC
Operation:
if NEGATIVE bit is 0
(PC) + 2 + 2n PC
Status Affected:
None
Status Affected:
None
Encoding:
1110
Description:
0011
nnnn
nnnn
Encoding:
1110
Description:
Words:
Words:
Cycles:
1(2)
Cycles:
1(2)
Q Cycle Activity:
If Jump:
0111
nnnn
nnnn
Q Cycle Activity:
If Jump:
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
Write to PC
Decode
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
No
operation
Decode
Read literal
n
Process
Data
No
operation
If No Jump:
Example:
If No Jump:
HERE
Before Instruction
PC
After Instruction
If CARRY
PC
If CARRY
PC
BNC
Jump
address (HERE)
=
=
=
=
0;
address (Jump)
1;
address (HERE + 2)
Example:
HERE
Before Instruction
PC
After Instruction
If NEGATIVE
PC
If NEGATIVE
PC
Preliminary
BNN
Jump
address (HERE)
=
=
=
=
0;
address (Jump)
1;
address (HERE + 2)
DS41303C-page 319
PIC18F2XK20/4XK20
BNOV
BNZ
Syntax:
BNOV
Syntax:
BNZ
Operands:
-128 n 127
Operands:
-128 n 127
Operation:
if OVERFLOW bit is 0
(PC) + 2 + 2n PC
Operation:
if ZERO bit is 0
(PC) + 2 + 2n PC
Status Affected:
None
Status Affected:
None
Encoding:
1110
Description:
0101
nnnn
nnnn
Encoding:
1110
Description:
Words:
Words:
Cycles:
1(2)
Cycles:
1(2)
Q Cycle Activity:
If Jump:
0001
nnnn
nnnn
Q Cycle Activity:
If Jump:
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
Write to PC
Decode
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
No
operation
Decode
Read literal
n
Process
Data
No
operation
If No Jump:
If No Jump:
Example:
HERE
Before Instruction
PC
=
After Instruction
If OVERFLOW =
PC
=
If OVERFLOW =
PC
=
DS41303C-page 320
BNOV Jump
Example:
HERE
Before Instruction
PC
After Instruction
If ZERO
PC
If ZERO
PC
address (HERE)
0;
address (Jump)
1;
address (HERE + 2)
Preliminary
BNZ
Jump
address (HERE)
=
=
=
=
0;
address (Jump)
1;
address (HERE + 2)
PIC18F2XK20/4XK20
BRA
Unconditional Branch
BSF
Syntax:
BRA
Syntax:
BSF
Operands:
-1024 n 1023
Operands:
0 f 255
0b7
a [0,1]
Operation:
(PC) + 2 + 2n PC
Status Affected:
None
Encoding:
1101
Description:
0nnn
nnnn
nnnn
Words:
Cycles:
Bit Set f
Operation:
1 f<b>
Status Affected:
None
Encoding:
1000
Q1
Q2
Q3
Q4
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
No
operation
No
operation
Example:
HERE
Before Instruction
PC
After Instruction
PC
BRA
Jump
address (HERE)
address (Jump)
ffff
ffff
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write
register f
Example:
BSF
Before Instruction
FLAG_REG
After Instruction
FLAG_REG
bbba
Description:
Q Cycle Activity:
Decode
f, b {,a}
Preliminary
FLAG_REG, 7, 1
0Ah
8Ah
DS41303C-page 321
PIC18F2XK20/4XK20
BTFSC
BTFSS
Syntax:
BTFSC f, b {,a}
Syntax:
BTFSS f, b {,a}
Operands:
0 f 255
0b7
a [0,1]
Operands:
0 f 255
0b<7
a [0,1]
Operation:
skip if (f<b>) = 0
Operation:
skip if (f<b>) = 1
Status Affected:
None
Status Affected:
None
Encoding:
1011
bbba
ffff
ffff
Encoding:
1010
bbba
ffff
ffff
Description:
Description:
Words:
Words:
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
Cycles:
1(2)
Note:
Q Cycle Activity:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
No
operation
Decode
Read
register f
Process
Data
No
operation
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
If skip:
If skip:
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Example:
HERE
FALSE
TRUE
Before Instruction
PC
After Instruction
If FLAG<1>
PC
If FLAG<1>
PC
DS41303C-page 322
BTFSC
:
:
FLAG, 1, 0
address (HERE)
=
=
=
=
0;
address (TRUE)
1;
address (FALSE)
Example:
HERE
FALSE
TRUE
Before Instruction
PC
After Instruction
If FLAG<1>
PC
If FLAG<1>
PC
Preliminary
BTFSS
:
:
FLAG, 1, 0
address (HERE)
=
=
=
=
0;
address (FALSE)
1;
address (TRUE)
PIC18F2XK20/4XK20
BTG
Bit Toggle f
BOV
Branch if Overflow
Syntax:
BTG f, b {,a}
Syntax:
BOV
Operands:
0 f 255
0b<7
a [0,1]
Operands:
-128 n 127
Operation:
if OVERFLOW bit is 1
(PC) + 2 + 2n PC
Status Affected:
None
Operation:
(f<b>) f<b>
Status Affected:
None
Encoding:
0111
Description:
Words:
Cycles:
Encoding:
bbba
ffff
ffff
1110
Description:
0100
nnnn
nnnn
Words:
Cycles:
1(2)
Q Cycle Activity:
If Jump:
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
No
operation
No
operation
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write
register f
Example:
BTG
PORTC,
4, 0
Before Instruction:
PORTC =
0111 0101 [75h]
After Instruction:
PORTC =
0110 0101 [65h]
If No Jump:
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
No
operation
Example:
HERE
Before Instruction
PC
=
After Instruction
If OVERFLOW =
PC
=
If OVERFLOW =
PC
=
Preliminary
BOV
Jump
address (HERE)
1;
address (Jump)
0;
address (HERE + 2)
DS41303C-page 323
PIC18F2XK20/4XK20
BZ
Branch if Zero
CALL
Subroutine Call
Syntax:
BZ
Syntax:
CALL k {,s}
Operands:
-128 n 127
Operands:
Operation:
if ZERO bit is 1
(PC) + 2 + 2n PC
0 k 1048575
s [0,1]
Operation:
(PC) + 4 TOS,
k PC<20:1>,
if s = 1
(W) WS,
(Status) STATUSS,
(BSR) BSRS
Status Affected:
None
Status Affected:
None
Encoding:
1110
Description:
0000
nnnn
nnnn
Words:
Cycles:
1(2)
Encoding:
1st word (k<7:0>)
2nd word(k<19:8>)
Q1
Q2
Q3
Q4
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
No
operation
No
operation
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
No
operation
If No Jump:
Example:
HERE
Before Instruction
PC
After Instruction
If ZERO
PC
If ZERO
PC
DS41303C-page 324
BZ
k7kkk
kkkk
110s
k19kkk
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
Jump
address (HERE)
=
=
=
=
1;
address (Jump)
0;
address (HERE + 2)
kkkk0
kkkk8
Description:
Q Cycle Activity:
If Jump:
Decode
1110
1111
No
operation
Example:
No
operation
HERE
Before Instruction
PC
=
After Instruction
PC
=
TOS
=
WS
=
BSRS
=
STATUSS =
Preliminary
No
operation
CALL
Read literal
k<19:8>,
Write to PC
No
operation
THERE, 1
address (HERE)
address (THERE)
address (HERE + 4)
W
BSR
Status
PIC18F2XK20/4XK20
CLRF
Clear f
Syntax:
CLRF
Operands:
0 f 255
a [0,1]
Operation:
000h f
1Z
Status Affected:
Encoding:
f {,a}
0110
Description:
101a
ffff
ffff
Words:
Cycles:
CLRWDT
Syntax:
CLRWDT
Operands:
None
Operation:
000h WDT,
000h WDT postscaler,
1 TO,
1 PD
Status Affected:
TO, PD
Encoding:
Q2
Q3
Q4
Read
register f
Process
Data
Write
register f
Example:
CLRF
Before Instruction
FLAG_REG
After Instruction
FLAG_REG
5Ah
00h
0100
Words:
Cycles:
Q Cycle Activity:
FLAG_REG, 1
0000
Q1
Q2
Q3
Q4
Decode
No
operation
Process
Data
No
operation
Example:
Q1
0000
Description:
Q Cycle Activity:
Decode
0000
Preliminary
CLRWDT
Before Instruction
WDT Counter
After Instruction
WDT Counter
WDT Postscaler
TO
PD
=
=
=
=
00h
0
1
1
DS41303C-page 325
PIC18F2XK20/4XK20
COMF
Complement f
CPFSEQ
Syntax:
COMF
Syntax:
CPFSEQ
Operands:
0 f 255
a [0,1]
Operation:
(f) (W),
skip if (f) = (W)
(unsigned comparison)
Status Affected:
None
f {,d {,a}}
0 f 255
d [0,1]
a [0,1]
Operands:
Operation:
(f) dest
Status Affected:
N, Z
Encoding:
0001
11da
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
Encoding:
0110
Description:
f {,a}
001a
ffff
ffff
Words:
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
Q Cycle Activity:
Example:
COMF
Before Instruction
REG
=
After Instruction
REG
=
W
=
REG, 0, 0
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
No
operation
13h
If skip:
13h
ECh
Q1
Q2
Q3
No
No
No
operation
operation
operation
If skip and followed by 2-word instruction:
Q1
Q2
Q3
No
No
No
operation
operation
operation
No
No
No
operation
operation
operation
Example:
DS41303C-page 326
Preliminary
HERE
NEQUAL
EQUAL
Q4
No
operation
Q4
No
operation
No
operation
CPFSEQ REG, 0
:
:
Before Instruction
PC Address
W
REG
After Instruction
=
=
=
HERE
?
?
If REG
PC
If REG
PC
=
=
W;
Address (EQUAL)
W;
Address (NEQUAL)
PIC18F2XK20/4XK20
CPFSGT
CPFSLT
Syntax:
CPFSGT
Syntax:
CPFSLT
Operands:
0 f 255
a [0,1]
Operands:
0 f 255
a [0,1]
Operation:
(f) (W),
skip if (f) > (W)
(unsigned comparison)
Operation:
(f) (W),
skip if (f) < (W)
(unsigned comparison)
Status Affected:
None
Status Affected:
None
Encoding:
0110
Description:
Words:
f {,a}
010a
ffff
ffff
Encoding:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
Q2
Read
register f
Q3
Process
Data
Q4
No
operation
Q1
Q2
Q3
No
No
No
operation
operation
operation
If skip and followed by 2-word instruction:
Q1
Q2
Q3
No
No
No
operation
operation
operation
No
No
No
operation
operation
operation
Q4
No
operation
Example:
HERE
NGREATER
GREATER
=
=
Address (HERE)
?
If REG
PC
If REG
PC
>
=
W;
Address (GREATER)
W;
Address (NGREATER)
ffff
Cycles:
1(2)
Note:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
No
operation
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
If skip:
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Example:
CPFSGT REG, 0
:
:
Before Instruction
PC
W
After Instruction
ffff
Words:
If skip:
Q4
No
operation
No
operation
000a
Q Cycle Activity:
Q1
Decode
0110
Description:
Cycles:
f {,a}
Preliminary
HERE
NLESS
LESS
CPFSLT REG, 1
:
:
Before Instruction
PC
W
After Instruction
=
=
Address (HERE)
?
If REG
PC
If REG
PC
<
=
W;
Address (LESS)
W;
Address (NLESS)
DS41303C-page 327
PIC18F2XK20/4XK20
DAW
DECF
Syntax:
DAW
Syntax:
Operands:
None
Operands:
Operation:
0 f 255
d [0,1]
a [0,1]
Operation:
(f) 1 dest
Status Affected:
C, DC, N, OV, Z
Decrement f
Encoding:
0000
0000
0000
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register W
Process
Data
Write
W
Cycles:
Q Cycle Activity:
DAW
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
Before Instruction
=
=
=
A5h
0
0
ffff
Example1:
W
=
C
=
DC
=
After Instruction
ffff
Words:
0111
Description:
01da
Encoding:
W
C
DC
Example 2:
0000
Description:
Example:
DECF
Before Instruction
CNT
=
Z
=
After Instruction
CNT
=
Z
=
05h
1
0
CNT,
1, 0
01h
0
00h
1
Before Instruction
W
=
C
=
DC
=
After Instruction
W
C
DC
=
=
=
DS41303C-page 328
CEh
0
0
34h
1
0
Preliminary
PIC18F2XK20/4XK20
Decrement f, skip if 0
DCFSNZ
Syntax:
Syntax:
DCFSNZ
Operands:
0 f 255
d [0,1]
a [0,1]
Operands:
0 f 255
d [0,1]
a [0,1]
Operation:
(f) 1 dest,
skip if result = 0
Operation:
(f) 1 dest,
skip if result 0
Status Affected:
None
Status Affected:
None
DECFSZ
Encoding:
0010
Description:
11da
ffff
ffff
Words:
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
Encoding:
0100
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
ffff
Words:
Cycles:
1(2)
Note:
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
If skip:
If skip:
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
HERE
DECFSZ
GOTO
CNT, 1, 1
LOOP
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Example:
CONTINUE
HERE
ZERO
NZERO
Before Instruction
TEMP
After Instruction
TEMP
If TEMP
PC
If TEMP
PC
Address (HERE)
CNT - 1
0;
Address (CONTINUE)
0;
Address (HERE + 2)
ffff
Q Cycle Activity:
Q1
Before Instruction
PC
=
After Instruction
CNT
=
If CNT
=
PC =
If CNT
PC =
11da
Description:
Q Cycle Activity:
Example:
f {,d {,a}}
Preliminary
DCFSNZ
:
:
TEMP, 1, 0
=
=
=
TEMP 1,
0;
Address (ZERO)
0;
Address (NZERO)
DS41303C-page 329
PIC18F2XK20/4XK20
GOTO
Unconditional Branch
INCF
Syntax:
GOTO k
Syntax:
INCF
Operands:
0 k 1048575
Operands:
Operation:
k PC<20:1>
Status Affected:
None
0 f 255
d [0,1]
a [0,1]
Operation:
(f) + 1 dest
Status Affected:
C, DC, N, OV, Z
Encoding:
1st word (k<7:0>)
2nd word(k<19:8>)
1110
1111
1111
k19kkk
k7kkk
kkkk
kkkk0
kkkk8
Description:
Increment f
Encoding:
0010
Cycles:
2
Q1
Q2
Q3
Q4
Read literal
k<7:0>,
No
operation
Read literal
k<19:8>,
Write to PC
No
operation
No
operation
No
operation
No
operation
ffff
ffff
Words:
Cycles:
Q Cycle Activity:
Decode
10da
Description:
f {,d {,a}}
Q Cycle Activity:
Example:
GOTO THERE
After Instruction
PC =
Address (THERE)
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
Example:
INCF
Before Instruction
CNT
=
Z
=
C
=
DC
=
After Instruction
CNT
=
Z
=
C
=
DC
=
DS41303C-page 330
Preliminary
CNT, 1, 0
FFh
0
?
?
00h
1
1
1
PIC18F2XK20/4XK20
INCFSZ
Increment f, skip if 0
INFSNZ
Syntax:
INCFSZ
Syntax:
INFSNZ
0 f 255
d [0,1]
a [0,1]
f {,d {,a}}
Operands:
0 f 255
d [0,1]
a [0,1]
Operands:
Operation:
(f) + 1 dest,
skip if result = 0
Operation:
(f) + 1 dest,
skip if result 0
Status Affected:
None
Status Affected:
None
Encoding:
0011
Description:
11da
ffff
ffff
Encoding:
0100
Description:
Words:
Words:
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
Cycles:
1(2)
Note:
Q Cycle Activity:
10da
ffff
ffff
Q Cycle Activity:
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
Decode
Read
register f
Process
Data
Write to
destination
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
If skip:
If skip:
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Example:
HERE
NZERO
ZERO
Before Instruction
PC
=
After Instruction
CNT
=
If CNT
=
PC
=
If CNT
PC
=
INCFSZ
:
:
CNT, 1, 0
Example:
Before Instruction
PC
=
After Instruction
REG
=
If REG
PC
=
If REG
=
PC
=
Address (HERE)
CNT + 1
0;
Address (ZERO)
0;
Address (NZERO)
HERE
ZERO
NZERO
Preliminary
INFSNZ
REG, 1, 0
Address (HERE)
REG + 1
0;
Address (NZERO)
0;
Address (ZERO)
DS41303C-page 331
PIC18F2XK20/4XK20
IORLW
IORWF
Syntax:
IORLW k
Syntax:
IORWF
Operands:
0 k 255
Operands:
Operation:
(W) .OR. k W
Status Affected:
N, Z
0 f 255
d [0,1]
a [0,1]
Operation:
Status Affected:
N, Z
Encoding:
0000
Description:
1001
kkkk
kkkk
Words:
Cycles:
Inclusive OR W with f
Encoding:
0001
Q1
Q2
Q3
Q4
Read
literal k
Process
Data
Write to W
Example:
IORLW
ffff
Words:
Cycles:
35h
9Ah
BFh
ffff
Before Instruction
W
=
After Instruction
00da
Description:
Q Cycle Activity:
Decode
f {,d {,a}}
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
Example:
IORWF
Before Instruction
RESULT =
W
=
After Instruction
RESULT =
W
=
DS41303C-page 332
Preliminary
RESULT, 0, 1
13h
91h
13h
93h
PIC18F2XK20/4XK20
LFSR
Load FSR
MOVF
Syntax:
LFSR f, k
Syntax:
MOVF
Operands:
0f2
0 k 4095
Operands:
Operation:
k FSRf
0 f 255
d [0,1]
a [0,1]
Status Affected:
None
Operation:
f dest
Status Affected:
N, Z
Encoding:
1110
1111
1110
0000
00ff
k7kkk
k11kkk
kkkk
Description:
Words:
Cycles:
Move f
Encoding:
0101
Q1
Q2
Q3
Q4
Read literal
k MSB
Process
Data
Write
literal k
MSB to
FSRfH
Decode
Read literal
k LSB
Process
Data
Write literal
k to FSRfL
Example:
After Instruction
FSR2H
FSR2L
03h
ABh
ffff
ffff
Words:
Cycles:
LFSR 2, 3ABh
=
=
00da
Description:
Q Cycle Activity:
Decode
f {,d {,a}}
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write W
Example:
MOVF
Before Instruction
REG
W
After Instruction
REG
W
Preliminary
REG, 0, 0
=
=
22h
FFh
=
=
22h
22h
DS41303C-page 333
PIC18F2XK20/4XK20
MOVFF
Move f to f
MOVLB
Syntax:
MOVFF fs,fd
Syntax:
MOVLW k
Operands:
0 fs 4095
0 fd 4095
Operands:
0 k 255
Operation:
k BSR
Operation:
(fs) fd
Status Affected:
None
Status Affected:
None
Encoding:
Encoding:
1st word (source)
2nd word (destin.)
1100
1111
Description:
ffff
ffff
ffff
ffff
ffffs
ffffd
Words:
Cycles:
2 (3)
0000
0001
kkkk
kkkk
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
literal k
Process
Data
Write literal
k to BSR
MOVLB
Example:
Before Instruction
BSR Register =
After Instruction
BSR Register =
02h
05h
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
(src)
Process
Data
No
operation
Decode
No
operation
No
operation
Write
register f
(dest)
No dummy
read
Example:
MOVFF
Before Instruction
REG1
REG2
After Instruction
REG1
REG2
DS41303C-page 334
REG1, REG2
=
=
33h
11h
=
=
33h
33h
Preliminary
PIC18F2XK20/4XK20
MOVLW
Move literal to W
MOVWF
Syntax:
MOVLW k
Syntax:
MOVWF
Operands:
0 k 255
Operands:
Operation:
kW
0 f 255
a [0,1]
Status Affected:
None
Operation:
(W) f
Status Affected:
None
Encoding:
0000
1110
kkkk
kkkk
Description:
Words:
Cycles:
Move W to f
Encoding:
0110
Q1
Q2
Q3
Q4
Read
literal k
Process
Data
Write to W
Example:
MOVLW
=
ffff
ffff
Words:
Cycles:
5Ah
After Instruction
W
111a
Description:
Q Cycle Activity:
Decode
f {,a}
5Ah
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write
register f
Example:
MOVWF
REG, 0
Before Instruction
W
=
REG
=
After Instruction
W
REG
Preliminary
=
=
4Fh
FFh
4Fh
4Fh
DS41303C-page 335
PIC18F2XK20/4XK20
MULLW
MULWF
Multiply W with f
Syntax:
MULLW
Syntax:
MULWF
Operands:
0 k 255
Operands:
Operation:
(W) x k PRODH:PRODL
0 f 255
a [0,1]
Status Affected:
None
Operation:
Status Affected:
None
Encoding:
0000
Description:
1101
kkkk
kkkk
Words:
Cycles:
Encoding:
0000
Q1
Q2
Q3
Q4
Read
literal k
Process
Data
Write
registers
PRODH:
PRODL
Example:
MULLW
W
PRODH
PRODL
After Instruction
W
PRODH
PRODL
=
=
=
E2h
?
?
=
=
=
E2h
ADh
08h
ffff
ffff
Words:
Cycles:
0C4h
Before Instruction
001a
Description:
Q Cycle Activity:
Decode
f {,a}
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write
registers
PRODH:
PRODL
Example:
MULWF
REG, 1
Before Instruction
W
REG
PRODH
PRODL
After Instruction
W
REG
PRODH
PRODL
DS41303C-page 336
Preliminary
=
=
=
=
C4h
B5h
?
?
=
=
=
=
C4h
B5h
8Ah
94h
PIC18F2XK20/4XK20
NEGF
Negate f
NOP
No Operation
Syntax:
NEGF
Syntax:
NOP
Operands:
0 f 255
a [0,1]
Operands:
None
Operation:
(f)+1f
Status Affected:
N, OV, C, DC, Z
Encoding:
f {,a}
0110
Description:
Cycles:
No operation
Status Affected:
None
Encoding:
110a
ffff
0000
1111
ffff
Words:
Operation:
0000
xxxx
Description:
No operation.
Words:
Cycles:
0000
xxxx
0000
xxxx
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
No
operation
No
operation
No
operation
Example:
None.
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write
register f
Example:
NEGF
Before Instruction
REG
=
After Instruction
REG
=
REG, 1
Preliminary
DS41303C-page 337
PIC18F2XK20/4XK20
POP
PUSH
Syntax:
POP
Syntax:
PUSH
Operands:
None
Operands:
None
Operation:
Operation:
(PC + 2) TOS
Status Affected:
None
Status Affected:
None
Encoding:
0000
0000
0000
0110
Description:
Words:
Cycles:
Encoding:
0000
0101
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
No
operation
POP TOS
value
No
operation
POP
GOTO
NEW
Q1
Q2
Q3
Q4
Decode
PUSH
PC + 2 onto
return stack
No
operation
No
operation
Example:
Before Instruction
TOS
Stack (1 level down)
=
=
0031A2h
014332h
After Instruction
TOS
PC
=
=
014332h
NEW
DS41303C-page 338
0000
Q Cycle Activity:
Example:
0000
Description:
Preliminary
PUSH
Before Instruction
TOS
PC
=
=
345Ah
0124h
After Instruction
PC
TOS
Stack (1 level down)
=
=
=
0126h
0126h
345Ah
PIC18F2XK20/4XK20
RCALL
Relative Call
RESET
Reset
Syntax:
RCALL
Syntax:
RESET
Operands:
-1024 n 1023
Operands:
None
Operation:
(PC) + 2 TOS,
(PC) + 2 + 2n PC
Operation:
Status Affected:
None
Status Affected:
All
Encoding:
1101
Description:
1nnn
nnnn
nnnn
Words:
Cycles:
Encoding:
0000
Q2
Q3
Q4
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
1111
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Start
Reset
No
operation
No
operation
Example:
Q1
1111
Description:
Q Cycle Activity:
Decode
0000
After Instruction
Registers =
Flags*
=
RESET
Reset Value
Reset Value
PUSH PC to
stack
No
operation
Example:
No
operation
HERE
RCALL Jump
Before Instruction
PC =
Address (HERE)
After Instruction
PC =
Address (Jump)
TOS =
Address (HERE + 2)
Preliminary
DS41303C-page 339
PIC18F2XK20/4XK20
RETFIE
RETLW
Return literal to W
Syntax:
RETFIE {s}
Syntax:
RETLW k
Operands:
s [0,1]
Operands:
0 k 255
Operation:
(TOS) PC,
1 GIE/GIEH or PEIE/GIEL,
if s = 1
(WS) W,
(STATUSS) Status,
(BSRS) BSR,
PCLATU, PCLATH are unchanged.
Operation:
k W,
(TOS) PC,
PCLATU, PCLATH are unchanged
Status Affected:
None
Status Affected:
0000
0000
0001
Cycles:
Q Cycle Activity:
Q2
Q3
Q4
Decode
No
operation
No
operation
POP PC
from stack
Set GIEH or
GIEL
No
operation
RETFIE
After Interrupt
PC
W
BSR
Status
GIE/GIEH, PEIE/GIEL
DS41303C-page 340
kkkk
kkkk
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
literal k
Process
Data
POP PC
from stack,
Write to W
No
operation
No
operation
No
operation
No
operation
Example:
Q1
Example:
1100
000s
Words:
No
operation
0000
Description:
GIE/GIEH, PEIE/GIEL.
Encoding:
Description:
Encoding:
No
operation
No
operation
1
=
=
=
=
=
TOS
WS
BSRS
STATUSS
1
CALL TABLE ;
;
;
;
:
TABLE
ADDWF PCL ;
RETLW k0
;
RETLW k1
;
:
:
RETLW kn
;
Before Instruction
W
=
After Instruction
W
=
Preliminary
W contains table
offset value
W now has
table value
W = offset
Begin table
End of table
07h
value of kn
PIC18F2XK20/4XK20
RETURN
RLCF
Syntax:
RETURN {s}
Syntax:
RLCF
Operands:
s [0,1]
Operands:
Operation:
(TOS) PC,
if s = 1
(WS) W,
(STATUSS) Status,
(BSRS) BSR,
PCLATU, PCLATH are unchanged
0 f 255
d [0,1]
a [0,1]
Operation:
Status Affected:
C, N, Z
Status Affected:
None
Encoding:
0000
Encoding:
0000
0001
001s
Description:
Words:
Cycles:
0011
Description:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
No
operation
Process
Data
POP PC
from stack
No
operation
No
operation
No
operation
No
operation
f {,d {,a}}
01da
ffff
ffff
C
Words:
Cycles:
Q Cycle Activity:
Example:
RETURN
After Instruction:
PC = TOS
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
Example:
Before Instruction
REG
=
C
=
After Instruction
REG
=
W
=
C
=
Preliminary
RLCF
REG, 0, 0
1110 0110
0
1110 0110
1100 1100
1
DS41303C-page 341
PIC18F2XK20/4XK20
RLNCF
RRCF
Syntax:
RLNCF
Syntax:
RRCF
Operands:
0 f 255
d [0,1]
a [0,1]
Operands:
0 f 255
d [0,1]
a [0,1]
Operation:
Operation:
Status Affected:
N, Z
Status Affected:
C, N, Z
Encoding:
0100
Description:
f {,d {,a}}
01da
ffff
ffff
Encoding:
0011
Description:
register f
Words:
Cycles:
1
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
Before Instruction
REG
=
After Instruction
REG
=
DS41303C-page 342
00da
RLNCF
Words:
Cycles:
ffff
register f
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
RRCF
REG, 0, 0
REG, 1, 0
1010 1011
ffff
Q Cycle Activity:
Example:
f {,d {,a}}
Example:
Before Instruction
REG
=
C
=
After Instruction
REG
=
W
=
C
=
0101 0111
Preliminary
1110 0110
0
1110 0110
0111 0011
0
PIC18F2XK20/4XK20
RRNCF
SETF
Syntax:
RRNCF
Syntax:
SETF
Operands:
0 f 255
d [0,1]
a [0,1]
Operands:
0 f 255
a [0,1]
Operation:
FFh f
Operation:
Status Affected:
None
Status Affected:
f {,d {,a}}
Encoding:
N, Z
Encoding:
0100
Description:
00da
ffff
ffff
Cycles:
1
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Example 1:
RRNCF
Before Instruction
REG
=
After Instruction
REG
=
Example 2:
100a
ffff
ffff
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write
register f
Example:
Q1
0110
Q Cycle Activity:
Decode
f {,a}
Description:
register f
Words:
Set f
SETF
Before Instruction
REG
After Instruction
REG
REG, 1
5Ah
FFh
REG, 1, 0
1101 0111
1110 1011
RRNCF
REG, 0, 0
Before Instruction
W
=
REG
=
After Instruction
?
1101 0111
=
=
1110 1011
1101 0111
W
REG
Preliminary
DS41303C-page 343
PIC18F2XK20/4XK20
SLEEP
SUBFWB
Syntax:
SLEEP
Syntax:
SUBFWB
Operands:
None
Operands:
Operation:
00h WDT,
0 WDT postscaler,
1 TO,
0 PD
0 f 255
d [0,1]
a [0,1]
Operation:
Status Affected:
N, OV, C, DC, Z
Status Affected:
TO, PD
Encoding:
0000
Encoding:
0000
0000
0011
Description:
Words:
Cycles:
0101
Q1
Q2
Q3
Q4
Decode
No
operation
Process
Data
Go to
Sleep
SLEEP
Before Instruction
TO =
?
PD =
?
DS41303C-page 344
01da
ffff
ffff
Words:
Cycles:
Q Cycle Activity:
After Instruction
1
TO =
0
PD =
If WDT causes wake-up, this bit is cleared.
f {,d {,a}}
Description:
Q Cycle Activity:
Example:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
SUBFWB
REG, 1, 0
Example 1:
Before Instruction
REG
=
3
W
=
2
C
=
1
After Instruction
REG
=
FF
W
=
2
C
=
0
Z
=
0
N
=
1 ; result is negative
SUBFWB
REG, 0, 0
Example 2:
Before Instruction
REG
=
2
W
=
5
C
=
1
After Instruction
REG
=
2
W
=
3
C
=
1
Z
=
0
N
=
0 ; result is positive
SUBFWB
REG, 1, 0
Example 3:
Before Instruction
REG
=
1
W
=
2
C
=
0
After Instruction
REG
=
0
W
=
2
C
=
1
Z
=
1 ; result is zero
N
=
0
Preliminary
PIC18F2XK20/4XK20
SUBLW
SUBWF
Syntax:
SUBLW k
Syntax:
SUBWF
Operands:
0 k 255
Operands:
Operation:
k (W) W
Status Affected:
N, OV, C, DC, Z
0 f 255
d [0,1]
a [0,1]
Operation:
Status Affected:
N, OV, C, DC, Z
Encoding:
0000
Description
1000
kkkk
kkkk
Words:
Cycles:
Subtract W from f
Encoding:
0101
Q2
Q3
Q4
Decode
Read
literal k
Process
Data
Write to W
Example 1:
Before Instruction
W
=
C
=
After Instruction
W
=
C
=
Z
=
N
=
Example 2:
Before Instruction
W
=
C
=
After Instruction
W
=
C
=
Z
=
N
=
Example 3:
Before Instruction
W
=
C
=
After Instruction
W
=
C
=
Z
=
N
=
SUBLW
02h
Cycles:
Q Cycle Activity:
02h
?
00h
1
; result is zero
1
0
SUBLW
ffff
Words:
01h
?
SUBLW
ffff
02h
01h
1
; result is positive
0
0
11da
Description:
Q Cycle Activity:
Q1
f {,d {,a}}
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
SUBWF
REG, 1, 0
Example 1:
Before Instruction
REG
=
W
=
C
=
After Instruction
REG
=
W
=
C
=
Z
=
N
=
02h
03h
?
FFh ; (2s complement)
0
; result is negative
0
1
Example 2:
Before Instruction
REG
=
W
=
C
=
After Instruction
REG
=
W
=
C
=
Z
=
N
=
Example 3:
Before Instruction
REG
=
W
=
C
=
After Instruction
REG
=
W
=
C
=
Z
=
N
=
Preliminary
3
2
?
1
2
1
0
0
; result is positive
SUBWF
REG, 0, 0
2
2
?
2
0
1
1
0
SUBWF
; result is zero
REG, 1, 0
1
2
?
FFh ;(2s complement)
2
0
; result is negative
0
1
DS41303C-page 345
PIC18F2XK20/4XK20
SUBWFB
SWAPF
Swap f
Syntax:
SUBWFB
Syntax:
Operands:
0 f 255
d [0,1]
a [0,1]
Operands:
0 f 255
d [0,1]
a [0,1]
Operation:
Operation:
Status Affected:
N, OV, C, DC, Z
(f<3:0>) dest<7:4>,
(f<7:4>) dest<3:0>
Status Affected:
None
Encoding:
0101
Description:
f {,d {,a}}
10da
ffff
ffff
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Q2
Read
register f
Example 1:
SUBWFB
Before Instruction
REG
=
W
=
C
=
After Instruction
REG
=
W
=
C
=
Z
=
N
=
Example 2:
Q4
Write to
destination
(0001 1001)
(0000 1101)
0Ch
0Dh
1
0
0
(0000 1100)
(0000 1101)
10da
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
REG, 1, 0
19h
0Dh
1
0011
Example:
SWAPF
Before Instruction
REG
=
After Instruction
REG
=
REG, 1, 0
53h
35h
; result is positive
SUBWFB REG, 0, 0
Before Instruction
REG
=
W
=
C
=
After Instruction
REG
=
W
=
C
=
Z
=
N
=
Example 3:
1Bh
1Ah
0
(0001 1011)
(0001 1010)
1Bh
00h
1
1
0
(0001 1011)
SUBWFB
Before Instruction
REG
=
W
=
C
=
After Instruction
REG
=
W
C
Z
N
Q3
Process
Data
Encoding:
=
=
=
=
DS41303C-page 346
; result is zero
REG, 1, 0
03h
0Eh
1
(0000 0011)
(0000 1110)
F5h
(1111 0101)
; [2s comp]
(0000 1110)
0Eh
0
0
1
; result is negative
Preliminary
PIC18F2XK20/4XK20
TBLRD
Table Read
TBLRD
Syntax:
Example1:
TBLRD
Operands:
None
Operation:
if TBLRD *,
(Prog Mem (TBLPTR)) TABLAT;
TBLPTR No Change;
if TBLRD *+,
(Prog Mem (TBLPTR)) TABLAT;
(TBLPTR) + 1 TBLPTR;
if TBLRD *-,
(Prog Mem (TBLPTR)) TABLAT;
(TBLPTR) 1 TBLPTR;
if TBLRD +*,
(TBLPTR) + 1 TBLPTR;
(Prog Mem (TBLPTR)) TABLAT;
Example2:
0000
0000
0000
*+ ;
Before Instruction
TABLAT
TBLPTR
MEMORY (00A356h)
After Instruction
TABLAT
TBLPTR
10nn
nn=0 *
=1 *+
=2 *=3 +*
Description:
Words:
Cycles:
TBLRD
=
=
=
55h
00A356h
34h
=
=
34h
00A357h
+* ;
Before Instruction
TABLAT
TBLPTR
MEMORY (01A357h)
MEMORY (01A358h)
After Instruction
TABLAT
TBLPTR
=
=
=
=
AAh
01A357h
12h
34h
=
=
34h
01A358h
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
No
operation
No
operation
No
operation
No
operation
No operation
(Read Program
Memory)
No
operation
No operation
(Write TABLAT)
Preliminary
DS41303C-page 347
PIC18F2XK20/4XK20
TBLWT
Table Write
TBLWT
Syntax:
Example1:
TBLWT *+;
Operands:
None
Operation:
if TBLWT*,
(TABLAT) Holding Register;
TBLPTR No Change;
if TBLWT*+,
(TABLAT) Holding Register;
(TBLPTR) + 1 TBLPTR;
if TBLWT*-,
(TABLAT) Holding Register;
(TBLPTR) 1 TBLPTR;
if TBLWT+*,
(TBLPTR) + 1 TBLPTR;
(TABLAT) Holding Register;
Status Affected:
Before Instruction
TABLAT
=
55h
TBLPTR
=
00A356h
HOLDING REGISTER
(00A356h)
=
FFh
After Instructions (table write completion)
TABLAT
=
55h
TBLPTR
=
00A357h
HOLDING REGISTER
(00A356h)
=
55h
Example 2:
None
Encoding:
0000
0000
0000
11nn
nn=0 *
=1 *+
=2 *=3 +*
Description:
Words:
Cycles:
TBLWT +*;
Before Instruction
TABLAT
=
34h
TBLPTR
=
01389Ah
HOLDING REGISTER
(01389Ah)
=
FFh
HOLDING REGISTER
(01389Bh)
=
FFh
After Instruction (table write completion)
TABLAT
=
34h
TBLPTR
=
01389Bh
HOLDING REGISTER
(01389Ah)
=
FFh
HOLDING REGISTER
(01389Bh)
=
34h
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
No
No
No
operation operation operation
No
No
No
No
operation operation operation operation
(Read
(Write to
TABLAT)
Holding
Register )
DS41303C-page 348
Preliminary
PIC18F2XK20/4XK20
TSTFSZ
Test f, skip if 0
XORLW
Syntax:
TSTFSZ f {,a}
Syntax:
XORLW k
Operands:
0 f 255
a [0,1]
Operands:
0 k 255
Operation:
(W) .XOR. k W
Operation:
skip if f = 0
Status Affected:
N, Z
Status Affected:
None
Encoding:
Encoding:
0110
Description:
011a
ffff
ffff
Words:
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
0000
1010
kkkk
kkkk
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
literal k
Process
Data
Write to W
Example:
XORLW
0AFh
Before Instruction
W
=
After Instruction
W
B5h
1Ah
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
No
operation
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
If skip:
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Example:
HERE
NZERO
ZERO
Before Instruction
PC
After Instruction
If CNT
PC
If CNT
PC
TSTFSZ
:
:
CNT, 1
Address (HERE)
=
=
00h,
Address (ZERO)
00h,
Address (NZERO)
Preliminary
DS41303C-page 349
PIC18F2XK20/4XK20
XORWF
Exclusive OR W with f
Syntax:
XORWF
Operands:
0 f 255
d [0,1]
a [0,1]
Operation:
Status Affected:
N, Z
Encoding:
0001
f {,d {,a}}
10da
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
Example:
XORWF
Before Instruction
REG
=
W
=
After Instruction
REG
=
W
=
DS41303C-page 350
REG, 1, 0
AFh
B5h
1Ah
B5h
Preliminary
PIC18F2XK20/4XK20
24.2
A summary of the instructions in the extended instruction set is provided in Table 24-3. Detailed descriptions
are provided in Section 24.2.2 Extended Instruction
Set. The opcode field descriptions in Table 24-1 apply
to both the standard and extended PIC18 instruction
sets.
Note:
24.2.1
TABLE 24-3:
Note:
Mnemonic,
Operands
ADDFSR
ADDULNK
CALLW
MOVSF
f, k
k
MOVSS
zs, zd
PUSHL
SUBFSR
SUBULNK
f, k
k
zs, fd
Description
Cycles
1
2
2
2
LSb
Status
Affected
1000
1000
0000
1011
ffff
1011
xxxx
1010
ffkk
11kk
0001
0zzz
ffff
1zzz
xzzz
kkkk
kkkk
kkkk
0100
zzzz
ffff
zzzz
zzzz
kkkk
None
None
None
None
1110
1110
0000
1110
1111
1110
1111
1110
1
2
1110
1110
1001
1001
ffkk
11kk
kkkk
kkkk
None
None
Preliminary
None
None
DS41303C-page 351
PIC18F2XK20/4XK20
24.2.2
ADDFSR
ADDULNK
Syntax:
ADDFSR f, k
Syntax:
ADDULNK k
Operands:
0 k 63
f [ 0, 1, 2 ]
Operands:
0 k 63
Operation:
FSR(f) + k FSR(f)
Status Affected:
None
Encoding:
1110
FSR2 + k FSR2,
Operation:
(TOS) PC
Status Affected:
1000
ffkk
kkkk
Description:
Words:
Cycles:
None
Encoding:
1110
Q1
Q2
Q3
Q4
Read
literal k
Process
Data
Write to
FSR
Example:
ADDFSR 2, 23h
Before Instruction
FSR2
=
03FFh
After Instruction
FSR2
=
0422h
kkkk
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
literal k
Process
Data
Write to
FSR
No
Operation
No
Operation
No
Operation
No
Operation
Example:
Note:
11kk
Q Cycle Activity:
Decode
1000
Description:
ADDULNK 23h
Before Instruction
FSR2
=
PC
=
03FFh
0100h
After Instruction
FSR2
=
PC
=
0422h
(TOS)
All PIC18 instructions may take an optional label argument preceding the instruction mnemonic for use in
symbolic addressing. If a label is used, the instruction syntax then becomes: {label} instruction argument(s).
DS41303C-page 352
Preliminary
PIC18F2XK20/4XK20
CALLW
MOVSF
Syntax:
CALLW
Syntax:
MOVSF [zs], fd
Operands:
None
Operands:
Operation:
(PC + 2) TOS,
(W) PCL,
(PCLATH) PCH,
(PCLATU) PCU
0 zs 127
0 fd 4095
Operation:
((FSR2) + zs) fd
Status Affected:
None
Status Affected:
None
Encoding:
0000
0000
0001
0100
Description
Words:
Cycles:
Move Indexed to f
Encoding:
1st word (source)
2nd word (destin.)
Q1
Q2
Q3
Q4
Read
WREG
PUSH PC to
stack
No
operation
No
operation
No
operation
No
operation
No
operation
HERE
Before Instruction
PC
=
PCLATH =
PCLATU =
W
=
After Instruction
PC
=
TOS
=
PCLATH =
PCLATU =
W
=
Cycles:
Q Cycle Activity:
Q1
Decode
address (HERE)
10h
00h
06h
zzzzs
ffffd
Words:
CALLW
001006h
address (HERE + 2)
10h
00h
06h
0zzz
ffff
Decode
Example:
1011
ffff
Description:
Q Cycle Activity:
Decode
1110
1111
Q2
Q3
Determine
Determine
source addr source addr
No
operation
No
operation
No dummy
read
Example:
MOVSF
Before Instruction
FSR2
Contents
of 85h
REG2
After Instruction
FSR2
Contents
of 85h
REG2
Preliminary
Q4
Read
source reg
Write
register f
(dest)
[05h], REG2
80h
=
=
33h
11h
80h
=
=
33h
33h
DS41303C-page 353
PIC18F2XK20/4XK20
MOVSS
PUSHL
Syntax:
Syntax:
PUSHL k
Operands:
Operands:
0 k 255
Operation:
Operation:
k (FSR2),
FSR2 1 FSR2
Status Affected:
None
Status Affected:
None
Encoding:
1st word (source)
2nd word (dest.)
1110
1111
Description
1011
xxxx
1zzz
xzzz
zzzzs
zzzzd
Words:
Cycles:
Encoding:
Q1
Decode
Q2
Q3
Determine
Determine
source addr source addr
Determine
dest addr
Example:
1010
kkkk
kkkk
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read k
Process
data
Write to
destination
Example:
PUSHL 08h
Before Instruction
FSR2H:FSR2L
Memory (01ECh)
=
=
01ECh
00h
After Instruction
FSR2H:FSR2L
Memory (01ECh)
=
=
01EBh
08h
Q4
Read
source reg
Write
to dest reg
Before Instruction
FSR2
Contents
of 85h
Contents
of 86h
After Instruction
FSR2
Contents
of 85h
Contents
of 86h
DS41303C-page 354
Determine
dest addr
1111
Description:
Q Cycle Activity:
Decode
80h
33h
11h
80h
33h
33h
Preliminary
PIC18F2XK20/4XK20
SUBFSR
SUBULNK
Syntax:
SUBFSR f, k
Syntax:
SUBULNK k
Operands:
0 k 63
Operands:
0 k 63
f [ 0, 1, 2 ]
Operation:
Operation:
FSR(f) k FSRf
Status Affected:
None
Encoding:
1110
FSR2 k FSR2
(TOS) PC
ffkk
kkkk
Description:
Words:
Cycles:
Encoding:
1110
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
SUBFSR 2, 23h
1001
11kk
kkkk
Description:
Words:
Cycles:
Q Cycle Activity:
Example:
Q Cycle Activity:
Before Instruction
FSR2
=
Q1
Q2
Q3
Q4
03FFh
Decode
After Instruction
FSR2
=
Read
register f
Process
Data
Write to
destination
03DCh
No
Operation
No
Operation
No
Operation
No
Operation
Example:
Preliminary
SUBULNK 23h
Before Instruction
FSR2
=
PC
=
03FFh
0100h
After Instruction
FSR2
=
PC
=
03DCh
(TOS)
DS41303C-page 355
PIC18F2XK20/4XK20
24.2.3
Note:
BYTE-ORIENTED AND
BIT-ORIENTED INSTRUCTIONS IN
INDEXED LITERAL OFFSET MODE
Enabling the PIC18 instruction set
extension may cause legacy applications
to behave erratically or fail entirely.
24.2.3.1
24.2.4
CONSIDERATIONS WHEN
ENABLING THE EXTENDED
INSTRUCTION SET
It is important to note that the extensions to the instruction set may not be beneficial to all users. In particular,
users who are not writing code that uses a software
stack may not benefit from using the extensions to the
instruction set.
DS41303C-page 356
Preliminary
PIC18F2XK20/4XK20
ADDWF
ADD W to Indexed
(Indexed Literal Offset mode)
BSF
Syntax:
ADDWF
Syntax:
BSF [k], b
Operands:
0 k 95
d [0,1]
Operands:
0 f 95
0b7
Operation:
Operation:
1 ((FSR2) + k)<b>
Status Affected:
N, OV, C, DC, Z
Status Affected:
None
Encoding:
[k] {,d}
0010
Description:
01d0
kkkk
kkkk
Encoding:
1000
bbb0
kkkk
kkkk
Description:
Words:
Cycles:
Q Cycle Activity:
Words:
Q1
Q2
Q3
Q4
Cycles:
Decode
Read
register f
Process
Data
Write to
destination
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read k
Process
Data
Write to
destination
Example:
ADDWF
Example:
Before Instruction
FLAG_OFST
FSR2
Contents
of 0A0Ah
After Instruction
Contents
of 0A0Ah
[OFST] , 0
Before Instruction
W
OFST
FSR2
Contents
of 0A2Ch
After Instruction
W
Contents
of 0A2Ch
=
=
=
17h
2Ch
0A00h
20h
37h
20h
BSF
[FLAG_OFST], 7
=
=
0Ah
0A00h
55h
D5h
SETF
Set Indexed
(Indexed Literal Offset mode)
Syntax:
SETF [k]
Operands:
0 k 95
Operation:
FFh ((FSR2) + k)
Status Affected:
None
Encoding:
0110
1000
kkkk
kkkk
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read k
Process
Data
Write
register
Example:
SETF
Before Instruction
OFST
FSR2
Contents
of 0A2Ch
After Instruction
Contents
of 0A2Ch
Preliminary
[OFST]
=
=
2Ch
0A00h
00h
FFh
DS41303C-page 357
PIC18F2XK20/4XK20
24.2.5
DS41303C-page 358
Preliminary
PIC18F2XK20/4XK20
25.0
DEVELOPMENT SUPPORT
25.1
Preliminary
DS41303C-page 359
PIC18F2XK20/4XK20
25.2
MPASM Assembler
25.5
25.3
25.6
25.4
DS41303C-page 360
Preliminary
PIC18F2XK20/4XK20
25.7
25.9
25.8
Preliminary
DS41303C-page 361
PIC18F2XK20/4XK20
25.11 PICSTART Plus Development
Programmer
DS41303C-page 362
Preliminary
PIC18F2XK20/4XK20
26.0
ELECTRICAL CHARACTERISTICS
Preliminary
DS41303C-page 363
PIC18F2XK20/4XK20
FIGURE 26-1:
3.5V
3.0V
Voltage
2.7V
2.2V
1.8V
10
20
30 32
40
50
60
64
Frequency (MHz)
DS41303C-page 364
Preliminary
PIC18F2XK20/4XK20
26.1
PIC18F2XK20/4XK20
Param
Symbol
No.
Characteristic
Typ
Max
Units
D001
VDD
Supply Voltage
1.8
3.6
D002
VDR
1.5
D003
VPOR
0.7
D004
SVDD
0.05
D005
VBOR
BORV<1:0> = 11
1.8
BORV<1:0> = 10
2.3
BORV<1:0> = 01
2.8
BORV<1:0> = 00
3.1
This is the limit to which VDD can be lowered in Sleep mode, or during a device Reset, without losing RAM
data.
Note 1:
26.2
Conditions
PIC18F2XK20/4XK20
Param
No.
D006
Device Characteristics
Typ
0.1
-40C
0.1
+25C
0.5
+85C
D007
Note 1:
Conditions
+125C
0.1
-40C
0.3
+25C
0.8
+85C
15
+125C
The power-down current in Sleep mode does not depend on the oscillator type. Power-down current is
measured with the part in Sleep mode, with all I/O pins in high-impedance state and tied to VDD or VSS and
all features that add delta current disabled (such as WDT, Timer1 Oscillator, BOR, etc.).
Preliminary
DS41303C-page 365
PIC18F2XK20/4XK20
26.3
PIC18F2XK20/4XK20
Param
No.
Device Characteristics
Supply Current (IDD)(1, 2)
D008
Max Units
Conditions
-40C
10
+25C
14
+85C
11
+125C
VDD = 1.8V
FOSC = 31 kHz
(RC_RUN mode,
LFINTOSC source)
11
15
-40C
12
16
+25C
16
25
+85C
26
+125C
D009
0.4
0.5
mA
-40C TO +85C
VDD = 1.8V
D009A
0.6
0.8
mA
-40C TO +85C
VDD = 3.0V
D010
2.1
2.5
mA
-40C TO +85C
VDD = 1.8V
D010A
3.7
4.4
mA
-40C TO +85C
VDD = 3.0V
D008A
Note 1:
2:
VDD = 3.0V
FOSC = 1 MHz
(RC_RUN mode,
HF-INTOSC source)
FOSC = 16 MHz
(RC_RUN mode,
HF-INTOSC source)
The supply current is mainly a function of operating voltage, frequency and mode. Other factors, such as
I/O pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption.
The test conditions for all IDD measurements in active operation mode are:
OSC1 = external square wave, from rail-to-rail; all I/O pins tri-stated, pulled to VDD;
MCLR = VDD; WDT enabled/disabled as specified.
For RC oscillator configurations, current through REXT is not included. The current through the resistor can
be estimated by the formula Ir = VDD/2REXT (mA) with REXT in k.
DS41303C-page 366
Preliminary
PIC18F2XK20/4XK20
26.4
PIC18F2XK20/4XK20
Param
No.
Device Characteristics
Typ
-40C
+25C
+85C
+125C
-40C
10
+25C
20
+85C
20
+125C
D012
300
400
-40C to +125C
VDD = 1.8V
D012A
450
600
-40C to +125C
VDD = 3.0V
D013
0.95
1.20
mA
-40C to +125C
VDD = 1.8V
D013A
1.6
2.0
mA
-40C to +125C
VDD = 3.0V
D011
D011A
Note 1:
2:
Max Units
Conditions
VDD = 1.8V
FOSC = 31 kHz
(RC_IDLE mode,
LFINTOSC source)
VDD = 3.0V
FOSC = 1 MHz
(RC_IDLE mode,
HF-INTOSC source)
FOSC = 16 MHz
(RC_IDLE mode,
HF-INTOSC source)
The supply current is mainly a function of operating voltage, frequency and mode. Other factors, such as
I/O pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption.
The test conditions for all IDD measurements in active operation mode are:
OSC1 = external square wave, from rail-to-rail; all I/O pins tri-stated, pulled to VDD;
MCLR = VDD; WDT enabled/disabled as specified.
For RC oscillator configurations, current through REXT is not included. The current through the resistor can
be estimated by the formula Ir = VDD/2REXT (mA) with REXT in k.
Preliminary
DS41303C-page 367
PIC18F2XK20/4XK20
26.5
PIC18F2XK20/4XK20
Param
No.
Device Characteristics
Typ
Max Units
0.35
0.45
mA
-40C to +85C
VDD = 1.8V
D014A
0.55
0.75
mA
-40C to +85C
VDD = 3.0V
D015
2.3
2.8
mA
-40C to +85C
VDD = 1.8V
D015A
4.1
5.0
mA
-40C to +85C
VDD = 3.0V
11.5
14.0
mA
-40C to +85C
VDD = 3.0V
D017
2.0
2.6
mA
-40C to +85C
VDD = 1.8V
D017A
3.5
4.5
mA
-40C to +85C
VDD = 3.0V
12
15
mA
-40C to +85C
VDD = 3.0V
D014
Conditions
D016
D018
Note 1:
2:
26.6
FOSC = 64 MHz
(PRI_RUN,
EC oscillator)
FOSC = 4 MHz
16 MHz Internal
(PRI_RUN HS+PLL)
FOSC = 16 MHz
64 MHz Internal
(PRI_RUN HS+PLL)
Device Characteristics
Typ
50
70
-40C to +85C
VDD = 1.8V
100
150
-40C to +85C
VDD = 3.0V
D020
0.9
1.1
mA
-40C to +85C
VDD = 1.8V
D020A
1.6
1.9
mA
-40C to +85C
VDD = 3.0V
5.0
6.0
mA
-40C to +85C
VDD = 3.0V
D019
FOSC = 20 MHz
(PRI_RUN,
EC oscillator)
The supply current is mainly a function of operating voltage, frequency and mode. Other factors, such as
I/O pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption.
The test conditions for all IDD measurements in active operation mode are:
OSC1 = external square wave, from rail-to-rail; all I/O pins tri-stated, pulled to VDD;
MCLR = VDD; WDT enabled/disabled as specified.
For RC oscillator configurations, current through REXT is not included. The current through the resistor can
be estimated by the formula Ir = VDD/2REXT (mA) with REXT in k.
PIC18F2XK20/4XK20
Param
No.
FOSC = 1 MHz
(PRI_RUN,
EC oscillator)
D019A
Max Units
Conditions
D021
FOSC = 1 MHz
(PRI_IDLE mode,
EC oscillator)
FOSC = 20 MHz
(PRI_IDLEmode,
EC oscillator)
FOSC = 64 MHz
(PRI_IDLEmode,
EC oscillator)
DS41303C-page 368
Preliminary
PIC18F2XK20/4XK20
26.7
PIC18F2XK20/4XK20
Param
No.
Device Characteristics
Supply Current (IDD)(1, 2)
D022
D022A
D023
D023A
Note 1:
2:
3:
Max Units
Conditions
-40C
10
+25C
14
+85C
11
15
-40C
12
16
+25C
16
25
+85C
-40C
+25C
+85C
-40C
10
+25C
20
+85C
VDD = 1.8V
VDD = 3.0V
VDD = 1.8V
VDD = 3.0V
FOSC = 32 kHz(3)
(SEC_RUN mode,
Timer1 as clock)
FOSC = 32 kHz(3)
(SEC_IDLE mode,
Timer1 as clock)
The supply current is mainly a function of operating voltage, frequency and mode. Other factors, such as
I/O pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption.
The test conditions for all IDD measurements in active operation mode are:
OSC1 = external square wave, from rail-to-rail; all I/O pins tri-stated, pulled to VDD;
MCLR = VDD; WDT enabled/disabled as specified.
For RC oscillator configurations, current through REXT is not included. The current through the resistor can
be estimated by the formula Ir = VDD/2REXT (mA) with REXT in k.
Low-Power mode on T1 osc.
Preliminary
DS41303C-page 369
PIC18F2XK20/4XK20
26.8
PIC18F2XK20/4XK20
Param
No.
Device Characteristics
Typ
Max Units
Conditions
D024
(IWDT)
Brown-out Reset(2)
D024A
(IBOR)
D024B
(IHLVD)
High/Low-Voltage Detect(2)
D025
(IOSCB)
Timer1 Oscillator
Timer1 Oscillator
D025A
(IOSCB)
1.5
-40C
1.5
+25C
2.0
+85C
2.0
-40C
3.0
+25C
3.0
+85C
40
-40C to +85C
VDD = 2.7V
45
-40C to +85C
VDD = 3.3V
-40C to +85C
VDD = 3.3V
TBD
-40C to +85C
VDD = 1.8V
TBD
-40C to +85C
VDD = 3.3V
-40C
+25C
+85C
-40C
+25C
+85C
-40C
+25C
+85C
-40C
+25C
+85C
TBD
-40C to +85C
VDD = 1.8V
TBD
-40C to +85C
VDD = 3.0V
VDD = 1.8V
VDD = 3.0V
VDD = 1.8V
32 kHz on Timer1(1)
VDD = 3.0V
32 kHz on Timer1(1)
VDD = 1.8V
32 kHz on Timer1(3)
VDD = 3.0V
32 kHz on Timer1(3)
D026
(IAD)
A/D Converter
D027
Comparators
TBD
-40C to +85C
VDD = 1.8V
CVREF
TBD
-40C to +85C
VDD = 1.8V
D028
VDD = 3.0V
(ICVREF)
3:
VDD = 3.0V
(ICOMP)
Legend:
Note 1:
2:
Sleep mode,
BOREN<1:0> = 10
TBD = To Be Determined.
Low-Power mode on T1 osc.
BOR and HLVD enable internal band gap reference. With both modules enabled, current consumption will be
less than the sum of both specifications.
High-Power mode in T1 osc.
DS41303C-page 370
Preliminary
PIC18F2XK20/4XK20
26.9
DC CHARACTERISTICS
Param
Symbol
No.
VIL
Characteristic
Min
Max
Units
Conditions
D030
VSS
0.15 VDD
D031
VSS
VSS
0.2 VDD
0.3 VDD
V
V
MCLR
VSS
0.2 VDD
D033
OSC1
VSS
0.3 VDD
D033A
D033B
D034
OSC1
OSC1
T13CKI
VSS
VSS
VSS
0.2 VDD
0.3 VDD
0.3 VDD
V
V
V
RC, EC modes(1)
XT, LP modes
VDD
0.8 VDD
0.7 VDD
VDD
VDD
V
V
MCLR
0.8 VDD
VDD
D043
OSC1
0.7
VDD
VDD
D043A
D043B
D043C
D044
OSC1
OSC1
OSC1
T13CKI
0.8 VDD
0.9 VDD
1.6
1.6
VDD
VDD
VDD
VDD
V
V
V
V
EC mode
RC mode(1)
XT, LP modes
D032
VIH
D040
D041
D042
IIL
D060
I/O ports
D061
MCLR
OSC1
50
400
D063
D070
Note 1:
2:
3:
4:
IPU
IPURB
In RC oscillator configuration, the OSC1/CLKIN pin is a Schmitt Trigger input. It is not recommended that
the PIC device be driven with an external clock while in RC mode.
The leakage current on the MCLR pin is strongly dependent on the applied voltage level. The specified
levels represent normal operating conditions. Higher leakage current may be measured at different input
voltages.
Negative current is defined as current sourced by the pin.
Parameter is characterized but not tested.
Preliminary
DS41303C-page 371
PIC18F2XK20/4XK20
26.9
DC CHARACTERISTICS
Param
Symbol
No.
VOL
Characteristic
Min
Max
Units
Conditions
D080
I/O ports
0.6
D083
OSC2/CLKOUT
(RC, RCIO, EC, ECIO modes)
0.6
VOH
D090
I/O ports
VDD 0.7
D092
OSC2/CLKOUT
(RC, RCIO, EC, ECIO modes)
VDD 0.7
OSC2 pin
15
pF
D101
CIO
50
pF
D102
CB
SCL, SDA
400
pF
I2C Specification
Note 1:
2:
3:
4:
In RC oscillator configuration, the OSC1/CLKIN pin is a Schmitt Trigger input. It is not recommended that
the PIC device be driven with an external clock while in RC mode.
The leakage current on the MCLR pin is strongly dependent on the applied voltage level. The specified
levels represent normal operating conditions. Higher leakage current may be measured at different input
voltages.
Negative current is defined as current sourced by the pin.
Parameter is characterized but not tested.
DS41303C-page 372
Preliminary
PIC18F2XK20/4XK20
26.10 Memory Programming Requirements
Standard Operating Conditions (unless otherwise stated)
Operating temperature -40C TA +125C
DC CHARACTERISTICS
Param
No.
Sym
Characteristic
Min
Typ
Max
Units
Conditions
VPP
D113
IDDP
VDD + 1.5
10
mA
(Note 3, Note 4)
ED
Byte Endurance
100K
E/W
D121
VDRW
1.8
3.6
D122
TDEW
ms
D123
40
Year
Provided no other
specifications are violated
D124
TREF
1M
10M
E/W
-40C to +85C
D130
EP
Cell Endurance
10K
E/W
-40C to +85C
D131
VPR
1.8
3.6
D132
VIW
1.8
3.6
D133
TIW
D134
-40C to +85C
Using EECON to
read/write
ms
40
Year
Provided no other
specifications are violated
Data in Typ column is at 3.0V, 25C unless otherwise stated. These parameters are for design guidance
only and are not tested.
Note 1: These specifications are for programming the on-chip program memory through the use of table write instructions.
2: Refer to Section 7.8 Using the Data EEPROM for a more detailed discussion on data EEPROM
endurance.
3: Required only if single-supply programming is disabled.
4:
The MPLAB ICD 2 does not support variable VPP output. Circuitry to limit the ICD 2 VPP voltage must be
placed between the ICD 2 and target system when programming or debugging with the ICD 2.
Preliminary
DS41303C-page 373
PIC18F2XK20/4XK20
TABLE 26-1:
COMPARATOR SPECIFICATIONS
Operating Conditions: 1.8V < VDD < 3.6V, -40C < TA < +125C (unless otherwise stated).
Param
No.
Sym
Characteristics
Min
Typ
Max
Units
CM01
VIOFF
7.5
15
mV
CM02
VICM
VDD
CM03
CMRR
55
dB
CM04
TRESP
Response Time
150
400
ns
CM05
TMC2OV
10
*
Note 1:
Comments
Note 1
TABLE 26-2:
Operating Conditions: 1.8V < VDD < 3.6V, -40C < TA < +125C (unless otherwise stated).
Param
No.
Sym
Characteristics
Min
Typ
Max
Units
Comments
CV01*
CLSB
Step Size(2)
VDD/24
VDD/32
V
V
CV02*
CACC
Absolute Accuracy
1/4
1/2
LSb
LSb
CV03*
CR
2k
CV04*
CST
Settling Time(1)
10
*
Note 1:
TABLE 26-3:
Operating Conditions: 1.8V < VDD < 3.6V, -40C < TA < +125C (unless otherwise stated).
VR Voltage Reference Specifications
Param
No.
Sym
Characteristics
Typ
Max
Units
TBD
1.2
TBD
VR01
VROUT
VR voltage output
VR02
TCVOUT
TBD
TBD
ppm/C
VR03
VROUT/
VDD
TBD
V/V
VR04
TSTABLE
Settling Time
TBD
TBD
Comments
DS41303C-page 374
Preliminary
PIC18F2XK20/4XK20
FIGURE 26-2:
VHLVD
(HLVDIF set by hardware)
HLVDIF
TABLE 26-4:
Characteristic
Min
Typ
Max
Units
1.8
1.9
LVV = 0010
2.0
LVV = 0011
2.1
LVV = 0100
2.2
LVV = 0101
2.3
LVV = 0110
2.4
LVV = 0111
2.5
LVV = 1000
2.6
LVV = 1001
2.7
LVV = 1010
2.8
LVV = 1011
2.9
LVV = 1100
3.0
LVV = 1101
3.3
LVV = 1110
3.5
Conditions
Production tested at TAMB = 25C. Specifications over temperature limits ensured by characterization.
Preliminary
DS41303C-page 375
PIC18F2XK20/4XK20
26.11 AC (Timing) Characteristics
26.11.1
DS41303C-page 376
3. TCC:ST
4. Ts
Time
osc
rd
rw
sc
ss
t0
t1
wr
OSC1
RD
RD or WR
SCK
SS
T0CKI
T13CKI
WR
P
R
V
Z
Period
Rise
Valid
High-impedance
High
Low
High
Low
SU
Setup
STO
Stop condition
Preliminary
PIC18F2XK20/4XK20
26.11.2
TIMING CONDITIONS
TABLE 26-5:
AC CHARACTERISTICS
FIGURE 26-3:
Load Condition 2
VDD/2
RL
CL
Pin
VSS
CL
Pin
RL = 464
VSS
CL = 50 pF
Preliminary
DS41303C-page 377
PIC18F2XK20/4XK20
26.11.3
FIGURE 26-4:
Q1
Q2
Q3
Q4
Q1
OSC1
1
CLKOUT
TABLE 26-6:
Param.
No.
1A
Symbol
FOSC
TOSC
Characteristic
Min
Max
Units
External CLKIN
Frequency(1)
DC
64
MHz
Oscillator Frequency(1)
DC
MHz
RC Oscillator mode
0.1
MHz
XT Oscillator mode
25
MHz
HS Oscillator mode
16
MHz
33
kHz
LP Oscillator mode
15.6
ns
250
ns
RC Oscillator mode
250
10,000
ns
XT Oscillator mode
40
62.5
250
250
ns
ns
HS Oscillator mode
HS + PLL Oscillator mode
30
200
LP Oscillator mode
62.5
ns
TCY = 4/FOSC
30
ns
XT Oscillator mode
2.5
LP Oscillator mode
10
ns
HS Oscillator mode
Period(1)
Time(1)
TCY
Instruction Cycle
TOSL,
TOSH
Note 1:
TOSR,
TOSF
Conditions
EC, ECIO Oscillator mode
20
ns
XT Oscillator mode
50
ns
LP Oscillator mode
7.5
ns
HS Oscillator mode
Instruction cycle period (TCY) equals four times the input oscillator time base period for all configurations
except PLL. All specified values are based on characterization data for that particular oscillator type under
standard operating conditions with the device executing code. Exceeding these specified limits may result
in an unstable oscillator operation and/or higher than expected current consumption. All devices are tested
to operate at min. values with an external clock applied to the OSC1/CLKIN pin. When an external clock
input is used, the max. cycle time limit is DC (no clock) for all devices.
DS41303C-page 378
Preliminary
PIC18F2XK20/4XK20
TABLE 26-7:
Param
No.
Sym
F10
Characteristic
Min
Typ
Max
Units
Conditions
MHz
VDD = 1.8-3.6V
16
MHz
VDD = 3.0-3.6V
16
20
MHz
VDD = 1.8-3.6V
VDD = 3.0-3.6V
F11
FSYS
16
64
MHz
F12
trc
ms
CLK
-2
+2
F13
Data in Typ column is at 3V, 25C unless otherwise stated. These parameters are for design guidance
only and are not tested.
TABLE 26-8:
PIC18F2XK20/4XK20
Param
No.
Typ
Max
Units
Conditions
HFINTOSC Accuracy @ Freq = 16 MHz, 8 MHz, 4 MHz, 2 MHz, 1 MHz, 500 kHz, 250 kHz(1)
1
+25C
VDD = 1.8-3.6V
-2
+2
0C to +85C
VDD = 1.8-3.6V
-5
+5
-40C to +125C
VDD = 1.8-3.6V
35.938
kHz
-40C to +125C
VDD = 1.8-3.6V
Preliminary
DS41303C-page 379
PIC18F2XK20/4XK20
FIGURE 26-5:
Q4
Q2
Q3
OSC1
11
10
CLKOUT
13
19
14
12
18
16
I/O pin
(Input)
15
17
I/O pin
(Output)
Note:
20, 21
Refer to Figure 26-3 for load conditions.
TABLE 26-9:
Param
No.
New Value
Old Value
Symbol
Characteristic
Min
Typ
Max
Units Conditions
10
75
200
ns
(Note 1)
11
75
200
ns
(Note 1)
12
TckR
35
100
ns
(Note 1)
13
TckF
35
100
ns
(Note 1)
0.5 TCY + 20
ns
(Note 1)
0.25 TCY + 25
ns
(Note 1)
(Note 1)
14
TckL2ioV
15
16
TckH2ioI
17
ns
50
150
ns
18
TosH2ioI
100
ns
19
ns
20
TioR
10
25
ns
21
TioF
10
25
ns
22
TINP
20
ns
23
TRBP
TCY
ns
These parameters are asynchronous events not related to any internal clock edges.
Note 1: Measurements are taken in RC mode, where CLKOUT output is 4 x TOSC.
DS41303C-page 380
Preliminary
PIC18F2XK20/4XK20
FIGURE 26-6:
VDD
MCLR
30
Internal
POR
33
PWRT
Time-out
32
OSC
Time-out
Internal
Reset
Watchdog
Timer
Reset
31
34
34
I/O pins
Note:
FIGURE 26-7:
VDD
35
VBGAP = 1.2V
VIVRST
Enable Internal
Reference Voltage
Internal Reference
Voltage Stable
36
TABLE 26-10: RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER, POWER-UP TIMER
AND BROWN-OUT RESET REQUIREMENTS
Param.
Symbol
No.
30
31
TmcL
TWDT
32
33
TOST
TPWRT
Characteristic
MCLR Pulse Width (low)
Watchdog Timer Time-out Period
(no postscaler)
Oscillation Start-up Timer Period
Power-up Timer Period
TIOZ
Min
Typ
Max
Units
4.00
TBD
s
ms
65.5
TBD
ms
Conditions
200
20
50
s
s
200
5
10
s
s
ms
VDD VHLVD
Preliminary
DS41303C-page 381
PIC18F2XK20/4XK20
FIGURE 26-8:
41
40
42
T1OSO/T13CKI
46
45
47
48
TMR0 or
TMR1
Note:
Symbol
Characteristic
40
Tt0H
41
Tt0L
42
Tt0P
T0CKI Period
No prescaler
With prescaler
No prescaler
With prescaler
No prescaler
With prescaler
45
46
Tt1H
Tt1L
Tt1P
Ft1
0.5 TCY + 20
ns
10
ns
0.5 TCY + 20
ns
10
ns
TCY + 10
ns
Greater of:
20 ns or
(TCY + 40)/N
ns
ns
10
ns
Asynchronous
30
ns
0.5 TCY + 5
ns
10
ns
T13CKI
Synchronous
Input Period
DS41303C-page 382
Units Conditions
0.5 TCY + 20
Synchronous, no prescaler
Asynchronous
48
Max
Synchronous,
with prescaler
T13CKI
High Time
Asynchronous
47
Min
Preliminary
30
ns
Greater of:
20 ns or
(TCY + 40)/N
ns
60
ns
DC
50
kHz
2 TOSC
7 TOSC
N = prescale
value
(1, 2, 4,..., 256)
N = prescale
value (1, 2, 4, 8)
PIC18F2XK20/4XK20
FIGURE 26-9:
50
51
52
CCPx
(Compare or PWM Mode)
54
53
Note:
51
TccL
TccH
Characteristic
Min
Max
Units
0.5 TCY + 20
ns
10
ns
CCPx Input
High Time
0.5 TCY + 20
ns
10
ns
3 TCY + 40
N
ns
No prescaler
With
prescaler
52
TccP
53
TccR
25
ns
54
TccF
25
ns
Preliminary
Conditions
N = prescale
value (1, 4 or 16)
DS41303C-page 383
PIC18F2XK20/4XK20
FIGURE 26-10:
RE2/CS
RE0/RD
RE1/WR
65
RD7:RD0
62
64
63
Note:
Symbol
Characteristic
Min
Max
Units
62
TdtV2wrH
20
ns
63
TwrH2dtI
20
ns
64
TrdL2dtV
80
ns
65
TrdH2dtI
RD or CS to DataOut Invalid
10
30
ns
66
TibfINH
3 TCY
DS41303C-page 384
Preliminary
Conditions
PIC18F2XK20/4XK20
FIGURE 26-11:
SS
70
SCK
(CKP = 0)
71
72
78
79
79
78
SCK
(CKP = 1)
80
bit 6 - - - - - -1
MSb
SDO
LSb
75, 76
SDI
MSb In
bit 6 - - - -1
LSb In
74
73
Note:
Symbol
Characteristic
Min
Max Units
70
TssL2scH,
TssL2scL
71
TscH
Continuous
1.25 TCY + 30
ns
Single Byte
40
ns
Continuous
1.25 TCY + 30
ns
Single Byte
40
ns
100
ns
1.5 TCY + 40
ns
100
ns
71A
72
TscL
72A
TCY
ns
73
TdiV2scH,
TdiV2scL
73A
Tb2b
74
TscH2diL,
TscL2diL
75
TdoR
25
ns
76
TdoF
25
ns
78
TscR
25
ns
79
TscF
25
ns
80
TscH2doV,
TscL2doV
50
ns
Note 1:
2:
Conditions
(Note 1)
(Note 1)
(Note 2)
Preliminary
DS41303C-page 385
PIC18F2XK20/4XK20
FIGURE 26-12:
SS
81
SCK
(CKP = 0)
71
72
79
73
SCK
(CKP = 1)
80
78
MSb
SDO
bit 6 - - - - - -1
LSb
bit 6 - - - -1
LSb In
75, 76
SDI
MSb In
74
Note:
Symbol
Characteristic
TscH
TscL
73
TdiV2scH,
TdiV2scL
73A
Tb2b
74
TscH2diL,
TscL2diL
75
TdoR
71A
72
72A
Continuous
Min
Max Units
1.25 TCY + 30
ns
Single Byte
40
ns
Continuous
1.25 TCY + 30
ns
Single Byte
40
ns
100
ns
1.5 TCY + 40
ns
100
ns
25
ns
76
TdoF
25
ns
78
TscR
25
ns
79
TscF
25
ns
80
TscH2doV,
TscL2doV
50
ns
81
TdoV2scH,
TdoV2scL
TCY
ns
Note 1:
2:
Conditions
(Note 1)
(Note 1)
(Note 2)
DS41303C-page 386
Preliminary
PIC18F2XK20/4XK20
FIGURE 26-13:
SS
70
SCK
(CKP = 0)
83
71
72
78
79
79
78
SCK
(CKP = 1)
80
MSb
SDO
bit 6 - - - - - -1
LSb
77
75, 76
MSb In
SDI
73
Note:
bit 6 - - - -1
LSb In
74
TABLE 26-16: EXAMPLE SPI MODE REQUIREMENTS (SLAVE MODE TIMING, CKE = 0)
Param
No.
Symbol
Characteristic
70
71
TscH
71A
72
TscL
72A
Min
TCY
ns
Continuous
1.25 TCY + 30
ns
Single Byte
40
ns
Continuous
1.25 TCY + 30
ns
Single Byte
40
ns
100
ns
73
73A
Tb2b
74
Last Clock Edge of Byte 1 to the First Clock Edge of Byte 2 1.5 TCY + 40
ns
100
ns
75
TdoR
25
ns
76
TdoF
25
ns
77
10
50
ns
78
TscR
25
ns
79
TscF
80
83
Note 1:
2:
25
ns
50
ns
1.5 TCY + 40
ns
(Note 1)
(Note 1)
(Note 2)
Preliminary
DS41303C-page 387
PIC18F2XK20/4XK20
FIGURE 26-14:
SS
SCK
(CKP = 0)
70
83
71
72
SCK
(CKP = 1)
80
MSb
SDO
bit 6 - - - - - -1
LSb
75, 76
SDI
MSb In
Note:
77
bit 6 - - - -1
LSb In
74
Refer to Figure 26-3 for load conditions.
Symbol
Characteristic
Min
70
71
TscH
TscL
73A
Tb2b
Last Clock Edge of Byte 1 to the First Clock Edge of Byte 2 1.5 TCY + 40
74
75
TdoR
76
TdoF
25
ns
77
10
50
ns
78
TscR
25
ns
79
TscF
25
ns
80
50
ns
82
50
ns
83
1.5 TCY + 40
ns
71A
72
72A
Note 1:
2:
Continuous
TCY
ns
1.25 TCY + 30
ns
Single Byte
40
ns
Continuous
1.25 TCY + 30
ns
(Note 1)
Single Byte
40
ns
(Note 1)
ns
(Note 2)
100
ns
25
ns
DS41303C-page 388
Preliminary
PIC18F2XK20/4XK20
I2C BUS START/STOP BITS TIMING
FIGURE 26-15:
SCL
91
93
90
92
SDA
Stop
Condition
Start
Condition
Note:
Characteristic
90
TSU:STA
Start Condition
91
THD:STA
92
TSU:STO
93
Max
Units
Conditions
4700
ns
ns
Setup Time
600
Start Condition
4000
Hold Time
600
Stop Condition
4700
Setup Time
Hold Time
FIGURE 26-16:
Min
600
4000
600
ns
ns
102
100
101
SCL
90
106
107
91
92
SDA
In
110
109
109
SDA
Out
Note:
Preliminary
DS41303C-page 389
PIC18F2XK20/4XK20
TABLE 26-19: I2C BUS DATA REQUIREMENTS (SLAVE MODE)
Param.
Symbol
No.
100
THIGH
Characteristic
Clock High Time
Min
Max
Units
4.0
0.6
1.5 TCY
4.7
1.3
SSP Module
101
TLOW
1.5 TCY
1000
ns
20 + 0.1 CB
300
ns
300
ns
20 + 0.1 CB
300
ns
CB is specified to be from
10 to 400 pF
4.7
0.6
4.0
0.6
ns
0.9
250
ns
100
ns
4.7
0.6
SSP Module
102
TR
103
TF
90
91
106
107
92
109
TAA
110
TBUF
D102
CB
Note 1:
2:
Conditions
3500
ns
ns
4.7
1.3
400
pF
CB is specified to be from
10 to 400 pF
(Note 2)
(Note 1)
Time the bus must be free
before a new transmission
can start
As a transmitter, the device must provide this internal minimum delay time to bridge the undefined region
(min. 300 ns) of the falling edge of SCL to avoid unintended generation of Start or Stop conditions.
A fast mode I2C bus device can be used in a standard mode I2C bus system but the requirement,
TSU:DAT 250 ns, must then be met. This will automatically be the case if the device does not stretch the
LOW period of the SCL signal. If such a device does stretch the LOW period of the SCL signal, it must
output the next data bit to the SDA line, TR max. + TSU:DAT = 1000 + 250 = 1250 ns (according to the
standard mode I2C bus specification), before the SCL line is released.
DS41303C-page 390
Preliminary
PIC18F2XK20/4XK20
FIGURE 26-17:
SCL
93
91
90
92
SDA
Stop
Condition
Start
Condition
Note:
TSU:STA
Characteristic
Start Condition
Setup Time
91
92
93
Min
Max
Units
2(TOSC)(BRG + 1)
ns
ns
2(TOSC)(BRG + 1)
1 MHz mode(1)
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
1 MHz mode(1)
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
1 MHz mode(1)
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
1 MHz mode(1)
2(TOSC)(BRG + 1)
Conditions
ns
ns
FIGURE 26-18:
102
100
101
SCL
90
106
91
107
92
SDA
In
109
109
110
SDA
Out
Note:
Preliminary
DS41303C-page 391
PIC18F2XK20/4XK20
TABLE 26-21: MASTER SSP I2C BUS DATA REQUIREMENTS
Param.
Symbol
No.
100
THIGH
Characteristic
Min
Max
Units
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG
+ 1)
ms
mode(1)
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG + 1)
ms
mode(1)
ms
101
TLOW
1 MHz
102
103
90
91
TR
TF
TSU:STA
2(TOSC)(BRG + 1)
1000
ns
20 + 0.1 CB
300
ns
1 MHz mode(1)
300
ns
300
ns
20 + 0.1 CB
300
ns
1 MHz mode(1)
100
ns
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG
+ 1)
ms
1 MHz mode(1)
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG + 1)
ms
1 MHz mode(1)
2(TOSC)(BRG + 1)
ms
ns
106
0.9
ms
107
TSU:DAT
250
ns
92
109
TAA
Data Input
Setup Time
Output Valid
from Clock
100
ns
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG + 1)
ms
1 MHz mode(1)
2(TOSC)(BRG + 1)
ms
3500
ns
ns
1000
mode(1)
ns
4.7
ms
1.3
ms
400
pF
1 MHz
110
D102
Note 1:
2:
TBUF
CB
Conditions
CB is specified to be from
10 to 400 pF
CB is specified to be from
10 to 400 pF
Only relevant for
Repeated Start
condition
After this period, the first
clock pulse is generated
(Note 2)
I2C
DS41303C-page 392
Preliminary
PIC18F2XK20/4XK20
FIGURE 26-19:
RC6/TX/CK
pin
121
121
RC7/RX/DT
pin
120
Note:
122
Symbol
Characteristic
Min
Max
Units
120
40
ns
121
Tckrf
20
ns
122
Tdtrf
20
ns
FIGURE 26-20:
Conditions
RC6/TX/CK
pin
125
RC7/RX/DT
pin
126
Note:
Symbol
Characteristic
Min
Max
Units
125
TdtV2ckl
10
ns
126
TckL2dtl
15
ns
Preliminary
Conditions
DS41303C-page 393
PIC18F2XK20/4XK20
TABLE 26-24: A/D CONVERTER CHARACTERISTICS: PIC18F2XK20/4XK20
Param
Symbol
No.
Characteristic
Min
Typ
Max
Units
10
bit
Conditions
VREF 3.0V
A01
NR
Resolution
A03
EIL
<1
A04
EDL
<1
A06
EOFF
Offset Error
<3
A07
EGN
Gain Error
<3
A10
Monotonicity
A20
VREF
A21
VREFH
A22
1.8
3
V
V
VDD/2
VDD + 0.6
VREFL
VSS 0.3V
VDD 3.0V
Guaranteed(1)
A25
VAIN
VREFL
VREFH
A30
ZAIN
Recommended Impedance of
Analog Voltage Source
2.5
A50
IREF
5
150
A
A
Note 1:
2:
The A/D conversion result never decreases with an increase in the input voltage and has no missing
codes.
VREFH current is from RA3/AN3/VREF+ pin or VDD, whichever is selected as the VREFH source.
VREFL current is from RA2/AN2/VREF-/CVREF pin or VSS, whichever is selected as the VREFL source.
DS41303C-page 394
Preliminary
PIC18F2XK20/4XK20
FIGURE 26-21:
BSF ADCON0, GO
(Note 2)
131
Q4
130
132
A/D CLK
A/D DATA
.. .
...
NEW_DATA
OLD_DATA
ADRES
TCY
ADIF
GO
DONE
SAMPLING STOPPED
SAMPLE
Note
1:
If the A/D clock source is selected as RC, a time of TCY is added before the A/D clock starts.
This allows the SLEEP instruction to be executed.
2:
This is a minimal RC delay (typically 100 ns), which also disconnects the holding capacitor from the analog input.
TAD
Characteristic
A/D Clock Period
Min
Max
Units
0.7
25.0(1)
TBD
A/D RC mode
11
12
TAD
1.4
TBD
s
s
131
TCNV
Conversion Time
(not including acquisition time) (Note 2)
132
TACQ
135
TSWC
(Note 4)
TBD
TDIS
Discharge Time
0.2
Legend:
Note 1:
2:
3:
4:
Conditions
-40C to +85C
0C to +85C
TBD = To Be Determined
The time of the A/D clock period is dependent on the device frequency and the TAD clock divider.
ADRES register may be read on the following TCY cycle.
The time for the holding capacitor to acquire the New input voltage when the voltage changes full scale
after the conversion (VDD to VSS or VSS to VDD). The source impedance (RS) on the input channels is 50
.
On the following cycle of the device clock.
Preliminary
DS41303C-page 395
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 396
Preliminary
PIC18F2XK20/4XK20
27.0
DC AND AC
CHARACTERISTICS GRAPHS
AND TABLES
Preliminary
DS41303C-page 397
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 398
Preliminary
PIC18F2XK20/4XK20
28.0
PACKAGING INFORMATION
28.1
Example
PIC18F25K20-E/SP
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX
YYWWNNN
e3
0610017
Example
PIC18F25K20-E/SO e3
0610017
XXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX
YYWWNNN
40-Lead PDIP
Example
XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX
YYWWNNN
Legend: XX...X
Y
YY
WW
NNN
e3
*
Note:
PIC18F45K20-E/P e3
0610017
Customer-specific information
Year code (last digit of calendar year)
Year code (last 2 digits of calendar year)
Week code (week of January 1 is week 01)
Alphanumeric traceability code
Pb-free JEDEC designator for Matte Tin (Sn)
This package is Pb-free. The Pb-free JEDEC designator ( e3 )
can be found on the outer packaging for this package.
In the event the full Microchip part number cannot be marked on one line, it will
be carried over to the next line, thus limiting the number of available
characters for customer-specific information.
Preliminary
DS41303C-page 399
PIC18F2XK20/4XK20
Package Marking Information (Continued)
28-Lead SSOP
Example
XXXXXXXXXXXXXXX
XXXXXXXXXXXXXXX
XXXXXXXXXXXXXXX
YYWWNNN
PIC18F25K20-E/SS
e3
0610017
28-Lead QFN
Example
XXXXXXXX
XXXXXXXX
YYWWNNN
18F24K20
-E/ML e3
0610017
44-Lead QFN
Example
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
YYWWNNN
PIC18F45K20
-E/ML e3
0610017
44-Lead TQFP
Example
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
YYWWNNN
DS41303C-page 400
PIC18F44K20
-E/PT e3
0610017
Preliminary
PIC18F2XK20/4XK20
28.2
Package Details
28-Lead Skinny Plastic Dual In-Line (SP) 300 mil Body [SPDIP]
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
N
NOTE 1
E1
3
D
E
A2
b1
A1
eB
Units
Dimension Limits
Number of Pins
INCHES
MIN
NOM
MAX
28
Pitch
.200
A2
.120
.135
.150
A1
.015
.290
.310
.335
E1
.240
.285
.295
Overall Length
1.345
1.365
1.400
.110
.130
.150
Lead Thickness
.008
.010
.015
b1
.040
.050
.070
.014
.018
.022
eB
.100 BSC
.430
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Significant Characteristic.
3. Dimensions D and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed .010" per side.
4. Dimensioning and tolerancing per ASME Y14.5M.
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
Microchip Technology Drawing C04-070B
Preliminary
DS41303C-page 401
PIC18F2XK20/4XK20
28-Lead Plastic Small Outline (SO) Wide, 7.50 mm Body [SOIC]
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
D
N
E
E1
NOTE 1
1 2 3
b
h
c
A2
L
A1
Units
Dimension Limits
Number of Pins
L1
MILLIMETERS
MIN
NOM
MAX
28
Pitch
Overall Height
1.27 BSC
A2
2.05
Standoff
A1
0.10
0.30
Overall Width
E1
7.50 BSC
Overall Length
17.90 BSC
2.65
10.30 BSC
Chamfer (optional)
0.25
0.75
Foot Length
0.40
1.27
Footprint
L1
1.40 REF
Lead Thickness
0.18
0.33
Lead Width
0.31
0.51
15
15
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Significant Characteristic.
3. Dimensions D and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed 0.15 mm per side.
4. Dimensioning and tolerancing per ASME Y14.5M.
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
Microchip Technology Drawing C04-052B
DS41303C-page 402
Preliminary
PIC18F2XK20/4XK20
40-Lead Plastic Dual In-Line (P) 600 mil Body [PDIP]
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
N
NOTE 1
E1
1 2 3
D
E
A2
b1
A1
eB
Units
Dimension Limits
Number of Pins
INCHES
MIN
NOM
MAX
40
Pitch
.250
A2
.125
.195
A1
.015
.590
.625
E1
.485
.580
Overall Length
1.980
2.095
.115
.200
Lead Thickness
.008
.015
b1
.030
.070
.014
.023
eB
.100 BSC
.700
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Significant Characteristic.
3. Dimensions D and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed .010" per side.
4. Dimensioning and tolerancing per ASME Y14.5M.
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
Microchip Technology Drawing C04-016B
Preliminary
DS41303C-page 403
PIC18F2XK20/4XK20
28-Lead Plastic Shrink Small Outline (SS) 5.30 mm Body [SSOP]
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
D
N
E
E1
1 2
NOTE 1
b
e
c
A2
A1
L1
Units
Dimension Limits
Number of Pins
MILLIMETERS
MIN
NOM
MAX
28
Pitch
Overall Height
0.65 BSC
2.00
A2
1.65
1.75
1.85
Standoff
A1
0.05
Overall Width
7.40
7.80
8.20
E1
5.00
5.30
5.60
Overall Length
9.90
10.20
10.50
Foot Length
0.55
0.75
0.95
Footprint
L1
1.25 REF
Lead Thickness
0.09
Foot Angle
0.25
8
Lead Width
0.22
0.38
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Dimensions D and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed 0.20 mm per side.
3. Dimensioning and tolerancing per ASME Y14.5M.
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
Microchip Technology Drawing C04-073B
DS41303C-page 404
Preliminary
PIC18F2XK20/4XK20
28-Lead Plastic Quad Flat, No Lead Package (ML) 6x6 mm Body [QFN]
with 0.55 mm Contact Length
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
D
D2
EXPOSED
PAD
e
E
E2
2
N
NOTE 1
L
BOTTOM VIEW
TOP VIEW
A3
A1
Units
Dimension Limits
Number of Pins
MILLIMETERS
MIN
NOM
MAX
28
Pitch
Overall Height
0.80
0.65 BSC
0.90
1.00
Standoff
A1
0.00
0.02
0.05
Contact Thickness
A3
0.20 REF
Overall Width
E2
Overall Length
D2
3.65
3.70
4.20
0.23
0.30
0.35
Contact Length
0.50
0.55
0.70
Contact-to-Exposed Pad
0.20
Contact Width
6.00 BSC
3.65
3.70
4.20
6.00 BSC
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Package is saw singulated.
3. Dimensioning and tolerancing per ASME Y14.5M.
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
Microchip Technology Drawing C04-105B
Preliminary
DS41303C-page 405
PIC18F2XK20/4XK20
44-Lead Plastic Quad Flat, No Lead Package (ML) 8x8 mm Body [QFN]
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
D
D2
EXPOSED
PAD
e
E
E2
b
2
2
1
N
1
N
NOTE 1
TOP VIEW
L
BOTTOM VIEW
A
A3
A1
Units
Dimension Limits
Number of Pins
MILLIMETERS
MIN
NOM
MAX
44
Pitch
Overall Height
0.80
0.65 BSC
0.90
1.00
Standoff
A1
0.00
0.02
0.05
Contact Thickness
A3
0.20 REF
Overall Width
E2
Overall Length
D2
6.30
6.45
6.80
0.25
0.30
0.38
Contact Length
0.30
0.40
0.50
Contact-to-Exposed Pad
0.20
Contact Width
8.00 BSC
6.30
6.45
6.80
8.00 BSC
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Package is saw singulated.
3. Dimensioning and tolerancing per ASME Y14.5M.
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
Microchip Technology Drawing C04-103B
DS41303C-page 406
Preliminary
PIC18F2XK20/4XK20
44-Lead Plastic Thin Quad Flatpack (PT) 10x10x1 mm Body, 2.00 mm Footprint [TQFP]
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
D
D1
E
e
E1
NOTE 1
1 2 3
NOTE 2
A1
Units
Dimension Limits
Number of Leads
A2
L1
MILLIMETERS
MIN
NOM
MAX
44
Lead Pitch
Overall Height
0.80 BSC
A2
0.95
1.00
1.05
Standoff
A1
0.05
0.15
Foot Length
0.45
0.60
0.75
Footprint
L1
1.20
1.00 REF
Foot Angle
Overall Width
12.00 BSC
Overall Length
12.00 BSC
E1
10.00 BSC
D1
10.00 BSC
3.5
Lead Thickness
0.09
0.20
Lead Width
0.30
0.37
0.45
11
12
13
11
12
13
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Chamfers at corners are optional; size may vary.
3. Dimensions D1 and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed 0.25 mm per side.
4. Dimensioning and tolerancing per ASME Y14.5M.
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
Microchip Technology Drawing C04-076B
Preliminary
DS41303C-page 407
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 408
Preliminary
PIC18F2XK20/4XK20
APPENDIX A:
REVISION HISTORY
APPENDIX B:
DEVICE
DIFFERENCES
Revision B (03/2007)
Added
part
numbers
PIC18F26K20
and
PIC18F46K20; Replaced Development Support
Section; Replaced Package Drawings.
Revision C (10/2007)
Revised Table 1, DIL Pins 34 and 35; Table 2, Pins 22
and 24; Table 1-2, Pins RB1 and RB3; Table 1-3, Pins
RB1 and RB3; Revised Sections 4.3, 4.4, 4.4.1, 4.4.2,
4.4.4; Revised Table 4-3, Note 2; Revised Table 6-1;
Revise Section 7.8: Revised Section 9.2; Revised
Examples 10-1 and 10-2; Revised Table 10-3, Pins
RB1 and RB3; Revised Sections 12.2 through 12.5;
Revised Register 16-1, bit 3-0; Revised Sections 16.1,
16.2, 16.4.4; Revised Register 16-2, bit 6-4; Revised
Table 16-2, Note 2; Revised Register 17-1, bit 6;
Revised Register 17-3; Revised Table 17-4; Revised
Register 19-1, added Note 2; Revised Register 20-3,
bits 5 and 4; Revised Register 23-4, bit 1; Revised Register 23-12, bit 7-5; Revised Section 23.3; Revised Section 24.1.1, instruction set descriptions; Revised
Section 26.0, voltage on MCLR; Revised DC Characteristics 26.2, 26.3, 26.4 26.5, 26.6, 26.7, 26.8 and
26.10; Revised Tables 26-1, 26-6, 26-7, 26-9, 26-23.
TABLE B-1:
DEVICE DIFFERENCES
Features
Program Memory
(Bytes)
8192
16384
32768
65536
8192
16384
32768
65536
Program Memory
(Instructions)
4096
8192
16384
32768
4096
8192
16384
32768
19
19
19
19
20
20
20
20
Interrupt Sources
I/O Ports
Capture/Compare/PWM
Modules
Enhanced
Capture/Compare/PWM
Modules
Parallel
Communications (PSP)
No
No
No
No
Yes
Yes
Yes
Yes
10-bit Analog-to-Digital
Module
11 input
channels
11 input
channels
11 input
channels
11 input
channels
14 input
channels
14 input
channels
14 input
channels
14 input
channels
28-pin PDIP
28-pin SOIC
28-pin SSOP
28-pin QFN
28-pin PDIP
28-pin SOIC
28-pin SSOP
28-pin QFN
28-pin PDIP
28-pin SOIC
28-pin SSOP
28-pin QFN
28-pin PDIP
28-pin SOIC
28-pin SSOP
28-pin QFN
40-pin PDIP
44-pin TQFP
44-pin QFN
40-pin PDIP
44-pin TQFP
44-pin QFN
40-pin PDIP
44-pin TQFP
44-pin QFN
40-pin PDIP
44-pin TQFP
44-pin QFN
Packages
Preliminary
DS41303C-page 409
PIC18F2XK20/4XK20
NOTES:
DS41303C-page 410
Preliminary
PIC18F2XK20/4XK20
INDEX
A
A/D
Preliminary
DS41303C-page 411
PIC18F2XK20/4XK20
Detecting .................................................................... 52
Disabling in Sleep Mode ............................................ 52
Minimun Enable Time ................................................ 52
Software Enabled ....................................................... 52
BSF .................................................................................. 321
BTFSC ............................................................................. 322
BTFSS .............................................................................. 322
BTG .................................................................................. 323
BZ ..................................................................................... 324
C
C Compilers
MPLAB C18 ............................................................. 360
MPLAB C30 ............................................................. 360
CALL ................................................................................ 324
CALLW ............................................................................. 353
Capture (CCP Module) ..................................................... 141
Associated Registers ............................................... 144
CCP Pin Configuration ............................................. 141
CCPRxH:CCPRxL Registers ................................... 141
Prescaler .................................................................. 141
Software Interrupt .................................................... 141
Timer1/Timer3 Mode Selection ................................ 141
Capture (ECCP Module) .................................................. 170
Capture/Compare/PWM (CCP) ........................................ 139
Capture Mode. See Capture.
CCP Mode and Timer Resources ............................ 140
CCPRxH Register .................................................... 140
CCPRxL Register ..................................................... 140
Compare Mode. See Compare.
Interaction of Two CCP Modules ............................. 140
Module Configuration ............................................... 140
PWM Mode .............................................................. 145
Duty Cycle ........................................................ 146
Effects of Reset ................................................ 148
Example PWM Frequencies & Resolutions
Fosc=20 MHZ .......................................... 147
Fosc=40 MHZ .......................................... 147
Fosc=8 MHZ ............................................ 147
Operation in Sleep Mode ................................. 148
Setup for Operation .......................................... 148
System Clock Frequency Changes .................. 148
PWM Period ............................................................. 146
Setup for PWM Operation ........................................ 148
CCP1CON Register ......................................................... 169
CCP2CON Register ......................................................... 139
Clock Accuracy with Asynchronous Operation ................ 240
Clock Sources
Associated registers ................................................... 39
External Modes .......................................................... 28
EC ...................................................................... 28
HS ...................................................................... 29
LP ....................................................................... 29
OST .................................................................... 28
RC ...................................................................... 30
XT ...................................................................... 29
Internal Modes ........................................................... 30
Frequency Selection .......................................... 32
HFINTOSC ......................................................... 30
INTOSC ............................................................. 30
INTOSCIO .......................................................... 30
LFINTOSC ......................................................... 32
Selecting the 31 kHz Source ...................................... 26
Selection Using OSCCON Register ........................... 26
Clock Switching .................................................................. 35
CLRF ................................................................................ 325
DS41303C-page 412
Preliminary
PIC18F2XK20/4XK20
CONFIG6L Register ......................................................... 299
CONFIG7H Register ........................................................ 300
CONFIG7L Register ......................................................... 300
Configuration Bits ............................................................. 294
Configuration Register Protection .................................... 307
Context Saving During Interrupts ..................................... 117
CPFSEQ .......................................................................... 326
CPFSGT .......................................................................... 327
CPFSLT ........................................................................... 327
Customer Change Notification Service ............................ 421
Customer Notification Service .......................................... 421
Customer Support ............................................................ 421
CVREF Voltage Reference Specifications ........................ 374
D
Data Addressing Modes ..................................................... 81
Comparing Addressing Modes with the
Extended Instruction Set Enabled ..................... 84
Direct .......................................................................... 81
Indexed Literal Offset ................................................. 83
Instructions Affected .......................................... 83
Indirect ....................................................................... 81
Inherent and Literal .................................................... 81
Data EEPROM
Code Protection ....................................................... 307
Data EEPROM Memory ..................................................... 97
Associated Registers ............................................... 101
EEADR and EEADRH Registers ............................... 97
EECON1 and EECON2 Registers ............................. 97
Operation During Code-Protect ............................... 100
Protection Against Spurious Write ........................... 100
Reading ...................................................................... 99
Using ........................................................................ 100
Write Verify ................................................................ 99
Writing ........................................................................ 99
Data Memory ..................................................................... 69
Access Bank .............................................................. 75
and the Extended Instruction Set ............................... 83
Bank Select Register (BSR) ....................................... 69
General Purpose Registers ........................................ 75
Map for PIC18F23K20/43K20 .................................... 70
Map for PIC18F24K20/44K20 .................................... 71
Map for PIC18F25K20/45K20 .............................. 72, 73
Special Function Registers ........................................ 75
DAW ................................................................................. 328
DC and AC Characteristics
Graphs and Tables .................................................. 397
DC Characteristics
Input/Output ............................................................. 371
Peripheral Supply Current ........................................ 370
Power-Down Current ............................................... 365
Primary Idle Supply Current ..................................... 368
Primary Run Supply Current .................................... 368
RC Idle Supply Current ............................................ 367
RC Run Supply Current ........................................... 366
Secondary Oscillator Supply Current ....................... 369
Supply Voltage ......................................................... 365
DCFSNZ .......................................................................... 329
DECF ............................................................................... 328
DECFSZ ........................................................................... 329
Development Support ...................................................... 359
Device Differences ........................................................... 409
Device Overview .................................................................. 9
Details on Individual Family Members ....................... 10
Features (table) .......................................................... 11
New Core Features ...................................................... 9
E
ECCP1AS Register .......................................................... 179
EECON1 Register ........................................................ 89, 98
Effect on Standard PIC Instructions ................................. 356
Effects of Power Managed Modes on Various
Clock Sources ........................................................... 34
Effects of Reset
PWM mode .............................................................. 148
Electrical Characteristics ................................................. 363
Enhanced Capture/Compare/PWM (ECCP) .................... 169
Associated Registers ............................................... 187
Capture and Compare Modes ................................. 170
Capture Mode. See Capture (ECCP Module).
Enhanced PWM Mode ............................................. 171
Auto-Restart .................................................... 180
Auto-shutdown ................................................ 179
Direction Change in Full-Bridge Output Mode . 177
Full-Bridge Application ..................................... 175
Full-Bridge Mode ............................................. 175
Half-Bridge Application .................................... 174
Half-Bridge Application Examples ................... 181
Half-Bridge Mode ............................................. 174
Output Relationships (Active-High and
Active-Low) .............................................. 172
Output Relationships Diagram ......................... 173
Programmable Dead Band Delay .................... 181
Shoot-through Current ..................................... 181
Start-up Considerations ................................... 178
Outputs and Configuration ....................................... 170
Standard PWM Mode .............................................. 170
Timer Resources ..................................................... 170
Enhanced Universal Synchronous Asynchronous
Receiver Transmitter (EUSART) ............................ 231
Errata ................................................................................... 8
EUSART .......................................................................... 231
Asynchronous Mode ................................................ 233
12-bit Break Transmit and Receive ................. 249
Associated Registers, Receive ........................ 239
Associated Registers, Transmit ....................... 235
Auto-Wake-up on Break .................................. 248
Baud Rate Generator (BRG) ........................... 243
Clock Accuracy ................................................ 240
Receiver .......................................................... 236
Setting up 9-bit Mode with Address Detect ..... 238
Transmitter ...................................................... 233
Baud Rate Generator (BRG)
Associated Registers ....................................... 243
Auto Baud Rate Detect .................................... 247
Baud Rate Error, Calculating ........................... 243
Baud Rates, Asynchronous Modes ................. 244
Formulas .......................................................... 243
High Baud Rate Select (BRGH Bit) ................. 243
Clock polarity
Synchronous Mode .......................................... 251
Data polarity
Asychronous Receive ...................................... 236
Asychronous Transmit ..................................... 233
Preliminary
DS41303C-page 413
PIC18F2XK20/4XK20
Synchronous Mode .......................................... 251
Interrupts
Asychronous Receive ...................................... 237
Asychronous Transmit ..................................... 233
Synchronous Master Mode .............................. 251, 256
Associated Registers, Receive ........................ 255
Associated Registers, Transmit ............... 253, 256
Reception ......................................................... 254
Transmission .................................................... 251
Synchronous Slave Mode
Associated Registers, Receive ........................ 257
Reception ......................................................... 257
Transmission .................................................... 256
Extended Instruction Set
ADDFSR .................................................................. 352
ADDULNK ................................................................ 352
and Using MPLAB Tools .......................................... 358
CALLW ..................................................................... 353
Considerations for Use ............................................ 356
MOVSF .................................................................... 353
MOVSS .................................................................... 354
PUSHL ..................................................................... 354
SUBFSR .................................................................. 355
SUBULNK ................................................................ 355
Syntax ...................................................................... 351
F
Fail-Safe Clock Monitor .............................................. 38, 293
Fail-Safe Condition Clearing ...................................... 38
Fail-Safe Detection .................................................... 38
Fail-Safe Operation .................................................... 38
Reset or Wake-up from Sleep .................................... 38
Fast Register Stack ............................................................ 66
Firmware Instructions ....................................................... 309
Flash Program Memory ...................................................... 87
Associated Registers ................................................. 95
Control Registers ....................................................... 88
EECON1 and EECON2 ..................................... 88
TABLAT (Table Latch) Register ......................... 90
TBLPTR (Table Pointer) Register ...................... 90
Erase Sequence ........................................................ 92
Erasing ....................................................................... 92
Operation During Code-Protect ................................. 95
Reading ...................................................................... 91
Table Pointer
Boundaries Based on Operation ........................ 90
Table Pointer Boundaries .......................................... 90
Table Reads and Table Writes .................................. 87
Write Sequence ......................................................... 93
Writing To ................................................................... 93
Protection Against Spurious Writes ................... 95
Unexpected Termination .................................... 95
Write Verify ........................................................ 95
G
General Call Address Support ......................................... 214
GOTO ............................................................................... 330
H
Hardware Multiplier .......................................................... 103
Introduction .............................................................. 103
Operation ................................................................. 103
Performance Comparison ........................................ 103
High/Low-Voltage Detect ................................................. 287
Applications .............................................................. 291
Associated Registers ............................................... 291
DS41303C-page 414
I
I/O Ports ........................................................................... 119
I2C
Associated Registers ............................................... 230
I2C Mode (MSSP)
Acknowledge Sequence Timing .............................. 224
Baud Rate Generator .............................................. 217
Bus Collision
During a Repeated Start Condition .................. 228
During a Stop Condition .................................. 229
Clock Arbitration ...................................................... 218
Clock Stretching ....................................................... 210
10-Bit Slave Receive Mode (SEN = 1) ............ 210
10-Bit Slave Transmit Mode ............................ 210
7-Bit Slave Receive Mode (SEN = 1) .............. 210
7-Bit Slave Transmit Mode .............................. 210
Clock Synchronization and the CKP bit (SEN = 1) .. 211
Effects of a Reset .................................................... 225
General Call Address Support ................................. 214
I2C Clock Rate w/BRG ............................................. 217
Master Mode ............................................................ 215
Operation ......................................................... 216
Reception ........................................................ 221
Repeated Start Condition Timing .................... 220
Start Condition Timing ..................................... 219
Transmission ................................................... 221
Multi-Master Communication, Bus Collision
and Arbitration ................................................. 225
Multi-Master Mode ................................................... 225
Operation ................................................................. 203
Read/Write Bit Information (R/W Bit) ............... 203, 204
Registers ................................................................. 198
Serial Clock (RC3/SCK/SCL) ................................... 204
Slave Mode .............................................................. 203
Addressing ....................................................... 203
Reception ........................................................ 204
Transmission ................................................... 204
Sleep Operation ....................................................... 225
Stop Condition Timing ............................................. 224
ID Locations ............................................................. 293, 307
INCF ................................................................................ 330
INCFSZ ............................................................................ 331
In-Circuit Debugger .......................................................... 307
In-Circuit Serial Programming (ICSP) ...................... 293, 307
Indexed Literal Offset Addressing
and Standard PIC18 Instructions ............................. 356
Indexed Literal Offset Mode ............................................. 356
Indirect Addressing ............................................................ 82
INFSNZ ............................................................................ 331
Initialization Conditions for all Registers ...................... 5760
Instruction Cycle ................................................................ 67
Clocking Scheme ....................................................... 67
Instruction Flow/Pipelining ................................................. 67
Instruction Set .................................................................. 309
ADDLW .................................................................... 315
Preliminary
PIC18F2XK20/4XK20
ADDWF .................................................................... 315
ADDWF (Indexed Literal Offset Mode) .................... 357
ADDWFC ................................................................. 316
ANDLW .................................................................... 316
ANDWF .................................................................... 317
BC ............................................................................ 317
BCF .......................................................................... 318
BN ............................................................................ 318
BNC ......................................................................... 319
BNN ......................................................................... 319
BNOV ....................................................................... 320
BNZ .......................................................................... 320
BOV ......................................................................... 323
BRA .......................................................................... 321
BSF .......................................................................... 321
BSF (Indexed Literal Offset Mode) .......................... 357
BTFSC ..................................................................... 322
BTFSS ..................................................................... 322
BTG .......................................................................... 323
BZ ............................................................................ 324
CALL ........................................................................ 324
CLRF ........................................................................ 325
CLRWDT .................................................................. 325
COMF ...................................................................... 326
CPFSEQ .................................................................. 326
CPFSGT .................................................................. 327
CPFSLT ................................................................... 327
DAW ......................................................................... 328
DCFSNZ .................................................................. 329
DECF ....................................................................... 328
DECFSZ ................................................................... 329
Extended Instruction Set .......................................... 351
General Format ........................................................ 311
GOTO ...................................................................... 330
INCF ......................................................................... 330
INCFSZ .................................................................... 331
INFSNZ .................................................................... 331
IORLW ..................................................................... 332
IORWF ..................................................................... 332
LFSR ........................................................................ 333
MOVF ....................................................................... 333
MOVFF .................................................................... 334
MOVLB .................................................................... 334
MOVLW ................................................................... 335
MOVWF ................................................................... 335
MULLW .................................................................... 336
MULWF .................................................................... 336
NEGF ....................................................................... 337
NOP ......................................................................... 337
Opcode Field Descriptions ....................................... 310
POP ......................................................................... 338
PUSH ....................................................................... 338
RCALL ..................................................................... 339
RESET ..................................................................... 339
RETFIE .................................................................... 340
RETLW .................................................................... 340
RETURN .................................................................. 341
RLCF ........................................................................ 341
RLNCF ..................................................................... 342
RRCF ....................................................................... 342
RRNCF .................................................................... 343
SETF ........................................................................ 343
SETF (Indexed Literal Offset Mode) ........................ 357
SLEEP ..................................................................... 344
SUBFWB .................................................................. 344
L
LFSR ............................................................................... 333
Low-Voltage ICSP Programming. See
Single-Supply ICSP Programming
M
Master Clear (MCLR) ......................................................... 51
Master Synchronous Serial Port (MSSP). See MSSP.
Memory Organization ........................................................ 63
Data Memory ............................................................. 69
Program Memory ....................................................... 63
Microchip Internet Web Site ............................................. 421
MOVF .............................................................................. 333
MOVFF ............................................................................ 334
MOVLB ............................................................................ 334
MOVLW ........................................................................... 335
MOVSF ............................................................................ 353
MOVSS ............................................................................ 354
MOVWF ........................................................................... 335
MPLAB ASM30 Assembler, Linker, Librarian .................. 360
MPLAB ICD 2 In-Circuit Debugger .................................. 361
MPLAB ICE 2000 High-Performance Universal
In-Circuit Emulator ................................................... 361
MPLAB Integrated Development Environment Software . 359
MPLAB PM3 Device Programmer ................................... 361
MPLAB REAL ICE In-Circuit Emulator System ............... 361
MPLINK Object Linker/MPLIB Object Librarian ............... 360
Preliminary
DS41303C-page 415
PIC18F2XK20/4XK20
MSSP
ACK Pulse ........................................................ 203, 204
Control Registers (general) ...................................... 189
I2C Mode. See I2C Mode.
Module Overview ..................................................... 189
SPI Master/Slave Connection .................................. 193
SPI Mode. See SPI Mode.
SSPBUF Register .................................................... 194
SSPSR Register ...................................................... 194
MULLW ............................................................................ 336
MULWF ............................................................................ 336
N
NEGF ............................................................................... 337
NOP ................................................................................. 337
O
OSCCON Register ............................................................. 27
Oscillator Configuration
EC .............................................................................. 25
ECIO .......................................................................... 25
HS .............................................................................. 25
HSPLL ........................................................................ 25
INTOSC ..................................................................... 25
INTOSCIO .................................................................. 25
LP ............................................................................... 25
RC .............................................................................. 25
RCIO .......................................................................... 25
XT .............................................................................. 25
Oscillator Module ............................................................... 25
HFINTOSC ................................................................. 25
LFINTOSC ................................................................. 25
Oscillator Selection .......................................................... 293
Oscillator Start-up Timer (OST) ................................... 34, 53
Oscillator Switching
Fail-Safe Clock Monitor .............................................. 38
Two-Speed Clock Start-up ......................................... 35
Oscillator Transitions .......................................................... 26
Oscillator, Timer1 ..................................................... 155, 167
Oscillator, Timer3 ............................................................. 165
OSCTUNE Register ........................................................... 31
P
P1A/P1B/P1C/P1D.See Enhanced
Capture/Compare/PWM (ECCP) ............................. 171
Packaging Information ..................................................... 399
Marking .................................................................... 399
Parallel Slave Port (PSP) ......................................... 128, 137
Associated Registers ............................................... 138
CS (Chip Select) ...................................................... 137
PORTD .................................................................... 137
RD (Read Input) ....................................................... 137
Select (PSPMODE Bit) .................................... 128, 137
WR (Write Input) ...................................................... 137
PICSTART Plus Development Programmer .................... 362
PIE Registers ................................................................... 112
PIE1 Register ................................................................... 112
PIE2 Register ................................................................... 113
Pin Functions
MCLR/VPP/RE3 .................................................... 14, 18
OSC1/CLKI/RA7 .................................................. 14, 18
OSC2/CLKO/RA6 ................................................ 14, 18
RA0/AN0/C12IN0- ................................................ 15, 19
RA1/AN1/C12IN0- ...................................................... 19
RA1/AN1/C12IN1- ...................................................... 15
RA2/AN2/VREF-/CVREF/C2IN+ ............................. 15, 19
DS41303C-page 416
Preliminary
PIC18F2XK20/4XK20
PORTD Register ...................................................... 128
TRISD Register ........................................................ 128
PORTE
Associated Registers ............................................... 133
LATE Register .......................................................... 131
PORTE Register ...................................................... 131
PSP Mode Select (PSPMODE Bit) .......................... 128
TRISE Register ........................................................ 131
Power Managed Modes ..................................................... 41
and A/D Operation ................................................... 263
and PWM Operation ................................................ 186
and SPI Operation ................................................... 197
Clock Transitions and Status Indicators ..................... 42
Effects on Clock Sources ........................................... 34
Entering ...................................................................... 41
Exiting Idle and Sleep Modes .................................... 46
by Interrupt ......................................................... 46
by Reset ............................................................. 46
by WDT Time-out ............................................... 46
Without a Start-up Delay .................................... 47
Idle Modes ................................................................. 43
PRI_IDLE ........................................................... 45
RC_IDLE ............................................................ 46
SEC_IDLE ......................................................... 45
Multiple Sleep Functions ............................................ 42
Run Modes ................................................................. 42
PRI_RUN ........................................................... 42
SEC_RUN .......................................................... 42
Selecting .................................................................... 41
Sleep Mode ................................................................ 43
Summary (table) ........................................................ 41
Power-on Reset (POR) ...................................................... 51
Power-up Timer (PWRT) ........................................... 53
Time-out Sequence .................................................... 53
Power-up Delays ................................................................ 34
Power-up Timer (PWRT) ................................................... 34
Prescaler, Timer0 ............................................................. 153
PRI_IDLE Mode ................................................................. 45
PRI_RUN Mode ................................................................. 42
Program Counter ............................................................... 64
PCL, PCH and PCU Registers ................................... 64
PCLATH and PCLATU Registers .............................. 64
Program Memory
and Extended Instruction Set ..................................... 85
Code Protection ....................................................... 305
Instructions ................................................................. 68
Two-Word .......................................................... 68
Interrupt Vector .......................................................... 63
Look-up Tables .......................................................... 66
Map and Stack (diagram) ........................................... 63
Reset Vector .............................................................. 63
Program Verification and Code Protection ....................... 304
Associated Registers ............................................... 304
Programming, Device Instructions ................................... 309
PSP. See Parallel Slave Port.
PSTRCON Register ......................................................... 183
Pulse Steering .................................................................. 183
PUSH ............................................................................... 338
PUSH and POP Instructions .............................................. 65
PUSHL ............................................................................. 354
PWM (CCP Module)
Associated Registers ............................................... 149
PWM (ECCP Module)
Effects of a Reset ..................................................... 186
Operation in Power Managed Modes ...................... 186
R
RAM. See Data Memory.
RC_IDLE Mode .................................................................. 46
RCALL ............................................................................. 339
RCON Register .......................................................... 50, 116
Bit Status During Initialization .................................... 56
RCREG ............................................................................ 238
RCSTA Register .............................................................. 241
Reader Response ............................................................ 422
Register
RCREG Register ..................................................... 247
Register File ....................................................................... 75
Register File Summary ................................................ 7779
Registers
ADCON0 (ADC Control 0) ....................................... 265
ADCON1 (ADC Control 1) ....................................... 266
ADCON2 (ADC Control 2) ....................................... 267
ADRESH (ADC Result High) with ADFM = 0) ......... 268
ADRESH (ADC Result High) with ADFM = 1) ......... 268
ADRESL (ADC Result Low) with ADFM = 0) ........... 268
ADRESL (ADC Result Low) with ADFM = 1) ........... 268
ANSEL (Analog Select 1) ........................................ 134
ANSEL (PORT Analog Control) ............................... 134
ANSELH (Analog Select 2) ...................................... 135
ANSELH (PORT Analog Control) ............................ 135
BAUDCTL (Baud Rate Control) ............................... 242
BAUDCTL (EUSART Baud Rate Control) ............... 242
CCP1CON (Enhanced Capture/Compare/PWM
Control) ........................................................... 169
CCP2CON (Standard Capture/Compare/PWM
Control) ............................................................ 139
CM1CON0 (C1 Control) .......................................... 278
CM2CON0 (C2 Control) .......................................... 279
CM2CON1 (C2 Control) .......................................... 281
CONFIG1H (Configuration 1 High) .......................... 295
CONFIG2H (Configuration 2 High) .......................... 296
CONFIG2L (Configuration 2 Low) ........................... 296
CONFIG3H (Configuration 3 High) .......................... 297
CONFIG4L (Configuration 4 Low) ........................... 297
CONFIG5H (Configuration 5 High) .......................... 298
CONFIG5L (Configuration 5 Low) ........................... 298
CONFIG6H (Configuration 6 High) .......................... 299
CONFIG6L (Configuration 6 Low) ........................... 299
CONFIG7H (Configuration 7 High) .......................... 300
CONFIG7L (Configuration 7 Low) ........................... 300
CVRCON (Comparator Voltage Reference Control)
CVRCON Register ........................................... 285
CVRCON2 (Comparator Voltage Reference Control 2)
CVRCON2 Register ......................................... 286
DEVID1 (Device ID 1) .............................................. 301
DEVID2 (Device ID 2) .............................................. 301
ECCPAS (Enhanced CCP Auto-shutdown Control) 179
EECON1 (Data EEPROM Control 1) ................... 89, 98
HLVDCON (High/Low-Voltage Detect Control) ....... 287
INTCON (Interrupt Control) ..................................... 107
INTCON2 (Interrupt Control 2) ................................ 108
INTCON3 (Interrupt Control 3) ................................ 109
IPR1 (Peripheral Interrupt Priority 1) ....................... 114
IPR2 (Peripheral Interrupt Priority 2) ....................... 115
OSCCON (Oscillator Control) .................................... 27
Preliminary
DS41303C-page 417
PIC18F2XK20/4XK20
OSCTUNE (Oscillator Tuning) ................................... 31
PIE1 (Peripheral Interrupt Enable 1) ........................ 112
PIE2 (Peripheral Interrupt Enable 2) ........................ 113
PIR1 (Peripheral Interrupt Request 1) ..................... 110
PIR2 (Peripheral Interrupt Request 2) ..................... 111
PSTRCON (Pulse Steering Control) ........................ 183
PWM1CON (Enhanced PWM Control) .................... 182
RCON (Reset Control) ....................................... 50, 116
RCON (Reset control) .............................................. 116
RCSTA (Receive Status and Control) ...................... 241
SLRCON (PORT Slew Rate Control) ....................... 136
SSPADD (MSSP Address and Baud Rate,
SPI Mode) ........................................................ 199
SSPCON1 (MSSP Control 1, I2C Mode) ................. 201
SSPCON1 (MSSP Control 1, SPI Mode) ................. 191
SSPCON2 (MSSP Control 2, I2C Mode) ................. 202
SSPMSK (SSP Mask) .............................................. 209
SSPSTAT (MSSP Status, SPI Mode) .............. 190, 200
STATUS ..................................................................... 80
STKPTR (Stack Pointer) ............................................ 65
T0CON (Timer0 Control) .......................................... 151
T1CON (Timer1 Control) .......................................... 155
T2CON (Timer2 Control) .......................................... 163
T3CON (Timer3 Control) .......................................... 165
TRISE (PORTE/PSP Control) .................................. 132
TXSTA (Transmit Status and Control) ..................... 240
WDTCON (Watchdog Timer Control) ....................... 303
RESET ............................................................................. 339
Reset State of Registers .................................................... 56
Resets ........................................................................ 49, 293
Brown-out Reset (BOR) ........................................... 293
Oscillator Start-up Timer (OST) ............................... 293
Power-on Reset (POR) ............................................ 293
Power-up Timer (PWRT) ......................................... 293
RETFIE ............................................................................ 340
RETLW ............................................................................. 340
RETURN .......................................................................... 341
Return Address Stack ........................................................ 64
Return Stack Pointer (STKPTR) ........................................ 65
Revision History ............................................................... 409
RLCF ................................................................................ 341
RLNCF ............................................................................. 342
RRCF ............................................................................... 342
RRNCF ............................................................................. 343
S
SCK .................................................................................. 189
SDI ................................................................................... 189
SDO ................................................................................. 189
SEC_IDLE Mode ................................................................ 45
SEC_RUN Mode ................................................................ 42
Serial Clock, SCK ............................................................. 189
Serial Data In (SDI) .......................................................... 189
Serial Data Out (SDO) ..................................................... 189
Serial Peripheral Interface. See SPI Mode.
SETF ................................................................................ 343
Shoot-through Current ..................................................... 181
Single-Supply ICSP Programming.
Slave Select (SS) ............................................................. 189
Slave Select Synchronization ........................................... 195
SLEEP .............................................................................. 344
Sleep
OSC1 and OSC2 Pin States ...................................... 34
Sleep Mode ........................................................................ 43
Slew Rate ......................................................................... 136
SLRCON Register ............................................................ 136
DS41303C-page 418
T
T0CON Register .............................................................. 151
T1CON Register .............................................................. 155
T2CON Register .............................................................. 163
T3CON Register .............................................................. 165
Table Pointer Operations (table) ........................................ 90
Table Reads/Table Writes ................................................. 66
TBLRD ............................................................................. 347
TBLWT ............................................................................. 348
Time-out in Various Situations (table) ................................ 53
Timer0 .............................................................................. 151
Associated Registers ............................................... 153
Operation ................................................................. 152
Overflow Interrupt .................................................... 153
Prescaler ................................................................. 153
Prescaler Assignment (PSA Bit) .............................. 153
Prescaler Select (T0PS2:T0PS0 Bits) ..................... 153
Prescaler. See Prescaler, Timer0.
Reads and Writes in 16-Bit Mode ............................ 152
Preliminary
PIC18F2XK20/4XK20
Source Edge Select (T0SE Bit) ................................ 152
Source Select (T0CS Bit) ......................................... 152
Switching Prescaler Assignment .............................. 153
Timer1 .............................................................................. 155
16-Bit Read/Write Mode ........................................... 158
Associated Registers ............................................... 161
Asynchronous Counter Mode .................................. 157
Reading and Writing ........................................ 157
Interrupt .................................................................... 159
Operation ................................................................. 156
Oscillator .......................................................... 155, 158
Oscillator Layout Considerations ............................. 159
Overflow Interrupt .................................................... 155
Prescaler .................................................................. 157
Resetting, Using the CCP Special Event Trigger ..... 159
Special Event Trigger (ECCP) ................................. 170
TMR1H Register ...................................................... 155
TMR1L Register ....................................................... 155
Use as a Real-Time Clock ....................................... 160
Timer2 .............................................................................. 163
Associated Registers ............................................... 164
Interrupt .................................................................... 164
Operation ................................................................. 163
Output ...................................................................... 164
Timer3 .............................................................................. 165
16-Bit Read/Write Mode ........................................... 167
Associated Registers ............................................... 168
Operation ................................................................. 166
Oscillator .......................................................... 165, 167
Overflow Interrupt ............................................ 165, 167
Special Event Trigger (CCP) .................................... 168
TMR3H Register ...................................................... 165
TMR3L Register ....................................................... 165
Timing Diagrams
A/D Conversion ........................................................ 395
Acknowledge Sequence .......................................... 224
Asynchronous Reception ......................................... 238
Asynchronous Transmission .................................... 234
Asynchronous Transmission (Back to Back) ........... 235
Auto Wake-up Bit (WUE) During Normal Operation 248
Auto Wake-up Bit (WUE) During Sleep ................... 249
Automatic Baud Rate Calculator .............................. 247
Baud Rate Generator with Clock Arbitration ............ 218
BRG Reset Due to SDA Arbitration During
Start Condition ................................................. 227
Brown-out Reset (BOR) ........................................... 381
Bus Collision During a Repeated Start Condition
(Case 1) .......................................................... 228
Bus Collision During a Repeated Start Condition
(Case 2) .......................................................... 228
Bus Collision During a Start Condition (SCL = 0) .... 227
Bus Collision During a Stop Condition (Case 1) ...... 229
Bus Collision During a Stop Condition (Case 2) ...... 229
Bus Collision During Start Condition (SDA only) ..... 226
Bus Collision for Transmit and Acknowledge ........... 225
Capture/Compare/PWM (CCP) ................................ 383
CLKO and I/O .......................................................... 380
Clock Synchronization ............................................. 211
Clock/Instruction Cycle .............................................. 67
Comparator Output .................................................. 273
Example SPI Master Mode (CKE = 0) ..................... 385
Example SPI Master Mode (CKE = 1) ..................... 386
Example SPI Slave Mode (CKE = 0) ....................... 387
Example SPI Slave Mode (CKE = 1) ....................... 388
External Clock (All Modes except PLL) .................... 378
Preliminary
DS41303C-page 419
PIC18F2XK20/4XK20
A/D Conversion Requirements ................................ 395
Capture/Compare/PWM Requirements ................... 383
CLKO and I/O Requirements ................................... 380
Example SPI Mode Requirements
(Master Mode, CKE = 0) .................................. 385
(Master Mode, CKE = 1) .................................. 386
(Slave Mode, CKE = 0) .................................... 387
(Slave Mode, CKE = 1) .................................... 388
External Clock Requirements .................................. 378
I2C Bus Data Requirements (Slave Mode) .............. 390
I2C Bus Start/Stop Bits Requirements
(Slave Mode) .................................................... 389
Master SSP I2C Bus Data Requirements ................ 392
Master SSP I2C Bus Start/Stop Bits Requirements . 391
Parallel Slave Port Requirements (PIC18F4X20) .... 384
PLL Clock ................................................................. 379
Reset, Watchdog Timer, Oscillator Start-up
Timer, Power-up Timer and Brown-out
Reset Requirements ........................................ 381
Timer0 and Timer1 External Clock Requirements ... 382
USART Synchronous Receive Requirements ......... 393
USART Synchronous Transmission Requirements . 393
Top-of-Stack Access .......................................................... 64
TRISE Register ................................................................ 132
PSPMODE Bit .......................................................... 128
TSTFSZ ............................................................................ 349
Two-Speed Clock Start-up Mode ....................................... 35
Two-Speed Start-up ......................................................... 293
Two-Word Instructions
Example Cases .......................................................... 68
TXREG ............................................................................. 233
TXSTA Register ............................................................... 240
BRGH Bit ................................................................. 243
W
Wake-up on Break ........................................................... 248
Watchdog Timer (WDT) ........................................... 293, 302
Associated Registers ............................................... 303
Control Register ....................................................... 303
Programming Considerations .................................. 302
WCOL ...................................................... 219, 220, 221, 224
WCOL Status Flag ................................... 219, 220, 221, 224
WDTCON Register .......................................................... 303
WWW Address ................................................................ 421
WWW, On-Line Support ...................................................... 8
X
XORLW ............................................................................ 349
XORWF ........................................................................... 350
V
Voltage Reference (VR)
Specifications ........................................................... 374
Voltage Reference. See Comparator Voltage
Reference (CVREF)
Voltage References
Fixed Voltage Reference (FVR) ............................... 284
VR Stabilization ........................................................ 284
VREF. SEE ADC Reference Voltage
DS41303C-page 420
Preliminary
PIC18F2XK20/4XK20
THE MICROCHIP WEB SITE
CUSTOMER SUPPORT
Distributor or Representative
Local Sales Office
Field Application Engineer (FAE)
Technical Support
Development Systems Information Line
Customers
should
contact
their
distributor,
representative or field application engineer (FAE) for
support. Local sales offices are also available to help
customers. A listing of sales offices and locations is
included in the back of this document.
Technical support is available through the web site
at: http://support.microchip.com
Preliminary
DS41303C-page 421
PIC18F2XK20/4XK20
READER RESPONSE
It is our intention to provide you with the best documentation possible to ensure successful use of your Microchip product. If you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation
can better serve you, please FAX your comments to the Technical Publications Manager at (480) 792-4150.
Please list the following information, and use this outline to provide us with your comments about this document.
To:
RE:
Reader Response
From: Name
Company
Address
City / State / ZIP / Country
Telephone: (_______) _________ - _________
Application (optional):
Would you like a reply?
Device: PIC18F2XK20/4XK20
N
Literature Number: DS41303C
Questions:
1. What are the best features of this document?
2. How does this document meet your hardware and software development needs?
3. Do you find the organization of this document easy to follow? If not, why?
4. What additions to the document do you think would enhance the structure and subject?
5. What deletions from the document could be made without affecting the overall usefulness?
DS41303C-page 422
Preliminary
PIC18F2XK20/4XK20
PRODUCT IDENTIFICATION SYSTEM
To order or obtain information, e.g., on pricing or delivery, refer to the factory or the listed sales office.
PART NO.
/XX
XXX
Device
Temperature
Range
Package
Pattern
Examples:
a)
b)
Device:
Temperature
Range:
Package:
ML
P
PT
SO
SP
SS
Pattern:
= -40C to +125C
=
=
=
=
=
=
c)
(Extended)
QFN
PDIP
TQFP (Thin Quad Flatpack)
SOIC
Skinny Plastic DIP
SSOP
Note 1:
Preliminary
DS41303C-page 423
ASIA/PACIFIC
ASIA/PACIFIC
EUROPE
Corporate Office
2355 West Chandler Blvd.
Chandler, AZ 85224-6199
Tel: 480-792-7200
Fax: 480-792-7277
Technical Support:
http://support.microchip.com
Web Address:
www.microchip.com
India - Bangalore
Tel: 91-80-4182-8400
Fax: 91-80-4182-8422
India - New Delhi
Tel: 91-11-4160-8631
Fax: 91-11-4160-8632
Austria - Wels
Tel: 43-7242-2244-39
Fax: 43-7242-2244-393
Denmark - Copenhagen
Tel: 45-4450-2828
Fax: 45-4485-2829
India - Pune
Tel: 91-20-2566-1512
Fax: 91-20-2566-1513
France - Paris
Tel: 33-1-69-53-63-20
Fax: 33-1-69-30-90-79
Japan - Yokohama
Tel: 81-45-471- 6166
Fax: 81-45-471-6122
Germany - Munich
Tel: 49-89-627-144-0
Fax: 49-89-627-144-44
Atlanta
Duluth, GA
Tel: 678-957-9614
Fax: 678-957-1455
Boston
Westborough, MA
Tel: 774-760-0087
Fax: 774-760-0088
Chicago
Itasca, IL
Tel: 630-285-0071
Fax: 630-285-0075
Dallas
Addison, TX
Tel: 972-818-7423
Fax: 972-818-2924
Detroit
Farmington Hills, MI
Tel: 248-538-2250
Fax: 248-538-2260
Kokomo
Kokomo, IN
Tel: 765-864-8360
Fax: 765-864-8387
Los Angeles
Mission Viejo, CA
Tel: 949-462-9523
Fax: 949-462-9608
Santa Clara
Santa Clara, CA
Tel: 408-961-6444
Fax: 408-961-6445
Toronto
Mississauga, Ontario,
Canada
Tel: 905-673-0699
Fax: 905-673-6509
Australia - Sydney
Tel: 61-2-9868-6733
Fax: 61-2-9868-6755
China - Beijing
Tel: 86-10-8528-2100
Fax: 86-10-8528-2104
Korea - Daegu
Tel: 82-53-744-4301
Fax: 82-53-744-4302
China - Chengdu
Tel: 86-28-8665-5511
Fax: 86-28-8665-7889
China - Fuzhou
Tel: 86-591-8750-3506
Fax: 86-591-8750-3521
Korea - Seoul
Tel: 82-2-554-7200
Fax: 82-2-558-5932 or
82-2-558-5934
China - Nanjing
Tel: 86-25-8473-2460
Fax: 86-25-8473-2470
Malaysia - Penang
Tel: 60-4-227-8870
Fax: 60-4-227-4068
China - Qingdao
Tel: 86-532-8502-7355
Fax: 86-532-8502-7205
Philippines - Manila
Tel: 63-2-634-9065
Fax: 63-2-634-9069
China - Shanghai
Tel: 86-21-5407-5533
Fax: 86-21-5407-5066
Singapore
Tel: 65-6334-8870
Fax: 65-6334-8850
China - Shenyang
Tel: 86-24-2334-2829
Fax: 86-24-2334-2393
China - Shenzhen
Tel: 86-755-8203-2660
Fax: 86-755-8203-1760
Taiwan - Kaohsiung
Tel: 886-7-536-4818
Fax: 886-7-536-4803
China - Shunde
Tel: 86-757-2839-5507
Fax: 86-757-2839-5571
Taiwan - Taipei
Tel: 886-2-2500-6610
Fax: 886-2-2508-0102
China - Wuhan
Tel: 86-27-5980-5300
Fax: 86-27-5980-5118
Thailand - Bangkok
Tel: 66-2-694-1351
Fax: 66-2-694-1350
Italy - Milan
Tel: 39-0331-742611
Fax: 39-0331-466781
Netherlands - Drunen
Tel: 31-416-690399
Fax: 31-416-690340
Spain - Madrid
Tel: 34-91-708-08-90
Fax: 34-91-708-08-91
UK - Wokingham
Tel: 44-118-921-5869
Fax: 44-118-921-5820
China - Xian
Tel: 86-29-8833-7252
Fax: 86-29-8833-7256
10/05/07
DS41303C-page 424
Preliminary