Академический Документы
Профессиональный Документы
Культура Документы
Peripheral Highlights:
Up to 33 I/O pins plus 3 Input-Only Pins:
- High-current Sink/Source 25 mA/25 mA
- Three programmable external interrupts
- 11 programmable interrupts-on-change
- Nine programmable weak pull-ups
- Programmable slew rate
SR Latch
Enhanced Capture/Compare/PWM (ECCP)
module:
- One, two or four PWM outputs
- Selectable polarity
- Programmable dead time
- Auto-shutdown and auto-restart
- Pulse steering control
Capture/Compare/PWM (CCP) module
Master Synchronous Serial Port (MSSP) module
Supporting 3-Wire SPI (all four modes) and I2C
Master and Slave modes
Two Analog Comparators with Input Multiplexing
10-Bit Analog-to-Digital (A/D) Converter module:
- Up to 25 input channels
- Auto-acquisition capability
- Conversion available during Sleep
DS30000684B-page 1
PIC18(L)F2X/45K50
10-Bit A/D
Channels
Comparators
CCP/
ECCP
BOR/LVD
CTMU
MSSP
EUSART
Timers
8-bit/16-bit
USB 2.0
PIC18(L)F45K50
32K
16384
2048
256
40/44
36
25-ch
1/1
Yes
Yes
2/2
Yes
PIC18(L)F25K50
32K
16384
2048
256
28
25
14-ch
1/1
Yes
Yes
2/2
Yes
PIC18(L)F24K50
16K
8192
2048
256
28
25
14-ch
1/1
Yes
Yes
2/2
Yes
Program Memory
Device
Flash
(bytes)
Data Memory
Data
Single-Word SRAM
EEPROM
Instructions (bytes)
Pins
I/O
(bytes)
Pin Diagrams
28-PIN SPDIP (300 MIL), SOIC, SSOP
MCLR/VPP/RE3
RA0
RA1
RA2
RA3
RA4
RA5
VSS
RA7
RA6
RC0
RC1
RC2
VUSB3V3
28
27
26
25
24
23
22
21
20
19
18
17
16
15
RB7
RB6
RB5
RB4
RB3
RB2
RB1
RB0
VDD
VSS
RC7
RC6
D+
D-
28-PIN QFN
28
27
26
25
24
23
22
RA1
RA0
MCLR/VPP/RE3
RB7
RB6
RB5
RB4
FIGURE 2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
PIC18(L)F2XK50
FIGURE 1:
1
21 RB3
2
20 RB2
3
19 RB1
PIC18(L)F2XK50
4
18 RB0
5
17 VDD
6
16 VSS
7
15 RC7
RC0 8
RC1 9
RC2 10
VUSB3V3 11
D- 12
D+ 13
RC6 14
RA2
RA3
RA4
RA5
VSS
RA7
RA6
Note:
For the QFN package, it is recommended that the bottom pad be connected to VSS.
DS30000684B-page 2
PIC18(L)F2X/45K50
40-PIN PDIP (600 MIL)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
MCLR/VPP/RE3
RA0
RA1
RA2
RA3
RA4
RA5
RE0
RE1
RE2
VDD
VSS
RA7
RA6
RC0
RC1
RC2
VUSB3V3
RD0
RD1
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
RB7
RB6
RB5
RB4
RB3
RB2
RB1
RB0
VDD
VSS
RD7
RD6
RD5
RD4
RC7
RC6
D+
DRD3
RD2
40-PIN UQFN
40
39
38
37
36
35
34
33
32
31
RC6
D+
DRD3
RD2
RD1
RD0
VUSB3V3
RC2
RC1
FIGURE 4:
PIC18(L)F45K50
FIGURE 3:
1
2
3
4
5
6
7
8
9
10
PIC18(L)F45K50
30 RC0
29 RA6
28 RA7
27 VSS
26 VDD
25 RE2
24 RE1
23 RE0
22 RA5
21 RA4
RB3
RB4
RB5
RB6
RB7
MCLR/VPP/RE3
RA0
RA1
RA2
RA3
11
12
13
14
15
16
17
18
19
20
RC7
RD4
RD5
RD6
RD7
VSS
VDD
RB0
RB1
RB2
Note:
For the UQFN package, it is recommended that the bottom pad be connected to VSS.
DS30000684B-page 3
PIC18(L)F2X/45K50
44-PIN TQFP
PIC18(L)F45K50
33
32
31
30
29
28
27
26
25
24
23
12
13
14
15
16
17
18
19
20
21
22
1
2
3
4
5
6
7
8
9
10
11
NC/ICRST(1)/ICVPP(1)
RC0
RA6
RA7
VSS
VDD
RE2
RE1
RE0
RA5
RA4
NC/ICCK(1)/ICPGC(1)
NC/ICDT(1)/ICPGD(1)
RB4
RB5
RB6
RB7
MCLR/VPP/RE3
RA0
RA1
RA2
RA3
RC7
RD4
RD5
RD6
RD7
VSS
VDD
RB0
RB1
RB2
RB3
44
43
42
41
40
39
38
37
36
35
34
RC6
D+
DRD3
RD2
RD1
RD0
VUSB3V3
RC2
RC1
NC
FIGURE 5:
Note 1:
DS30000684B-page 4
AN2
C2IN+
RA3
20
22
AN3
ICD
21
Basic
19
Pull-up
Interrupts
Timers
MSSP
RA2
EUSART
C12IN1- CTCMP
(E)CCP
C12IN0-
AN1
USB
AN0
20
VREFDACOUT
C1IN+
VREF+
21
23
C1OUT
RA5
22
24
AN4
C2OUT
SRQ
T0CKI
SRNQ
HLVDIN
SS
RA6
10
14
29
31
OSC2
CLKO
RA7
13
28
30
OSC1
CLKI
RB0
21
18
33
AN12
SRI
FLT0
SDI
SDA
INT0
RB1
22
19
34
AN10
C12IN3-
P1C(5)
SCK
SCL
INT1
RB2
23
20
35
10
10
AN8
CTED1
P1B(5)
RB3
24
21
INT2
36
11
11
AN9
C12IN2-
CTED2
CCP2(1)
SDO
RB4
25
22
37
12
14
AN11
P1D(5)
IOCB4
RB5
26
23
38
13
15
AN13
T1G
IOCB5
T3CKI(2)
RB6
27
24
39
14
16
PGC
DS30000684B-page 5
IOCB6
PIC18(L)F2X/45K50
RA4
Note 1:
2:
3:
4:
5:
6:
7:
Reference
19
18
SR Latch
17
CTMU
28
Analog
27
40-Pin PDIP
RA1
28-Pin QFN
Comparator
44-Pin TQFP
40-Pin UQFN
28-Pin SPDIP/SOIC/SSOP
RA0
I/O
TABLE 1:
Interrupts
Pull-up
Basic
IOCB7
PGD
SOSCO IOCC0
T1CKI
T3CKI
T3G
ICD
Timers
MSSP
EUSART
(E)CCP
USB
Reference
32
SR Latch
17
30
CTMU
15
15
Comparator
40
Analog
25
11
44-Pin TQFP
28-Pin QFN
28
40-Pin UQFN
28-Pin SPDIP/SOIC/SSOP
RB7
RC0
40-Pin PDIP
I/O
RC1
12
16
31
35
CCP2
SOSCI
IOCC1
RC2
13
10
17
32
36
AN14
CTPLS
CCP1
P1A
IOCC2
14
11
18
33
37
VUSB3V3
VDDCORE
15
12
23
38
42
D-
IOCC4
16
13
24
39
43
D+
IOCC5
RC6
17
14
25
40
44
AN18
TX
CK
IOCC6
RC7
18
15
26
AN19
RX
DT
SDO(6)
IOCC7
RD0
19
34
38
AN20
RD1
20
35
39
AN21
RD2
21
36
40
AN22
RD3
22
37
41
AN23
RD4
27
AN24
RD5
28
AN25
P1B(4)
RD6
29
AN26
P1C(4)
RD7
30
AN27
P1D(4)
Note 1:
2:
3:
4:
5:
6:
7:
PIC18(L)F2X/45K50
DS30000684B-page 6
TABLE 1:
44-Pin TQFP
Analog
USB
(E)CCP
EUSART
MSSP
Timers
Interrupts
Pull-up
Basic
ICD
23
25
AN5
24
26
AN6
Reference
40-Pin UQFN
SR Latch
40-Pin PDIP
RE1
CTMU
28-Pin QFN
RE0
Comparator
28-Pin SPDIP/SOIC/SSOP
I/O
TABLE 1:
RE2
10
25
27
AN7
RE3(7)
26
16
18
MCLR
VPP
20
17
11,
32
7,
26
7,
28
VDD
8,
19
5,
16
12,
31
6,
27
6,
29
VSS
12(3)
ICPGC(3)
ICCK(3)
(3)
ICPGD
(3)
ICDT(3)
ICVPP(3)
13
33(3)
DS30000684B-page 7
PIC18(L)F2X/45K50
Note 1:
2:
3:
4:
5:
6:
7:
ICRST(3)
PIC18(L)F2X/45K50
Table of Contents
1.0 Device Overview ....................................................................................................................................................................... 10
2.0 Guidelines for Getting Started with PIC18(L)F2X/45K50 Microcontrollers ................................................................................ 23
3.0 Oscillator Module (With Fail-Safe Clock Monitor)...................................................................................................................... 28
4.0 Power-Managed Modes ............................................................................................................................................................ 52
5.0 Reset ......................................................................................................................................................................................... 63
6.0 Memory Organization ................................................................................................................................................................ 73
7.0 Flash Program Memory ............................................................................................................................................................. 95
8.0 Data EEPROM Memory .......................................................................................................................................................... 104
9.0 8 x 8 Hardware Multiplier......................................................................................................................................................... 109
10.0 Interrupts .................................................................................................................................................................................. 111
11.0 I/O Ports .................................................................................................................................................................................. 128
12.0 Timer0 Module......................................................................................................................................................................... 153
13.0 Timer1/3 Module with Gate Control......................................................................................................................................... 156
14.0 Timer2 Module......................................................................................................................................................................... 168
15.0 Capture/Compare/PWM Modules............................................................................................................................................ 172
16.0 Master Synchronous Serial Port (MSSP) Module ................................................................................................................... 203
17.0 Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART) .............................................................. 258
18.0 Analog-to-Digital Converter (ADC) Module ............................................................................................................................. 287
19.0 Comparator Module................................................................................................................................................................. 301
20.0 Charge Time Measurement Unit (CTMU)................................................................................................................................ 310
21.0 SR Latch.................................................................................................................................................................................. 325
22.0 Fixed Voltage Reference (FVR)............................................................................................................................................... 330
23.0 Digital-to-Analog Converter (DAC) Module ............................................................................................................................. 332
24.0 Universal Serial Bus (USB) ..................................................................................................................................................... 336
25.0 High/Low-Voltage Detect (HLVD) ............................................................................................................................................ 364
26.0 Special Features of the CPU ................................................................................................................................................... 370
27.0 Instruction Set Summary ......................................................................................................................................................... 390
28.0 Development Support.............................................................................................................................................................. 440
29.0 Electrical Specifications ........................................................................................................................................................... 444
30.0 DC and AC Characteristics Graphs and Charts ...................................................................................................................... 485
31.0 Packaging Information............................................................................................................................................................. 486
Appendix A: Revision History............................................................................................................................................................ 503
Appendix B: Device Differences........................................................................................................................................................ 504
The Microchip Web Site .................................................................................................................................................................... 505
Customer Change Notification Service ............................................................................................................................................. 505
Customer Support ............................................................................................................................................................................. 505
Product Identification System............................................................................................................................................................ 506
DS30000684B-page 8
PIC18(L)F2X/45K50
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@microchip.com. 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)
When contacting a sales office, please specify which device, revision of silicon and data sheet (include literature number) you are
using.
DS30000684B-page 9
PIC18(L)F2X/45K50
1.0
DEVICE OVERVIEW
1.1
1.1.1
1.1.2
DS30000684B-page 10
1.1.3
PIC18(L)F2X/45K50
1.2
1.3
DS30000684B-page 11
PIC18(L)F2X/45K50
TABLE 1-1:
DEVICE FEATURES
Features
PIC18(L)F24K50
PIC18(L)F25K50
PIC18(L)F45K50
16384
32768
32768
8192
16384
16384
2048
2048
2048
256
256
(1)
I/O Ports
A, B, C, E
Capture/Compare/PWM Modules
(CCP)
Enhanced CCP Modules (ECCP)
10-bit Analog-to-Digital Module
(ADC)
Packages
256
(1)
A, B, C, E
1
3 internal
14 input
3 internal
14 input
3 internal
25 input
28-pin SPDIP
28-pin SOIC
28-pin SSOP
28-pin QFN
28-pin SPDIP
28-pin SOIC
28-pin SSOP
28-pin QFN
40-pin PDIP
40-pin UQFN
44-pin TQFP
Interrupt Sources
25
Timers (16-bit)
Serial Communications
MSSP,
EUSART
SR Latch
Yes
Yes
Programmable
High/Low-Voltage Detect (HLVD)
Yes
Yes
Instruction Set
Operating Frequency
Note 1:
A, B, C, D, E
DS30000684B-page 12
PIC18(L)F2X/45K50
FIGURE 1-1:
Table Pointer<21>
Data Latch
inc/dec logic
Data Memory
PCLATU PCLATH
21
PORTA
Address Latch
20
RA0:RA7
12
Data Address<12>
31-Level Stack
4
BSR
Address Latch
Program Memory
(16/32 Kbytes)
STKPTR
12
FSR0
FSR1
FSR2
Data Latch
8
4
Access
Bank
PORTB
12
RB0:RB7
inc/dec
logic
Table Latch
Address
Decode
ROM Latch
Instruction Bus <16>
PORTC
RC0:RC3
RC6:RC7
IR
8
State machine
control signals
Instruction
Decode and
Control
PRODH PRODL
PORTD
8 x 8 Multiply
8
W
BITOP
8
Internal
Oscillator
Block
OSC1(2)
(2)
OSC2
SOSCI
INTRC
Oscillator
SOSCO
16 MHz
Oscillator
Single-Supply
Programming
In-Circuit
Debugger
MCLR(1)
BOR
HLVD
FVR
DAC
Note
Comparators
C1/C2
Data
EEPROM
ECCP1
CCP2
Power-up
Timer
Oscillator
Start-up Timer
Power-on
Reset
Watchdog
Timer
Brown-out
Reset
Fail-Safe
Clock Monitor
PORTE
ALU<8>
RE0:RE2
Precision
Band Gap
Reference
RD0:RD7
RE3(1)
FVR
Timer0
Timer1
Timer3
Timer2
CTMU
DAC
USB
MSSP
EUSART
SR Latch
ADC
10-bit
FVR
DAC
1:
2:
OSC1/CLKIN and OSC2/CLKO are only available in select oscillator modes and when these pins are not being used as digital I/O.
Refer to Section 6.0 Memory Organization for additional information.
DS30000684B-page 13
PIC18(L)F2X/45K50
TABLE 1-2:
Pin Number
SPDIP,
SOIC,
SSOP
QFN
27
10
Legend:
Note 1:
2:
Pin Name
28
Pin
Type
Buffer
Type
Description
RA0/C12IN0-/AN0
RA0
I/O
TTL/DIG
C12IN0-
Analog
Digital I/O.
AN0
Analog
Analog input 0.
RA1/C12IN1-/AN1
RA1
I/O
TTL/DIG
C12IN1-
Analog
Digital I/O.
AN1
Analog
Analog input 1.
RA2
I/O
TTL/DIG
C2IN+
Analog
RA2/C2IN+/AN2/DACOUT/VREFDigital I/O.
Comparator C2 non-inverting input.
AN2
Analog
Analog input 2.
DACOUT
Analog
VREF-
Analog
RA3
I/O
TTL/DIG
C1IN+
Analog
RA3/C1IN+/AN3/VREF+
Digital I/O.
Comparator C1 non-inverting input.
AN3
Analog
Analog input 3.
VREF+
Analog
RA4/C1OUT/SRQ/T0CKI
RA4
I/O
ST/DIG
C1OUT
DIG
Comparator C1 output.
Digital I/O.
SRQ
DIG
SR latch Q output.
T0CKI
ST
RA5/C2OUT/SRNQ/SS/HLVDIN/AN4
RA5
I/O
TTL/DIG
C2OUT
DIG
Digital I/O.
SRNQ
DIG
SR latch Q output.
SS
TTL
HLVDIN
Analog
AN4
Analog
Analog input 4.
Comparator C2 output.
RA6/CLKO/OSC2
RA6
I/O
TTL/DIG
CLKO
DIG
OSC2
Digital I/O.
Outputs 1/4 the frequency of OSC1 and denotes the
instruction cycle rate.
Oscillator crystal output. Connects to crystal or
resonator in Crystal Oscillator modes.
TTL = TTL compatible input; CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels;
I = Input; O = Output; P = Power.
Default pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are set.
Alternate pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are clear.
DS30000684B-page 14
PIC18(L)F2X/45K50
TABLE 1-2:
Pin Number
SPDIP,
SOIC,
SSOP
QFN
21
22
23
24
Pin
Type
Buffer
Type
RA7
I/O
TTL/DIG
CLKI
CMOS
OSC1
ST
Pin Name
18
19
20
21
RA7/CLKI/OSC1
Note 1:
2:
Digital I/O.
RB0/INT0/FLT0/SRI/SDI/SDA/AN12
RB0
I/O
TTL/DIG
INT0
ST
External interrupt 0.
FLT0
ST
SRI
ST
SR latch input.
SDI
ST
SDA
I/O
I2C
AN12
Analog
RB1/INT1/P1C/SCK/SCL/C12IN3-/AN10
RB1
I/O
TTL/DIG
INT1
ST
External interrupt 1.
P1C
DIG
SCK
I/O
ST/DIG
SCL
I/O
I2C
C12IN3-
Analog
AN10
Analog
RB2/INT2/CTED1/P1B/AN8
RB2
I/O
TTL/DIG
INT2
ST
External interrupt 2.
CTED1
ST
P1B
DIG
AN8
Analog
I/O
TTL/DIG
Analog input 8.
RB3/CTED2/CCP2/SDO/C12IN2-/AN9
RB3
Legend:
Description
CTED2
ST
CCP2(2)
I/O
ST/DIG
SDO(1)
DIG
C12IN2-
Analog
AN9
Analog
Analog input 9.
TTL = TTL compatible input; CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels;
I = Input; O = Output; P = Power.
Default pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are set.
Alternate pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are clear.
DS30000684B-page 15
PIC18(L)F2X/45K50
TABLE 1-2:
Pin Number
SPDIP,
SOIC,
SSOP
QFN
25
22
Pin Name
27
28
11
12
Legend:
Note 1:
2:
23
24
25
Buffer
Type
I/O
TTL/DIG
Description
RB4/IOCB4/P1D/AN11
RB4
26
Pin
Type
IOCB4
TTL
Interrupt-on-change pin.
P1D
DIG
AN11
Analog
RB5/IOCB5/T3CKI/T1G/AN13
RB5
I/O
TTL/DIG
IOCB5
TTL
Interrupt-on-change pin.
T3CKI(2)
ST
T1G
ST
AN13
Analog
RB6/IOCB6/PGC
RB6
I/O
TTL/DIG
IOCB6
TTL
Interrupt-on-change pin.
PGC
I/O
ST
RB7/IOCB7/PGD
RB7
I/O
TTL/DIG
IOCB7
TTL
PGD
I/O
ST/DIG
RC0/IOCC0/T3CKI/T3G/T1CKI/SOSCO
RC0
I/O
ST/DIG
IOCC0
TTL
Interrupt-on-change pin.
Digital I/O.
T3CKI(1)
ST
T3G
ST
T1CKI
ST
SOSCO
RC1/IOCC1/CCP2/SOSCI
RC1
I/O
ST/DIG
IOCC1
TTL
Digital I/O.
CCP2(1)
I/O
ST/DIG
SOSCI
Analog
Interrupt-on-change pin.
TTL = TTL compatible input; CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels;
I = Input; O = Output; P = Power.
Default pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are set.
Alternate pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are clear.
DS30000684B-page 16
PIC18(L)F2X/45K50
TABLE 1-2:
Pin Number
SPDIP,
SOIC,
SSOP
QFN
13
10
Pin Name
15
16
17
18
11
12
13
14
15
26
Buffer
Type
I/O
ST/DIG
Description
RC2/CTPLS/P1A/CCP1/IOCC2/AN14
RC2
14
Pin
Type
Digital I/O.
CTPLS
DIG
P1A
DIG
CCP1
I/O
ST/DIG
IOCC2
TTL
AN14
Analog
VUSB3V3
VUSB3V3
Internal 3.3V voltage regulator output, positive supply
for USB transceiver.
D-/IOCC4
D-
I/O
IOCC4
ST
Interrupt-on-change pin.
D+
I/O
IOCC5
ST
Interrupt-on-change pin.
RC6
I/O
ST/DIG
IOCC6
TTL
D+/IOCC5
RC6/IOCC6/TX/CK/AN18
Digital I/O.
Interrupt-on-change pin.
TX
DIG
CK
I/O
ST
AN18
Analog
RC7/SDO/IOCC7/RX/DT/AN19
RC7
I/O
ST/DIG
SDO(2)
DIG
Digital I/O.
IOCC7
TTL
Interrupt-on-change pin.
RX
ST
DT
I/O
ST/DIG
AN19
Analog
RE3
ST
VPP
MCLR
ST
RE3/VPP/MCLR
Digital input.
Programming voltage input.
Active-Low Master Clear (device Reset) input.
20
17
VDD
8, 19
5, 16
VSS
Legend:
Note 1:
2:
TTL = TTL compatible input; CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels;
I = Input; O = Output; P = Power.
Default pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are set.
Alternate pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are clear.
DS30000684B-page 17
PIC18(L)F2X/45K50
TABLE 1-3:
Pin Number
Pin Name
PDIP
TQFP
UQFN
19
17
14
13
20
21
22
23
24
31
30
19
20
21
22
29
28
Buffer
Type
Description
RA0/C12IN0-/AN0
RA0
I/O
C12IN0-
Analog
AN0
Analog
Analog input 0.
RA1/C12IN1-/AN1
RA1
I/O
C12IN1-
Analog
AN1
Analog
Analog input 1.
RA2/C2IN+/AN2/DACOUT/VREFRA2
I/O
C2IN+
Analog
AN2
Analog
Analog input 2.
DACOUT
Analog
VREF-
Analog
RA3/C1IN+/AN3/VREF+
RA3
I/O
C1IN+
AN3
Analog
Analog input 3.
VREF+
Analog
RA4/C1OUT/SRQ/T0CKI
RA4
I/O
ST/DIG
C1OUT
DIG
Comparator C1 output.
SRQ
TTL
SR latch Q output.
T0CKI
ST
RA5/C2OUT/SRNQ/SS/HLVDIN/AN4
RA5
I/O
C2OUT
DIG
Comparator C2 output.
SRNQ
DIG
SR latch Q output.
SS
TTL
HLVDIN
Analog
AN4
Analog
Analog input 4.
RA6/CLKO/OSC2
RA6
I/O
CLKO
OSC2
RA7/CLKI/OSC1
RA7
I/O
CLKI
OSC1
ST
TTL = TTL compatible input; CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels;
I = Input; O = Output; P = Power.
Legend:
Note
18
Pin
Type
1:
Default pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are set.
2:
Alternate pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are clear.
3:
Pin is No Connect, except on PIC18(L)F45K50 TQFP devices with ICPRT Configuration bit set.
DS30000684B-page 18
PIC18(L)F2X/45K50
TABLE 1-3:
Pin Number
Pin Name
PDIP
TQFP
UQFN
33
34
35
36
37
10
11
14
10
11
12
15
Description
RB0
I/O
INT0
External interrupt 0.
FLT0
ST
SDI
ST
SDA
I/O
I2C
SRI
ST
AN12
Analog
SR latch input.
Analog input 12.
RB1/INT1/P1C/SCK/SCL/C12IN3-/AN10
RB1
I/O
INT1
External interrupt 1.
Enhanced CCP1 PWM output.
P1C
DIG
SCK
I/O
ST/DIG
SCL
I/O
I2C
C12IN3-
Analog
AN10
Analog
RB2/P1B/INT2/CTED1/AN8
RB2
I/O
P1B
INT2
ST
CTED1
ST
AN8
Analog
RB3/CTED2/SDO/CCP2/C12IN2-/AN9
RB3
I/O
CTED2
SDO(1)
DIG
CCP2(2)
I/O
ST
C12IN2-
Analog
AN9
Analog
Analog input 9.
RB4/IOCB4/P1D/AN11
I/O
IOCB4
TTL
Interrupt-on-change pin.
P1D
DIG
AN11
Analog
RB5/IOCB5/T3CKI/T1G/AN13
RB5
I/O
IOCB5
Interrupt-on-change pin.
T3CKI(2)
ST
T1G
ST
AN13
Analog
TTL = TTL compatible input; CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels;
I = Input; O = Output; P = Power.
Legend:
Note
13
Buffer
Type
RB0/INT0/FLT0/SDI/SDA/SRI/AN12
RB4
38
Pin
Type
1:
Default pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are set.
2:
Alternate pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are clear.
3:
Pin is No Connect, except on PIC18(L)F45K50 TQFP devices with ICPRT Configuration bit set.
DS30000684B-page 19
PIC18(L)F2X/45K50
TABLE 1-3:
Pin Number
Pin Name
PDIP
TQFP
UQFN
39
16
14
17
15
16
17
32
35
36
30
31
32
23
24
37
42
43
38
39
TTL
Interrupt-on-change pin.
I/O
ST
RB7/IOCB7/PGD
I/O
IOCB7
TTL
Interrupt-on-change pin.
PGD
I/O
ST
RC0/IOCC0/T3CKI/T3G/T1CKI/SOSCO
RC0
I/O
ST/DIG
Digital I/O.
IOCC0
TTL
Interrupt-on-change pin.
T3CKI(1)
ST
T3G
ST
T1CKI
ST
SOSCO
RC1/IOCC1/CCP2/SOSCI
RC1
I/O
ST/DIG
IOCC1
TTL
Digital I/O.
CCP2(1)
I/O
ST/DIG
SOSCI
Analog
Interrupt-on-change pin.
RC2/CTPLS/P1A/CCP1/IOCC2/AN14
I/O
ST/DIG
Digital I/O.
CTPLS
DIG
P1A
DIG
CCP1
I/O
ST/DIG
IOCC2
TTL
AN14
Analog
VUSB3V3
VUSB3V3
Internal 3.3V voltage regulator output, positive supply for USB
transceiver.
D-/IOCC4
D-
I/O
IOCC4
ST
Interrupt-on-change pin.
D+/IOCC5
D+
I/O
IOCC5
ST
Interrupt-on-change pin.
TTL = TTL compatible input; CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels;
I = Input; O = Output; P = Power.
Legend:
Note
33
I/O
PGC
RC2
18
Description
IOCB6
RB7
15
Buffer
Type
RB6/IOCB6/PGC
RB6
40
Pin
Type
1:
Default pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are set.
2:
Alternate pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are clear.
3:
Pin is No Connect, except on PIC18(L)F45K50 TQFP devices with ICPRT Configuration bit set.
DS30000684B-page 20
PIC18(L)F2X/45K50
TABLE 1-3:
Pin Number
Pin Name
PDIP
TQFP
UQFN
25
44
40
20
21
22
27
28
29
30
38
39
40
41
ST/DIG
35
36
37
Digital I/O.
IOCC6
TTL
TX
CK
I/O
ST
AN18
Analog
Interrupt-on-change pin.
RC7/RX/DT/SDO/IOCC7/AN19
RC7
I/O
ST/DIG
RX
ST
Digital I/O.
DT
I/O
ST
SDO
DIG
IOCC7
TTL
Interrupt-on-change pin.
AN19
Analog
RD0
I/O
ST/DIG
Digital I/O.
AN20
Analog
RD1
I/O
ST/DIG
Digital I/O.
AN21
Analog
RD2
I/O
ST/DIG
Digital I/O
AN22
Analog
RD3
I/O
ST/DIG
Digital I/O.
AN23
Analog
RD4
I/O
ST/DIG
Digital I/O.
AN24
Analog
RD5
I/O
ST/DIG
Digital I/O.
P1B
DIG
AN25
Analog
RD6
I/O
ST/DIG
Digital I/O.
P1C
DIG
AN26
Analog
RD7
I/O
ST/DIG
Digital I/O.
P1D
DIG
AN27
Analog
RD0/AN20
RD1/AN21
RD2/AN22
RD3/AN23
RD4/AN24
RD5/P1B/AN25
Enhanced CCP1 PWM output.
RD6/P1C/AN26
Enhanced CCP1 PWM output.
RD7/P1D/AN27
Enhanced CCP1 PWM output.
Analog input 27.
TTL = TTL compatible input; CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels;
I = Input; O = Output; P = Power.
Legend:
Note
34
Description
I/O
(2)
19
Buffer
Type
RC6/IOCC6/TX/CK/AN18
RC6
26
Pin
Type
1:
Default pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are set.
2:
Alternate pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are clear.
3:
Pin is No Connect, except on PIC18(L)F45K50 TQFP devices with ICPRT Configuration bit set.
DS30000684B-page 21
PIC18(L)F2X/45K50
TABLE 1-3:
Pin Number
Pin
Type
Buffer
Type
RE0
I/O
ST/DIG
Digital I/O.
AN5
Analog
Analog input 5.
RE1
I/O
ST/DIG
Digital I/O.
AN6
Analog
Analog input 6.
Pin Name
PDIP
TQFP
UQFN
25
23
26
10
24
27
25
18
16
12
13
RE0/AN5
RE1/AN6
RE2/AN7
RE2
I/O
ST
AN7
Analog
RE3
ST
VPP
MCLR
ST
ICCK
I/O
ST
ICPGC(3)
I/O
ST
I/O
ST
I/O
ST
Digital input.
Programming voltage input.
ICCK/ICPGC
ICDT/ICPGD
ICPGD
33
Digital I/O.
Analog input 7.
RE3/VPP/MCLR
ICDT
Description
(3)
ICRST/ICVPP
ICRST
ST
ICVPP(3)
11,32
7, 28
7, 26
VDD
12,31
6, 29
6, 27
VSS
34
Note
NC
TTL = TTL compatible input; CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels;
I = Input; O = Output; P = Power.
Legend:
1:
Default pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are set.
2:
Alternate pin assignment for SDO, T3CKI and CCP2 when Configuration bits SDOMX, T3CMX and CCP2MX are clear.
3:
Pin is No Connect, except on PIC18(L)F45K50 TQFP devices with ICPRT Configuration bit set.
DS30000684B-page 22
PIC18(L)F2X/45K50
C2(2)
VDD
R1
R2
MCLR
(1)
VUSB3V3
C1
C7(2)
PIC18F2X/45K50
VDD
VDD
VSS
C3(2)
C6(2)
VDD
RECOMMENDED
MINIMUM CONNECTIONS
VSS
FIGURE 2-1:
VSS
2.1
VDD
2.0
C4(2)
2:
DS30684A-page 23
PIC18(L)F2X/45K50
2.2
2.2.1
2.2.2
TANK CAPACITORS
DS30684A-page 24
2.3
FIGURE 2-2:
VDD
R1
R2
JP
MCLR
PIC18F2X/45K50
C1
Note 1:
R1 10 k is recommended. A suggested
starting value is 10 k. Ensure that the
MCLR pin VIH and VIL specifications are met.
2:
PIC18(L)F2X/45K50
Voltage Regulator Pins (VUSB3V3)
2.4.1
The X5R and X7R capacitors typically exhibit satisfactory temperature stability (ex: 15% over a wide
temperature range, but consult the manufacturers data
sheets for exact specifications). However, Y5V capacitors typically have extreme temperature tolerance
specifications of +22%/-82%. Due to the extreme
temperature tolerance, a 10 F nominal rated Y5V type
capacitor may not deliver enough total capacitance to
meet minimum internal voltage regulator stability and
transient response requirements. Therefore, Y5V
capacitors are not recommended for use with the
internal regulator if the application must operate over a
wide temperature range.
In addition to temperature tolerance, the effective
capacitance of large value ceramic capacitors can vary
substantially, based on the amount of DC voltage
applied to the capacitor. This effect can be very significant, but is often overlooked or is not always
documented.
A typical DC bias voltage vs. capacitance graph for
X7R type and Y5V type capacitors is shown in
Figure 2-3.
FIGURE 2-3:
2.4
10
0
-10
16V Capacitor
-20
-30
-40
10V Capacitor
-50
-60
-70
6.3V Capacitor
-80
0
10
11
12
13
14
15
16
17
DS30684A-page 25
PIC18(L)F2X/45K50
2.5
ICSP Pins
The PGC and PGD pins are used for In-Circuit Serial
Programming (ICSP) and debugging purposes. It is
recommended to keep the trace length between the
ICSP connector and the ICSP pins on the device as
short as possible. If the ICSP connector is expected to
experience an ESD event, a series resistor is recommended, with the value in the range of a few tens of
ohms, not to exceed 100.
Pull-up resistors, series diodes and capacitors on the
PGC and PGD pins are not recommended as they will
interfere with the programmer/debugger communications to the device. If such discrete components are an
application requirement, they should be removed from
the circuit during programming and debugging. Alternatively, refer to the AC/DC characteristics and timing
requirements information in the respective device
Flash programming specification for information on
capacitive loading limits, and pin input voltage high
(VIH) and input low (VIL) requirements.
For device emulation, ensure that the Communication
Channel Select (i.e., PGCx/PGDx pins), programmed
into the device, matches the physical connections for
the ICSP to the Microchip debugger/emulator tool.
For more information on available Microchip
development tools connection requirements, refer to
Section 28.0 Development Support.
2.6
2.7
Unused I/Os
DS30684A-page 26
PIC18(L)F2X/45K50
FIGURE 2-4:
SUGGESTED
PLACEMENT OF THE
OSCILLATOR CIRCUIT
Primary Oscillator
Crystal
DEVICE PINS
Primary
Oscillator
OSC1
C1
OSC2
GND
C2
`
SOSCO
SOSCI
Timer1 Oscillator
Crystal
T1 Oscillator: C1
T1 Oscillator: C2
GND
C1
OSCI
DEVICE PINS
DS30684A-page 27
PIC18(L)F2X/45K50
3.0
3.1
Overview
RC
LP
XT
INTOSC
HS
EC
External Resistor/Capacitor
Low-Power Crystal
Crystal/Resonator
Internal Oscillator
High-Speed Crystal/Resonator
External Clock
PCLKEN (CONFIG1H<5>)
PRISD (OSCCON2<2>)
CFGPLLEN (CONFIG1L<1>)
PLLEN (OSCCON2<4>)
IRCF<2:0> (OSCCON<6:4>)
INTSRC (OSCCON2<5>)
DS30000684B-page 28
PIC18(L)F2X/45K50
FIGURE 3-1:
Secondary Oscillator(1)
SOSCO
Secondary
Oscillator
(SOSC)
SOSCI
Low-Power Mode
Event Switch
(SCS<1:0>)
SOSCOUT
Secondary
Oscillator
PCLKEN
PRISD
PLL_Select
EN
IDLE
(4)
CPU
FOSC<3:0>
Primary
Oscillator(2)
( OSC)
Primary Oscillator
INTOSC
6
3x or
4xPLL
PLL Postscaler
OSC1
01
3
2
1
11
Primary
Clock
10
00
01
00
OSC2
CPUDIV
(3)
Peripherals
RA6
4
CLKO
Enabled Modes
INTOSC
1x
Internal Oscillator
IRCF<2:0>
INTSRC
FSEN
3
1
HFINTOSC
INTOSC
Divide
Circuit
INTRC
USB Module
Clock
Internal Oscillator MUX(3)
(16 MHz)
HF-16 MHZ
HF-8 MHZ
HF-4 MHZ
HF-2 MHZ
HF-1 MHZ
HF-500 kHZ
HF-250 kHZ
HF-31.25 kHZ
1
0
INTOSC
LS48MHZ
LF-31.25 kHz
(31.25 kHz)
Note
1:
2:
3:
4:
The Primary Oscillator MUX uses the INTOSC branch when FOSC<3:0> = 100x.
DS30000684B-page 29
PIC18(L)F2X/45K50
3.2
Oscillator Control
3.2.1
3.2.3
LOW-FREQUENCY SELECTION
3.2.4
POWER MANAGEMENT
3.2.2
INTERNAL FREQUENCY
SELECTION
DS30000684B-page 30
PIC18(L)F2X/45K50
FIGURE 3-2:
INTERNAL OSCILLATOR
MUX BLOCK DIAGRAM
IRCF<2:0>
INTSRC
3
HF-16 MHz
HF-8 MHz
HF-4 MHz
HF-2 MHz
HF-1 MHz
HF-500 kHz
HF-250 kHz
111
110
101
100
011
010
001
INTOSC
HF-31.25 kHz 1
LF-31.25 kHz
TABLE 3-1:
31.25 kHz
000
FOSC<3:0> CFGPLLEN
010x
0010
PLLEN
3xPLL(1)
4xPLL(2)
3xPLL(1)
4xPLL(2)
OFF
OFF
SPLLMULT PLL_Select
100x
xxxx
Note 1:
2:
PLLSEL
DS30000684B-page 31
PIC18(L)F2X/45K50
FIGURE 3-3:
SOSCEN
EN
SOSCOUT
Secondary
Oscillator
SOSCO
T1CKI
T3G
T3CKI
T1CLK_EXT_SRC
SOSCEN
0
T1CON<3>
SOSCEN
T3G
SOSCEN
1
T3CLK_EXT_SRC
0
0
T3CKI
T1G
T3CON<3>
T3CMX
T1G
DS30000684B-page 32
PIC18(L)F2X/45K50
3.3
REGISTER 3-1:
R/W-0
IDLEN
R/W-1
R/W-1
IRCF<2:0>
R-q
R-0
OSTS(1)
HFIOFS
R/W-0
R/W-0
SCS<1:0>
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:
DS30000684B-page 33
PIC18(L)F2X/45K50
REGISTER 3-2:
R-0/0
R-0/q
R/W-0
R/W-0/0
R/W-0/u
R/W-1/1
R-0/0
R-0/0
PLLRDY
SOSCRUN
INTSRC
PLLEN
SOSCGO(1)
PRISD
HFIOFR
LFIOFS
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
q = depends on condition
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1:
DS30000684B-page 34
PIC18(L)F2X/45K50
3.4
3.5.1
TABLE 3-2:
3.5
Switch From
Switch To
Frequency
Oscillator Delay
Sleep/POR
INTRC
HFINTOSC
31.25 kHz
31.25 kHz to 16 MHz
Sleep/POR
EC, RC
DC 48 MHz
2 instruction cycles
EC, RC
DC 48 MHz
1 cycle of each
Sleep/POR
LP, XT, HS
32 kHz to 25 MHz
Sleep/POR
PLL
32 MHz to 48 MHz
INTRC
HFINTOSC
3.5.2
EC MODE
1 s (approx.)
FIGURE 3-4:
Clock from
Ext. System
PIC MCU
I/O
OSC2/CLKO
DS30000684B-page 35
PIC18(L)F2X/45K50
3.5.3
Note 1: Quartz
crystal
characteristics
vary
according to type, package and
manufacturer. The user should consult the
manufacturer data sheets for specifications
and recommended application.
2: Always verify oscillator performance over
the VDD and temperature range that is
expected for the application.
3: For oscillator design assistance, refer to the
following Microchip Application Notes:
AN826, Crystal Oscillator Basics and
Crystal Selection for rfPIC and PIC
Devices (DS00826)
AN849, Basic PIC Oscillator Design
(DS00849)
AN943, Practical PIC Oscillator
Analysis and Design (DS00943)
AN949, Making Your Oscillator Work
(DS00949)
FIGURE 3-5:
FIGURE 3-6:
CERAMIC RESONATOR
OPERATION
(XT OR HS MODE)
QUARTZ CRYSTAL
OPERATION (LP, XT OR
HS MODE)
PIC MCU
OSC1/CLKIN
C1
To Internal
Logic
PIC MCU
RP(3)
OSC1/CLKIN
C1
Sleep
To Internal
Logic
Quartz
Crystal
C2
RF(2)
RS(1)
RF(2)
Sleep
OSC2/CLKO
Note 1:
2:
DS30000684B-page 36
C2 Ceramic
RS(1)
Resonator
OSC2/CLKO
PIC18(L)F2X/45K50
3.5.4
EXTERNAL RC MODES
3.6
3.5.4.1
FIGURE 3-7:
EXTERNAL RC MODES
VDD
PIC MCU
REXT
OSC1/CLKIN
Internal
Clock
CEXT
VSS
FOSC/4 or
I/O(2)
OSC2/CLKO(1)
3.5.4.2
RC Mode
RCIO Mode
2.
3.6.1
DS30000684B-page 37
PIC18(L)F2X/45K50
3.6.1.1
OSCTUNE Register
3.7
REGISTER 3-3:
R/W-0
R/W-0
SPLLMULT
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
TUN<6:0>
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
0000001 =
0000000 = Center frequency. Oscillator module is running at the factory calibrated frequency.
1111111 =
Note 1:
The TUN<6:0> bits may be supplied and controlled by the Active Clock Tuning module (see Section 3.15
Active Clock Tuning (ACT) Module) When the Active Clock Tuning is enabled, the TUN<6:0> bits are
read-only.
DS30000684B-page 38
PIC18(L)F2X/45K50
3.7.1
INTRC
3.7.2
16 MHz
8 MHz
4 MHz
2 MHz
1 MHz (Default after Reset)
500 kHz
250 kHz
31 kHz (INTRC or HFINTOSC)
3.7.3
3.7.3.1
3.7.3.2
3.7.3.3
DS30000684B-page 39
PIC18(L)F2X/45K50
3.8
3.8.1
3.8.2
DS30000684B-page 40
3.9
PIC18(L)F2X/45K50
3.10
Power-up Delays
TABLE 3-3:
OSC Mode
OSC1 Pin
OSC2 Pin
RC with IO
INTOSC with IO
EC with IO
EC with CLKO
LP, XT, HS
Note:
See Table 5-2 in Section 5.0 Reset for time-outs due to Sleep and MCLR Reset.
DS30000684B-page 41
PIC18(L)F2X/45K50
3.11
Clock Switching
3.11.1
3.11.2
Note:
3.11.3
4.
5.
6.
7.
DS30000684B-page 42
PIC18(L)F2X/45K50
3.12
3.12.1
DS30000684B-page 43
PIC18(L)F2X/45K50
3.12.2
1.
2.
3.
4.
5.
6.
TWO-SPEED START-UP
SEQUENCE
3.12.3
FIGURE 3-8:
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.
DS30000684B-page 44
PIC18(L)F2X/45K50
3.13
3.13.3
FIGURE 3-9:
External
Clock
INTRC
Oscillator
64
31 kHz
(~32 s)
488 Hz
(~2 ms)
3.13.1
Note:
Note:
When the device is configured for FailSafe clock monitoring in either HS, XT, or
LS oscillator modes then the IESO configuration bit should also be set so that the
clock will automatically switch from the
internal clock to the external oscillator
when the OST times out.
Clock
Failure
Detected
FAIL-SAFE DETECTION
3.13.2
Any Reset
By toggling the SCS1 bit of the OSCCON register
Sample Clock
3.13.4
FAIL-SAFE OPERATION
DS30000684B-page 45
PIC18(L)F2X/45K50
FIGURE 3-10:
Sample Clock
Oscillator
Failure
System
Clock
Output
Clock Monitor Output
(Q)
Failure
Detected
OSCFIF
Test
Note:
TABLE 3-4:
Name
INTCON
IPR2
OSCCON
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.
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP CCP2IP
124
OSTS
HFIOFS
SCS<1:0>
33
SOSCGO
PRISD
HFIOFR LFIOFS
34
IDLEN
OSCCON2
PLLRDY
OSCTUNE
SPLLMULT
IRCF<2:0>
SOSCRUN INTSRC
PLLEN
TUN<6:0>
38
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE CCP2IE
121
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF CCP2IF
118
Legend: = unimplemented locations, read as 0. Shaded bits are not used by clock sources.
TABLE 3-5:
Name
Bit 6
Bit 5
Bit 4
CONFIG1H
IESO
FCMEN
PCLKEN
CONFIG2L
LPBOR
Bit 3
BORV<1:0>
Bit 2
Bit 1
Bit 0
FOSC<3:0>
BOREN<1:0>
Register
on page
373
PWRTEN
374
Legend: = unimplemented locations, read as 0. Shaded bits are not used for clock sources.
DS30000684B-page 46
PIC18(L)F2X/45K50
3.14
3.14.1
LOW-SPEED OPERATION
TABLE 3-6:
System Clock
CPUDIV<1:0>
Microcontroller Clock
LS48MHZ
USB Clock
48
11
48/6 = 8 MHz
48/8 = 6 MHz
48
10
48/3 = 16 MHz
48/8 = 6 MHz
48
01
48/2 = 24 MHz
48/8 = 6 MHz
48
00
48 MHz
48/8 = 6 MHz
24
11
24/6 = 4 MHz
24/4 = 6 MHz
24
10
24/3 = 8 MHz
24/4 = 6 MHz
24
01
24/2 = 12 MHz
24/4 = 6 MHz
24
00
24 MHz
24/4 = 6 MHz
TABLE 3-7:
Input
Oscillator Frequency
Clock Mode
(FOSC<3:0>)
48 MHz
16 MHz
12 MHz
EC
EC or HS with 4xPLL
24 MHz
Note
EC or HS(1)
Microcontroller
Clock Frequency
6 (11)
8 MHz
3 (10)
16 MHz
2 (01)
24 MHz
None (00)
48 MHz
6 (11)
8 MHz
3 (10)
16 MHz
2 (01)
24 MHz
None (00)
48 MHz
6 (11)
8 MHz
3 (10)
16 MHz
2 (01)
24 MHz
None (00)
48 MHz
6 (11)
4 MHz
3 (10)
8 MHz
2 (01)
12 MHz
None (00)
24 MHz
1: The 24 MHz mode (without PLL) is only compatible with low-speed USB. Full-speed USB requires a 48
MHz system clock.
DS30000684B-page 47
PIC18(L)F2X/45K50
3.15
3.16
FIGURE 3-11:
3.17
3.18
3.19
ACTEN
ACTSRC
FSUSB_clk
SOSC_clk
1
0
ACT_clk
Enable
Active
Clock
Tuning
Module
16 MHz
Internal OSC
ACT data
7
ACTUD
ACTEN
DS30000684B-page 48
sfr data
7
OSCTUNE<6:0>
Write
OSCTUNE
ACTEN
PIC18(L)F2X/45K50
3.20
3.21
Interrupts
3.22
This ACT module does not run during Sleep and will
not generate interrupts during Sleep.
DS30000684B-page 49
PIC18(L)F2X/45K50
3.23
REGISTER 3-4:
R/W-0/0
R/W-0/0
U-0
R/W-0/0
R-0/0
U-0
R-0/0
U-0
ACTEN
ACTUD
ACTSRC(1)
ACTLOCK
ACTORS
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
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
Unimplemented: Read as 0
Note 1:
DS30000684B-page 50
PIC18(L)F2X/45K50
TABLE 3-8:
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
ACTCON
ACTEN
ACTUD
ACTSRC
ACTLOCK
ACTORS
50
OSCCON
IDLEN
OSTS
HFIOFS
OSCTUNE
SPLLMULT
OSCCON2
PLLRDY
Name
IRCF<2:0>
SCS<1:0>
TUN<6:0>
SOSCRUN
INTSRC
PLLEN
SOSCGO
33
38
PRISD
HFIOFR
LFIOFS
34
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
SOSCEN
T1SYNC
RD16
TMR1ON
165
TMR1CS<1:0>
T1CON
Legend:
T1CKPS<1:0>
= unimplemented location, read as 0. Shaded cells are not used by clock sources.
TABLE 3-9:
Name
CONFIG1H
Bit 6
Bit 5
Bit 4
IESO
FCMEN
PCLKEN
Bit 3
Bit 2
Bit 1
FOSC<3:0>
Bit 0
Register
on page
373
DS30000684B-page 51
PIC18(L)F2X/45K50
4.0
4.1.1
POWER-MANAGED MODES
4.1.2
Run modes
Idle modes
Sleep mode
ENTERING POWER-MANAGED
MODES
4.1
CLOCK SOURCES
TABLE 4-1:
POWER-MANAGED MODES
OSCCON Bits
Mode
(1)
IDLEN
Module Clocking
Available Clock and Oscillator Source
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:
DS30000684B-page 52
PIC18(L)F2X/45K50
4.1.3
4.2
Run Modes
4.2.1
PRI_RUN MODE
4.2.2
SEC_RUN MODE
4.2.3
RC_RUN MODE
Note:
DS30000684B-page 53
PIC18(L)F2X/45K50
On transitions from RC_RUN mode to PRI_RUN mode,
the device continues to be clocked from the INTOSC
multiplexer while the primary clock is started. When the
primary clock becomes ready, a clock switch to the primary clock occurs (see Figure 4-3). When the clock
switch is complete, the HFIOFS bit is cleared, the
OSTS bit is set and the primary clock is providing the
device clock. The IDLEN and SCS bits are not affected
by the switch. The INTRC source will continue to run if
either the WDT or the Fail-Safe Clock Monitor is
enabled.
FIGURE 4-1:
Q2
1
SOSCI
n-1
Q3
Q4
Q1
Q2
Q3
Clock Transition(1)
OSC1
CPU
Clock
Peripheral
Clock
Program
Counter
PC
PC + 2
PC + 4
FIGURE 4-2:
Q2
Q3
Q4
Q1
Q2 Q3 Q4 Q1 Q2 Q3
SOSC
OSC1
TOST(1)
TPLL(1)
1
PLL Clock
Output
n-1 n
Clock
Transition(2)
CPU Clock
Peripheral
Clock
Program
Counter
SCS<1:0> bits Changed
PC + 2
PC
PC + 4
Note1: TOST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
2: Clock transition typically occurs within 2-4 TOSC.
DS30000684B-page 54
PIC18(L)F2X/45K50
TABLE 4-2:
IRCF<2:0>
INTSRC
Selected Oscillator
000
INTRC
LFIOFS = 1
000
HFINTOSC
HFIOFS = 1
001-111
HFINTOSC
HFIOFS = 1
FIGURE 4-3:
Q2
Q3
Q4
Q2 Q3 Q4 Q1 Q2 Q3
Q1
INTOSC
Multiplexer
OSC1
TOST(1)
TPLL(1)
1
PLL Clock
Output
n-1 n
Clock
Transition(2)
CPU Clock
Peripheral
Clock
Program
Counter
PC + 2
PC
SCS<1:0> bits Changed
PC + 4
Note1: TOST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
2: Clock transition typically occurs within 2-4 TOSC.
DS30000684B-page 55
PIC18(L)F2X/45K50
4.3
4.3.1
Sleep Mode
REGISTER 4-1:
U-0
U-0
U-0
U-0
U-0
R-0
R/W-0/0
R/W-0/0
VREGPM<1:0>
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
x = Bit is unknown
0 = Bit is cleared
1 = bit is set
Unimplemented: Read as 0
bit 1-0
Note 1:
2:
DS30000684B-page 56
PIC18(L)F2X/45K50
4.4
Idle Modes
FIGURE 4-4:
Q1 Q2 Q3 Q4 Q1
OSC1
CPU
Clock
Peripheral
Clock
Sleep
Program
Counter
PC
FIGURE 4-5:
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.
4.4.1
PRI_IDLE MODE
DS30000684B-page 57
PIC18(L)F2X/45K50
4.4.2
SEC_IDLE MODE
FIGURE 4-6:
Q3
Q2
Q4
Q1
OSC1
CPU Clock
Peripheral
Clock
Program
Counter
PC
FIGURE 4-7:
PC + 2
Q2
Q3
Q4
OSC1
TCSD
CPU Clock
Peripheral
Clock
Program
Counter
PC
Wake Event
DS30000684B-page 58
PIC18(L)F2X/45K50
4.4.3
RC_IDLE MODE
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 bits are set, the HFINTOSC output is enabled.
The HFIOFS bit becomes set after the HFINTOSC
output stabilizes after an interval of TIOBST. For
information on the HFIOFS bit, see Table 4-2.
Clocks to the peripherals continue while the
HFINTOSC source stabilizes. The HFIOFS bit will
remain set if the IRCF bits were previously set at a nonzero value or if INTSRC was set before the SLEEP
instruction was executed and the HFINTOSC source
was already stable. If the IRCF bits and INTSRC are all
clear, the HFINTOSC output will not be enabled, the
HFIOFS 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 INTRC source will
continue to run if either the WDT or the Fail-Safe Clock
Monitor is enabled.
4.5
4.5.1
EXIT BY INTERRUPT
4.5.2
DS30000684B-page 59
PIC18(L)F2X/45K50
4.5.3
EXIT BY RESET
4.5.4
DS30000684B-page 60
4.6
PIC18(L)F2X/45K50
4.7
REGISTER 4-2:
U-0
R/W-0
R/W-0
R/W-0
U-0
R/W-0
R/W-0
R/W-0
UARTMD
USBMD
ACTMD
TMR3MD
TMR2MD
TMR1MD
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
Unimplemented: Read as 0.
bit 6
bit 5
bit 4
bit 3
Unimplemented: Read as 0.
bit 2
bit 1
bit 0
DS30000684B-page 61
PIC18(L)F2X/45K50
REGISTER 4-3:
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
MSSPMD
CTMUMD
CMP2MD
CMP1MD
ADCMD
CCP2MD
CCP1MD
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
Unimplemented: Read as 0
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
DS30000684B-page 62
PIC18(L)F2X/45K50
5.0
RESET
FIGURE 5-1:
5.1
RCON Register
RESET
Instruction
Stack Full/Underflow Reset
Stack
Pointer
External Reset
MCLRE
MCLR
Idle
Sleep
WDT
Time-out
VDD
Detect
POR
VDD
Brown-out
Reset
BOREN
OST/PWRT
OST(2) 1024 Cycles
10-bit Ripple Counter
OSC1
32 s
INTRC
Chip_Reset
R
PWRT(2) 65.5 ms
11-bit Ripple Counter
Enable PWRT
Enable OST(1)
Note 1:
2:
DS30000684B-page 63
PIC18(L)F2X/45K50
5.2
REGISTER 5-1:
R/W-0/0
IPEN
SBOREN
(1)
U-0
R/W-1/q
RI
R-1/q
R-1/q
TO
PD
R/W-q/u
(2)
POR
bit 7
R/W-0/q
BOR
bit 0
Legend:
R = Readable bit
W = Writable bit
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
u = unchanged
q = depends on condition
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.
DS30000684B-page 64
PIC18(L)F2X/45K50
5.3
FIGURE 5-2:
5.4
PIC MCU
R
R1
MCLR
Note 1:
2:
3:
VDD
VDD
EXTERNAL POWER-ON
RESET CIRCUIT (FOR
SLOW VDD POWER-UP)
DS30000684B-page 65
PIC18(L)F2X/45K50
5.5
5.5.1
DETECTING BOR
DS30000684B-page 66
5.5.2
5.5.3
5.5.4
PIC18(L)F2X/45K50
TABLE 5-1:
BOR CONFIGURATIONS
BOR Configuration
Status of
SBOREN
(RCON<6>)
BOR Operation
BOREN1
BOREN0
Unavailable
Available
Unavailable
Unavailable
5.6
5.7
5.7.1
5.7.2
5.7.3
5.7.4
TIME-OUT SEQUENCE
DS30000684B-page 67
PIC18(L)F2X/45K50
TABLE 5-2:
Oscillator
Configuration
HSPLL
PWRTEN = 1
Exit from
Power-Managed Mode
PWRTEN = 0
66 ms
(1)
(2)
+ 1024 TOSC + 2 ms
HS, XT, LP
1024 TOSC
1024 TOSC
(1)
RC, RCIO
66
ms(1)
INTOSC, INTOSCIO
66 ms(1)
EC, ECIO
66 ms
FIGURE 5-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 5-4:
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
DS30000684B-page 68
PIC18(L)F2X/45K50
FIGURE 5-5:
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
FIGURE 5-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
DS30000684B-page 69
PIC18(L)F2X/45K50
FIGURE 5-7:
INTERNAL POR
TPWRT
PWRT TIME-OUT
OST TIME-OUT
TOST
TPLL
PLL TIME-OUT
INTERNAL RESET
Note:
DS30000684B-page 70
PIC18(L)F2X/45K50
5.8
TABLE 5-3:
Condition
RCON Register
SBOREN
RI
TO
PD
STKPTR Register
POR BOR STKFUL
STKUNF
Power-on Reset
0000h
RESET Instruction
0000h
u(2)
0000h
u(2)
0000h
u(2)
0000h
u(2)
0000h
u(2)
0000h
u(2)
0000h
u(2)
0000h
(2)
0000h
u(2)
PC + 2
u(2)
PC + 2(1)
u(2)
Brown-out Reset
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.
TABLE 5-4:
Name
RCON
STKPTR
Bit 6
Bit 5
Bit 4
Bit 3
IPEN
SBOREN
RI
TO
STKFUL
STKUNF
Bit 2
Bit 1
Bit 0
PD
POR
BOR
STKPTR<4:0>
Register
on page
64
76
Legend: = unimplemented locations, read as 0. Shaded bits are not used for Resets.
DS30000684B-page 71
PIC18(L)F2X/45K50
TABLE 5-5:
Bit 6
Bit 5
CONFIG2L
LPBOR
CONFIG3H
MCLRE
SDOMX
T3CMX
PBADEN
CCP2MX
376
CONFIG4L
DEBUG
XINST
ICPRT
LVP
STRVEN
377
CONFIG2H
Bit 4
Bit 3
BORV<1:0>
WDTPS<3:0>
Bit 2
Bit 1
Bit 0
Register
on page
Name
BOREN<1:0>
PWRTEN
WDTEN<1:0>
374
375
Legend: = unimplemented locations, read as 0. Shaded bits are not used for Resets.
DS30000684B-page 72
PIC18(L)F2X/45K50
6.0
MEMORY ORGANIZATION
6.1
FIGURE 6-1:
CALL,RCALL,RETURN
RETFIE,RETLW
Stack Level 1
Stack Level 31
Reset Vector
0000h
0008h
0018h
On-Chip
Program Memory
On-Chip
Program Memory
User Memory Space
3FFFh
4000h
PIC18(L)F24K50
7FFFh
8000h
PIC18(L)F25K50
PIC18(L)F45K50
Read 0
Read 0
1FFFFFh
200000h
DS30000684B-page 73
PIC18(L)F2X/45K50
6.1.1
PROGRAM COUNTER
6.1.2
FIGURE 6-2:
6.1.2.1
Top-of-Stack Access
Top-of-Stack Registers
TOSU
00h
TOSH
1Ah
DS30000684B-page 74
STKPTR<4:0>
00010
TOSL
34h
Top-of-Stack
Stack Pointer
001A34h
000D58h
00011
00010
00001
00000
PIC18(L)F2X/45K50
6.1.2.2
DS30000684B-page 75
PIC18(L)F2X/45K50
6.1.2.3
6.2
The POP instruction discards the current TOS by decrementing the Stack Pointer. The previous value pushed
onto the stack then becomes the TOS value.
REGISTER 6-1:
R/C-0
(1)
STKFUL
STKUNF
U-0
(1)
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
STKPTR<4:0>
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:
6.2.1
6.2.2
DS30000684B-page 76
PIC18(L)F2X/45K50
EXAMPLE 6-1:
RETURN, FAST
SUB1
6.2.3
6.2.3.2
6.2.3.1
Computed GOTO
EXAMPLE 6-2:
ORG
TABLE
MOVF
CALL
nn00h
ADDWF
RETLW
RETLW
RETLW
.
.
.
DS30000684B-page 77
PIC18(L)F2X/45K50
6.3
6.3.2
6.3.1
CLOCKING SCHEME
FIGURE 6-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/CLKO
(RC mode)
Execute INST (PC 2)
Fetch INST (PC)
EXAMPLE 6-3:
1. MOVLW 55h
4. BSF
TCY1
Fetch 1
Execute 1
2. MOVWF PORTB
3. BRA
SUB_1
PORTA, BIT3 (Forced NOP)
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.
DS30000684B-page 78
PIC18(L)F2X/45K50
6.3.3
INSTRUCTIONS IN PROGRAM
MEMORY
FIGURE 6-4:
LSB = 0
0Fh
EFh
F0h
C1h
F4h
55h
03h
00h
23h
56h
Program Memory
Byte Locations
6.3.4
Instruction 1:
Instruction 2:
MOVLW
GOTO
055h
0006h
Instruction 3:
MOVFF
123h, 456h
TWO-WORD INSTRUCTIONS
EXAMPLE 6-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
DS30000684B-page 79
PIC18(L)F2X/45K50
6.4
Note:
6.4.1
USB RAM
DS30000684B-page 80
6.4.2
PIC18(L)F2X/45K50
FIGURE 6-5:
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
Bank 3
Bank 4
Bank 5
Bank 6
Bank 7
Bank 8
Bank 9
Bank 10
Bank 11
Bank 12
1FFh
200h
FFh
00h
GPR
FFh
00h
2FFh
300h
When a = 1:
The BSR specifies the Bank
used by the instruction.
GPR
3FFh
400h
FFh
00h
GPR(2)
4FFh
500h
FFh
00h
GPR(2)
5FFh
600h
FFh
00h
GPR(2)
FFh
00h
Access Bank
6FFh
700h
GPR(2)
FFh
00h
FFh
00h
FFh
00h
FFh
00h
FFh
00h
FFh
Bank 13 00h
Bank 14
GPR
Bank 1
Bank 2
000h
05Fh
060h
0FFh
100h
FFh
00h
FFh
00h
Bank 15
Unimplemented.
Read as 00h.
Unimplemented.
Read as 00h.
Unimplemented.
Read as 00h.
Unimplemented.
Read as 00h.
Unimplemented.
Read as 00h.
Unimplemented.
Read as 00h.
Unimplemented.
Read as 00h.
Unimplemented
SFR(1)
7FFh
800h
8FFh
900h
9FFh
A00h
AFFh
B00h
BFFh
C00h
CFFh
D00h
DFFh
E00h
Note 1:
2:
F00h
F52h
F53h
F5Fh
F60h
SFR
FFh
00h
5Fh
Access RAM High 60h
(SFRs)
FFh
FFFh
DS30000684B-page 81
PIC18(L)F2X/45K50
FIGURE 6-6:
Bank Select(2)
000h
Data Memory
Bank 0
100h
Bank 1
200h
300h
Bank 2
00h
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.
DS30000684B-page 82
PIC18(L)F2X/45K50
6.4.3
ACCESS BANK
6.4.4
6.4.5
DS30000684B-page 83
PIC18(L)F2X/45K50
TABLE 6-1:
Address
Name
Address
Name
Address
FFFh
TOSU
FD7h
TMR0H
FAFh
FFEh
TOSH
FD6h
TMR0L
FFDh
TOSL
FD5h
FFCh
STKPTR
FD4h
Name
Address
Name
Address
Name
SPBRG1
F87h
IOCC
F5Fh
ANSELE(3)
FAEh
RCREG1
F86h
IOCB
F5Eh
ANSELD(3)
T0CON
FADh
TXREG1
F85h
WPUB
F5Dh
ANSELC
(2)
FACh
TXSTA1
F84h
PORTE
F5Ch
ANSELB
F5Bh
ANSELA
F5Ah
VREGCON(4)
FFBh
PCLATU
FD3h
OSCCON
FABh
RCSTA1
F83h
PORTD(3)
FFAh
PCLATH
FD2h
OSCCON2
FAAh
F82h
PORTC
FF9h
PCL
FD1h
WDTCON
FA9h
EEADR
F81h
PORTB
F59h
CCPTMRS
FF8h
TBLPTRU
FD0h
RCON
FA8h
EEDATA
F80h
PORTA
F58h
SRCON0
(1)
FF7h
TBLPTRH
FCFh
TMR1H
FA7h
F7Fh
PMD1
F57h
SRCON1
FF6h
TBLPTRL
FCEh
TMR1L
FA6h
EECON1
F7Eh
PMD0
F56h
FF5h
TABLAT
FCDh
T1CON
FA5h
IPR3
F7Dh
VREFCON0
F55h
FF4h
PRODH
FCCh
T1GCON
FA4h
PIR3
F7Ch
VREFCON1
F54h
FF3h
PRODL
FCBh SSP1CON3
FA3h
PIE3
F7Bh
VREFCON2
F53h
FF2h
INTCON
FCAh
SSP1MSK
FA2h
IPR2
F7Ah
SLRCON
F52h
FF1h
INTCON2
FC9h
SSP1BUF
FA1h
PIR2
F79h
UEP15
F51h
FF0h
INTCON3
FC8h
SSP1ADD
FA0h
PIE2
F78h
UEP14
F50h
FEFh
INDF0(1)
FC7h
SSP1STAT
F9Fh
IPR1
F77h
UEP13
F4Fh
FEEh
POSTINC0(1)
FC6h SSP1CON1
F9Eh
PIR1
F76h
UEP12
F4Eh
FEDh POSTDEC0(1)
EECON2
FC5h SSP1CON2
F9Dh
PIE1
F75h
UEP11
F4Dh
FECh
PREINC0(1)
FC4h
F9Ch
HLVDCON
F74h
UEP10
F4Ch
FEBh
PLUSW0
(1)
FC3h
ADRESL
F9Bh
OSCTUNE
F73h
UEP9
F4Bh
FEAh
FSR0H
FC2h
ADCON0
F9Ah
CM2CON1
F72h
UEP8
F4Ah
FE9h
FSR0L
FC1h
ADCON1
F99h
CM2CON0
F71h
UEP7
F49h
FE8h
WREG
FC0h
ADCON2
F98h
CM1CON0
F70h
UEP6
F48h
F47h
(1)
ADRESH
FBFh
CCPR1H
F97h
CCP2CON
F6Fh
UEP5
FE6h POSTINC1(1)
FBEh
CCPR1L
F96h
TRISE(3)
F6Eh
UEP4
General
F46h Purpose RAM
FE5h POSTDEC1(1)
FBDh
CCP1CON
F95h
TRISD(3)
F6Dh
UEP3
F45h
FBCh
TMR2
F94h
TRISC
F6Ch
UEP2
F44h
FE7h
INDF1
FE4h
PREINC1(1)
FE3h
PLUSW1(1)
FBBh
PR2
F93h
TRISB
F6Bh
UEP1
F43h
FE2h
FSR1H
FBAh
T2CON
F92h
TRISA
F6Ah
UEP0
F42h
FE1h
FSR1L
FB9h PSTR1CON
F91h
CCPR2H
F69h
UFRMH
F41h
FE0h
BSR
FB8h BAUDCON1
F90h
CCPR2L
F68h
UFRML
F40h
FDFh
INDF2(1)
FB7h PWM1CON
F8Fh
CTMUCONH
F67h
UEIR
F3Fh
FDEh POSTINC2(1)
FB6h
ECCP1AS
F8Eh
CTMUCONL
F66h
UEIE
F3Eh
FDDh POSTDEC2(1)
FB5h
STCON
F8Dh
LATE(3)
F65h
UIR
F3Dh
FB4h
T3GCON
F8Ch
LATD(3)
F64h
UIE
F3Ch
FDCh
PREINC2(1)
(1)
FDBh
PLUSW2
FB3h
TMR3H
F8Bh
LATC
F63h
UADDR
F3Bh
FDAh
FSR2H
FB2h
TMR3L
F8Ah
LATB
F62h
UCNFG
F3Ah
FD9h
FSR2L
FB1h
T3CON
F89h
LATA
F61h
USTAT
F39h
FD8h
STATUS
FB0h
SPBRGH1
F60h
UCTRL
F38h
Note 1:
2:
3:
4:
F88h CTMUICONH
DS30000684B-page 84
PIC18(L)F2X/45K50
TABLE 6-2:
Address
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
FFFh
TOSU
FFEh
TOSH
FFDh
TOSL
FFCh
STKPTR
STKFUL
STKUNF
STKPTR<4:0>
00-0 0000
FFBh
PCLATU
---0 0000
FFAh
PCLATH
FF9h
PCL
FF8h
TBLPTRU
FF7h
TBLPTRH
0000 0000
FF6h
TBLPTRL
0000 0000
FF5h
TABLAT
0000 0000
FF4h
PRODH
xxxx xxxx
FF3h
PRODL
FF2h
INTCON
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
FF1h
INTCON2
RBPU
INTEDG0
INTEDG1
INTEDG2
TMR0IP
IOCIP
1111 -1-1
FF0h
INTCON3
INT2IP
INT1IP
INT2IE
INT1IE
INT2IF
INT1IF
11-0 0-00
---0 0000
0000 0000
0000 0000
0000 0000
0000 0000
--00 0000
xxxx xxxx
0000 000x
FEFh
INDF0
Uses contents of FSR0 to address data memory value of FSR0 not changed (not a physical register)
---- ----
FEEh
POSTINC0
Uses contents of FSR0 to address data memory value of FSR0 post-incremented (not a physical register)
---- ----
FEDh
POSTDEC0
Uses contents of FSR0 to address data memory value of FSR0 post-decremented (not a physical register)
---- ----
FECh
PREINC0
Uses contents of FSR0 to address data memory value of FSR0 pre-incremented (not a physical register)
---- ----
FEBh
PLUSW0
Uses contents of FSR0 to address data memory value of FSR0 pre-incremented (not a physical register)
value of FSR0 offset by W
---- ----
FEAh
FSR0H
FE9h
FSR0L
xxxx xxxx
FE8h
WREG
Working Register
xxxx xxxx
FE7h
INDF1
Uses contents of FSR1 to address data memory value of FSR1 not changed (not a physical register)
---- ----
FE6h
POSTINC1
Uses contents of FSR1 to address data memory value of FSR1 post-incremented (not a physical register)
---- ----
FE5h
POSTDEC1
Uses contents of FSR1 to address data memory value of FSR1 post-incremented (not a physical register)
---- ----
FE4h
PREINC1
Uses contents of FSR1 to address data memory value of FSR1 pre-incremented (not a physical register)
---- ----
FE3h
PLUSW1
Uses contents of FSR1 to address data memory value of FSR1 pre-incremented (not a physical register)
value of FSR1 offset by W
---- ----
FE2h
FSR1H
FE1h
FSR1L
FE0h
BSR
FDFh
INDF2
Uses contents of FSR2 to address data memory value of FSR2 not changed (not a physical register)
---- ----
FDEh
POSTINC2
Uses contents of FSR2 to address data memory value of FSR2 post-incremented (not a physical register)
---- ----
FDDh
POSTDEC2
Uses contents of FSR2 to address data memory value of FSR2 post-decremented (not a physical register)
---- ----
FDCh
PREINC2
Uses contents of FSR2 to address data memory value of FSR2 pre-incremented (not a physical register)
---- ----
FDBh
PLUSW2
Uses contents of FSR2 to address data memory value of FSR2 pre-incremented (not a physical register)
value of FSR2 offset by W
---- ----
FDAh
FSR2H
FD9h
FSR2L
FD8h
STATUS
FD7h
TMR0H
FD6h
TMR0L
FD5h
T0CON
FD3h
OSCCON
IDLEN
FD2h
OSCCON2
PLLRDY
FD1h
WDTCON
FD0h
RCON
Legend:
Note 1:
2:
---- 0000
TMR0ON
T08BIT
---- 0000
xxxx xxxx
OV
DC
---x xxxx
0000 0000
xxxx xxxx
T0CS
T0SE
IRCF<2:0>
SOSCRUN
---- 0000
xxxx xxxx
---- 0000
INTSRC
PLLEN
PSA
T0PS<2:0>
OSTS
HFIOFS
SOSCGO
PRISD
1111 1111
SCS<1:0>
HFIOFR
LFIOFS
0011 q000
0000 0100
SWDTEN
---- ---0
IPEN
SBOREN
RI
TO
PD
POR
BOR
01-1 1100
DS30000684B-page 85
PIC18(L)F2X/45K50
TABLE 6-2:
Address
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
FCFh
TMR1H
Holding Register for the Most Significant Byte of the 16-bit TMR1 Register
xxxx xxxx
FCEh
TMR1L
Holding Register for the Least Significant Byte of the 16-bit TMR1 Register
xxxx xxxx
FCDh
T1CON
FCCh
T1GCON
SOSCEN
T1SYNC
TMR1GE
TMR1CS<1:0>
T1GPOL
T1GTM
T1CKPS<1:0>
T1GSPM
T1GGO/
DONE
T1GVAL
FCBh
SSP1CON3
FCAh
SSP1MSK
ACKTIM
PCIE
SCIE
BOEN
SDAHT
SBCDE
1111 1111
FC9h
SSP1BUF
xxxx xxxx
FC8h
SSP1ADD
SSP1 Address Register in I2C Slave Mode. SSP1 Baud Rate Reload Register in I2C Master Mode
FC7h
SSP1STAT
SMP
FC6h
SSP1CON1
FC5h
SSP1CON2
FC4h
ADRESH
FC3h
ADRESL
FC2h
ADCON0
CKE
D/A
WCOL
SSPOV
SSPEN
CKP
GCEN
ACKSTAT
ACKDT
ACKEN
R/W
RCEN
PEN
RD16
TMR1ON
T1GSS<1:0>
AHEN
DHEN
0000 0000
0000 0x00
0000 0000
0000 0000
UA
BF
RSEN
SEN
SSPM<3:0>
0000 0000
0000 0000
0000 0000
xxxx xxxx
xxxx xxxx
CHS<4:0>
GO/DONE
ADON
-000 0000
FC1h
ADCON1
TRIGSEL
FC0h
ADCON2
ADFM
FBFh
CCPR1H
FBEh
CCPR1L
FBDh
CCP1CON
FBCh
TMR2
Timer2 Register
FBBh
PR2
FBAh
T2CON
FB9h
PSTR1CON
STR1SYNC
STR1D
STR1C
STR1B
STR1A
---0 0001
FB8h
BAUDCON1
ABDOVF
RCIDL
RXDTP
TXCKP
BRG16
WUE
ABDEN
0100 0-00
FB7h
PWM1CON
P1RSEN
FB6h
ECCP1AS
ECCP1ASE
FB5h
ACTCON
ACTEN
ACTUD
ACTSRC
ACTLOCK
FB4h
T3GCON
TMR3GE
T3GPOL
T3GTM
T3GSPM
T3GGO/
DONE
T3GVAL
FB3h
TMR3H
Holding Register for the Most Significant Byte of the 16-bit TMR3 Register
FB2h
TMR3L
Holding Register for the Least Significant Byte of the 16-bit TMR3 Register
FB1h
T3CON
FB0h
SPBRGH1
0000 0000
FAFh
SPBRG1
0000 0000
FAEh
RCREG1
0000 0000
FADh
TXREG1
FACh
TXSTA1
CSRC
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
0000 0010
FABh
RCSTA1
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
0000 000x
FA9h
EEADR
EEADR<7:0>
0000 0000
FA8h
EEDATA
0000 0000
FA7h
EECON2
FA6h
EECON1
FA5h
PVCFG<1:0>
NVCFG<1:0>
ACQT<2:0>
P1M<1:0>
ADCS<2:0>
0--- 0000
0-00 0000
xxxx xxxx
xxxx xxxx
DC1B<1:0>
CCP1M<3:0>
0000 0000
0000 0000
1111 1111
T2OUTPS<3:0>
TMR2ON
T2CKPS<1:0>
P1DC<6:0>
ECCP1AS<2:0>
TMR3CS<1:0>
0000 0000
PSS1AC<1:0>
T3CKPS<1:0>
SOSCEN
-000 0000
PSS1BD<1:0>
T3SYNC
ACTORS
T3GSS<1:0>
0000 0000
00-0 0-00000 0x00
xxxx xxxx
xxxx xxxx
RD16
TMR3ON
0000 0000
0000 0000
---- ----
EEPGD
CFGS
FREE
WRERR
WREN
WR
RD
xx-0 x000
IPR3
CTMUIP
USBIP
TMR3GIP
TMR1GIP
0000 1111
FA4h
PIR3
CTMUIF
USBIF
TMR3GIF
TMR1GIF
0000 0000
FA3h
PIE3
CTMUIE
USBIE
TMR3GIE
TMR1GIE
0000 0000
FA2h
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
1111 1111
FA1h
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
0000 0000
FA0h
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
0000 0000
Legend:
Note 1:
2:
DS30000684B-page 86
PIC18(L)F2X/45K50
TABLE 6-2:
Address
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
F9Fh
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
1111 1111
F9Eh
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
F9Dh
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
0000 0000
F9Ch
HLVDCON
VDIRMAG
BGVST
IRVST
HLVDEN
F9Bh
OSCTUNE
SPLLMULT
F9Ah
CM2CON1
MC1OUT
MC2OUT
C1RSEL
C2RSEL
C1HYS
C2HYS
F99h
CM2CON0
C2ON
C2OUT
C2OE
C2POL
C2SP
C2R
C2CH<1:0>
F98h
CM1CON0
C1ON
C1OUT
C1OE
C1POL
C1SP
C1R
C1CH<1:0>
F97h
CCP2CON
F96h
TRISE
WPUE3
TRISE2(1)
TRISE1(1)
TRISE0(1)
1--- -111
F95h
TRISD(1)
TRISD7
TRISD6
TRISD5
TRISD4
TRISD3
TRISD2
TRISD1
TRISD0
1111 1111
F94h
TRISC
TRISC7
TRISC6
TRISC2
TRISC1
TRISC0
1111 -111
F93h
TRISB
TRISB7
TRISB6
TRISB5
TRISB4
TRISB3
TRISB2
TRISB1
TRISB0
1111 1111
F92h
TRISA
TRISA7
TRISA6
TRISA5
TRISA4
TRISA3
TRISA2
TRISA1
TRISA0
1111 1111
F91h
CCPR2H
F90h
CCPR2L
F8Fh
CTMUCONH
CTMUEN
F8Eh
CTMUCONL
EDG2POL
EDG2SEL<1:0>
F8Dh
LATE(1)
LATE2
LATE1
LATE0
F8Ch
LATD(1)
LATD7
LATD6
LATD5
LATD4
LATD3
LATD2
LATD1
LATD0
xxxx xxxx
F8Bh
LATC
LATC7
LATC6
LATC2
LATC1
LATC0
xxxx -xxx
F8Ah
LATB
LATB7
LATB6
LATB5
LATB4
LATB3
LATB2
LATB1
LATB0
xxxx xxxx
F89h
LATA
LATA7
LATA6
LATA5
LATA4
LATA3
LATA2
LATA1
LATA0
xxxx xxxx
F88h
CTMUICON
F87h
IOCC
IOCC7
IOCC6
IOCC5
IOCC4
IOCC2
IOCC1
IOCC0
0000 -000
F86h
IOCB
IOCB7
IOCB6
IOCB5
IOCB4
0000 ----
F85h
WPUB
WPUB7
WPUB6
WPUB5
WPUB4
WPUB3
WPUB2
WPUB1
WPUB0
1111 1111
PORTE(2)
RE3
---- x---
PORTE(1)
RE3
RE2
RE1
RE0
---- xxxx
F84h
HLVDL<3:0>
0000 0000
TUN<6:0>
0000 0000
DC2B<1:0>
CTMUSIDL
C1SYNC
C2SYNC
CCP2M<3:0>
0000 0000
0000 1000
0000 1000
--00 0000
xxxx xxxx
xxxx xxxx
TGEN
EDG1POL
EDGEN
EDGSEQEN
EDG1SEL<1:0>
IDISSEN
CTTRIG
EDG2STAT EDG1STAT
ITRIM<5:0>
IRNG<1:0>
0-00 0000
0000 00xx
---- -xxx
0000 0000
F83h
PORTD(1)
RD7
RD6
RD5
RD4
RD3
RD2
RD1
RD0
xxxx xxxx
F82h
PORTC
RC7
RC6
RC2
RC1
RC0
xx-- -xxx
F81h
PORTB
RB7
RB6
RB5
RB4
RB3
RB2
RB1
RB0
xxxx xxxx
F80h
PORTA
RA7
RA6
RA5
RA4
RA3
RA2
RA1
RA0
xxxx xxxx
F7Fh
PMD1
MSSPMD
CTMUMD
CMP2MD
CMP1MD
ADCMD
CCP2MD
CCP1MD
-000 0000
F7Eh
PMD0
UARTMD
USBMD
ACTMD
TMR3MD
TMR2MD
TMR1MD
-000 -000
F7Dh
VREFCON0
FVREN
FVRST
0001 00--
F7Ch
VREFCON1
DACEN
DACLPS
DACOE
DACNSS
000- 00-0
FVRS<1:0>
DACPSS<1:0>
F7Bh
VREFCON2
F7Ah
SLRCON
SLRE
SLRD
SLRC
SLRB
SLRA
---1 1111
F79h
UEP15
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
F78h
UEP14
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
F77h
UEP13
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
F76h
UEP12
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
F75h
UEP11
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
F74h
UEP10
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
F73h
UEP9
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
F72h
UEP8
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
F71h
UEP7
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
F70h
UEP6
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
Legend:
Note 1:
2:
DACR<4:0>
---0 0000
DS30000684B-page 87
PIC18(L)F2X/45K50
TABLE 6-2:
Address
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
F6Fh
UEP5
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
F6Eh
UEP4
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
F6Dh
UEP3
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
F6Ch
UEP2
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
F6Bh
UEP1
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
---0 0000
F6Ah
UEP0
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL
F69h
UFRMH
FRM<10:8>
---0 0000
---- -xxx
F68h
UFRML
F67h
UEIR
BTSEF
BTOEF
FRM<7:0>
DFN8EF
CRC16EF
CRC5EF
PIDEF
F66h
UEIE
BTSEE
BTOEE
DFN8EE
CRC16EE
CRC5EE
PIDEE
0--0 0000
F65h
UIR
SOFIF
STALLIF
IDLEIF
TRNIF
ACTVIF
UERRIF
URSTIF
-000 0000
F64h
UIE
SOFIE
STALLIE
IDLEIE
TRNIE
ACTVIE
UERRIE
URSTIE
-000 0000
F63h
UADDR
F62h
UCFG
UTEYE
F61h
USTAT
F60h
UCON
PPBRST
SE0
PKTDIS
F5Fh
ANSELE
F5Eh
ANSELD
ANSD7
ANSD6
ANSD5
F5Dh
ANSELC
ANSC7
ANSC6
F5Ch
ANSELB
F5Bh
ANSELA
F5Ah
VREGCON
F59h
CCPTMRS
F58h
SRCON0
SRLEN
F57h
SRCON1
SRSPE
SRSCKE
SRSC2E
xxxx xxxx
ADDR<6:0>
UOEMON
UPUEN
UTRDIS
ENDP<3:0>
0--0 0000
-000 0000
FSEN
PPB<1:0>
00-0 0000
DIR
PPBI
USBEN
RESUME
SUSPND
-0x0 000-
ANSE2
ANSE1
ANSE0
---- -111
ANSD4
ANSD3
ANSD2
ANSD1
ANSD0
1111 1111
ANSC2
11-- -1--
ANSB5
ANSB4
ANSB3
ANSB2
ANSB1
ANSB0
--11 1111
ANSA5
ANSA3
ANSA2
ANSA1
ANSA0
--1- 1111
VREGPM<1:0>
---- --01
C2TSEL
C1TSEL
---- 0--0
SRQEN
SRNQEN
SRPS
SRPR
0000 0000
SRSC1E
SRRPE
SRRCKE
SRRC2E
SRRC1E
0000 0000
SRCLK<2:0>
-xxx xxx-
F56h
---- ----
F55h
---- ----
F54h
---- ----
F53h
---- ----
Legend:
Note 1:
2:
DS30000684B-page 88
PIC18(L)F2X/45K50
6.4.6
STATUS REGISTER
6.5
REGISTER 6-2:
U-0
U-0
U-0
R/W-x
N
R/W-x
OV
R/W-x
Z
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:
2:
For Digit 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 bit 4 or bit 3 of the source
register.
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.
DS30000684B-page 89
PIC18(L)F2X/45K50
6.6
Note:
Inherent
Literal
Direct
Indirect
6.6.3
6.6.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 6-5:
NEXT
6.6.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 6.4.4 General
Purpose Register File) or a location in the Access
Bank (Section 6.4.3 Access Bank) as the data
source for the instruction.
DS30000684B-page 90
PIC18(L)F2X/45K50
6.6.3.1
6.6.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 6-7:
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
E00h
Bank 14
F00h
FFFh
Bank 15
Data Memory
DS30000684B-page 91
PIC18(L)F2X/45K50
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.
6.6.3.3
6.7
6.7.1
6.7.2
INSTRUCTIONS AFFECTED BY
INDEXED LITERAL OFFSET MODE
DS30000684B-page 92
PIC18(L)F2X/45K50
FIGURE 6-8:
000h
060h
Bank 0
100h
00h
Bank 1
through
Bank 14
F00h
60h
Valid range
for f
Access RAM
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
Data Memory
DS30000684B-page 93
PIC18(L)F2X/45K50
6.7.3
6.8
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.
FIGURE 6-9:
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
Bank 1
00h
Bank 1 Window
5Fh
60h
Bank 2
through
Bank 14
SFRs
FFh
Access Bank
F00h
Bank 15
F60h
FFFh
SFRs
Data Memory
DS30000684B-page 94
PIC18(L)F2X/45K50
7.0
7.1
FIGURE 7-1:
Program Memory
Table Pointer(1)
TBLPTRU
TBLPTRH
TABLAT
Program Memory
(TBLPTR)
DS30000684B-page 95
PIC18(L)F2X/45K50
FIGURE 7-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 7.6 Writing to Flash Program Memory.
7.2
Control Registers
EECON1 register
EECON2 register
TABLAT register
TBLPTR registers
7.2.1
DS30000684B-page 96
PIC18(L)F2X/45K50
7.3
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.
DS30000684B-page 97
PIC18(L)F2X/45K50
7.3.1
7.3.2
7.3.3
TABLE 7-1:
Example
TBLRD*
TBLWT*
TBLRD*+
TBLWT*+
TBLRD*TBLWT*-
TBLRD+*
TBLWT+*
FIGURE 7-3:
21
16
TBLPTRH
15
TABLE ERASE/WRITE
TBLPTR<21:n+1>(1)
TBLPTRL
TABLE WRITE
TBLPTR<n:0>(1)
DS30000684B-page 98
PIC18(L)F2X/45K50
7.4
FIGURE 7-4:
Program Memory
TBLPTR = xxxxx1
Instruction Register
(IR)
EXAMPLE 7-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
DS30000684B-page 99
PIC18(L)F2X/45K50
7.5
7.5.1
3.
4.
5.
6.
7.
8.
EXAMPLE 7-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
DS30000684B-page 100
EEPGD
CFGS
WREN
FREE
GIE
; write 55h
WR
GIE
; write 0AAh
; start erase (CPU stall)
; re-enable interrupts
PIC18(L)F2X/45K50
The programming block size is 64 bytes. Word or byte
programming is not supported.
7.6
FIGURE 7-5:
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 = 3Fh for 64 byte write blocks.
7.6.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. 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 7-3.
Note:
DS30000684B-page 101
PIC18(L)F2X/45K50
EXAMPLE 7-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
DS30000684B-page 102
;
;
;
;
PIC18(L)F2X/45K50
EXAMPLE 7-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
7.6.2
; write 55h
;
;
;
;
;
;
WRITE VERIFY
UNEXPECTED TERMINATION OF
WRITE OPERATION
TABLE 7-2:
Name
TBLPTRU
write 0AAh
start program (CPU stall)
repeat for remaining write blocks
re-enable interrupts
disable write to memory
7.6.4
7.6.3
PROTECTION AGAINST
SPURIOUS WRITES
7.7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
TBPLTRH
TBLPTRL
TABLAT
INTCON
EECON2
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
EECON1
EEPGD
CFGS
FREE
WRERR
WREN
WR
RD
97
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
124
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
118
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
121
PIE2
Legend:
= unimplemented, read as 0. Shaded bits are not used during Flash/EEPROM access.
DS30000684B-page 103
PIC18(L)F2X/45K50
8.0
EECON1
EECON2
EEDATA
EEADR
8.1
EEADR Register
8.2
DS30000684B-page 104
PIC18(L)F2X/45K50
REGISTER 8-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.
DS30000684B-page 105
PIC18(L)F2X/45K50
8.3
8.4
8.5
EXAMPLE 8-1:
MOVLW
MOVWF
BCF
BCF
BSF
MOVF
EXAMPLE 8-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
DS30000684B-page 106
PIC18(L)F2X/45K50
8.6
8.7
8.8
EXAMPLE 8-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
;
;
;
;
;
;
;
;
;
;
;
;
;
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
DS30000684B-page 107
PIC18(L)F2X/45K50
TABLE 8-1:
Name
Bit 6
INTCON
GIE/GIEH
PEIE/GIEL
EEADR
EEADR7
EEADR6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
EEDATA
EECON2
EECON1
EEPGD
CFGS
FREE
WRERR
WREN
WR
RD
105
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
124
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
118
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
121
Legend: = unimplemented, read as 0. Shaded bits are not used during EEPROM access.
DS30000684B-page 108
PIC18(L)F2X/45K50
9.0
8 x 8 HARDWARE MULTIPLIER
9.1
Introduction
9.2
EXAMPLE 9-1:
MOVF
MULWF
ARG1, W
ARG2
EXAMPLE 9-2:
MOVF
MULWF
ARG1, W
ARG2
BTFSC
SUBWF
ARG2, SB
PRODH, F
MOVF
BTFSC
SUBWF
ARG2, W
ARG1, SB
PRODH, F
8 x 8 UNSIGNED
MULTIPLY ROUTINE
;
; ARG1 * ARG2 ->
; PRODH:PRODL
8 x 8 SIGNED MULTIPLY
ROUTINE
;
;
;
;
;
Operation
TABLE 9-1:
Routine
8 x 8 unsigned
8 x 8 signed
16 x 16 unsigned
16 x 16 signed
Multiply Method
Program
Memory
(Words)
13
69
5.7 s
6.9 s
27.6 s
69 s
Hardware multiply
83.3 ns
100 ns
400 ns
1 s
33
91
7.5 s
9.1 s
36.4 s
91 s
Hardware multiply
500 ns
600 ns
2.4 s
6 s
21
242
20.1 s
24.2 s
96.8 s
242 s
Hardware multiply
28
28
2.3 s
2.8 s
11.2 s
28 s
52
254
21.6 s
25.4 s
102.6 s
254 s
Hardware multiply
35
40
3.3 s
4.0 s
16.0 s
40 s
DS30000684B-page 109
PIC18(L)F2X/45K50
Example 9-3 shows the sequence to do a 16 x 16
unsigned multiplication. Equation 9-1 shows the
algorithm that is used. The 32-bit result is stored in four
registers (RES<3:0>).
EQUATION 9-1:
RES3:RES0
=
=
16 x 16 UNSIGNED
MULTIPLICATION
ALGORITHM
ARG1H:ARG1L ARG2H:ARG2L
(ARG1H ARG2H 216) +
(ARG1H ARG2L 28) +
(ARG1L ARG2H 28) +
(ARG1L ARG2L)
EXAMPLE 9-3:
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
;
;
; ARG1H * ARG2H->
; PRODH:PRODL
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
ARG1L * ARG2H->
PRODH:PRODL
Add cross
products
ARG1H * ARG2L->
PRODH:PRODL
Add cross
products
EQUATION 9-2:
16 x 16 SIGNED
MULTIPLICATION
ALGORITHM
EXAMPLE 9-4:
16 x 16 SIGNED
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
BTFSS
BRA
MOVF
SUBWF
MOVF
SUBWFB
ARG2H, 7
SIGN_ARG1
ARG1L, W
RES2
ARG1H, W
RES3
; ARG2H:ARG2L neg?
; no, check ARG1
;
;
;
SIGN_ARG1
BTFSS
BRA
MOVF
SUBWF
MOVF
SUBWFB
ARG1H, 7
CONT_CODE
ARG2L, W
RES2
ARG2H, W
RES3
; ARG1H:ARG1L neg?
; no, done
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
CONT_CODE
:
DS30000684B-page 110
PIC18(L)F2X/45K50
10.0
INTERRUPTS
10.1
Mid-Range Compatibility
10.2
Interrupt Priority
10.3
Interrupt Response
DS30000684B-page 111
PIC18(L)F2X/45K50
Note:
FIGURE 10-1:
INT0IF
INT0IE
PIR1<7:0>
PIE1<7:0>
IPR1<7:0>
PIR2<7:0>
PIE2<7:0>
IPR2<7:0>
PIR3<7:0>
PIE3<7:0>
IPR3<7:0>
TMR0IF
TMR0IE
TMR0IP
IOCIF
IOCIE
IOCIP
INT1IF
INT1IE
INT1IP
INT2IF
INT2IE
INT2IP
(1)
Interrupt to CPU
Vector to Location
0008h
GIEH/GIE
IPEN
IPEN
GIEL/PEIE
IPEN
Interrupt to CPU
Vector to Location
0018h
TMR0IF
TMR0IE
TMR0IP
IOCIF
IOCIE
IOCIP
(1)
GIEH/GIE
GIEL/PEIE
INT1IF
INT1IE
INT1IP
INT2IF
INT2IE
INT2IP
Note
1:
The IOCIF interrupt also requires the individual pin IOCB enables.
DS30000684B-page 112
PIC18(L)F2X/45K50
10.4
INTCON Registers
10.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 three Peripheral Interrupt
Request Flag registers (PIR1, PIR2 and PIR3).
10.6
PIE Registers
10.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 three Peripheral Interrupt
Priority registers (IPR1, IPR2 and IPR3). Using the priority
bits requires that the Interrupt Priority Enable (IPEN) bit be
set.
DS30000684B-page 113
PIC18(L)F2X/45K50
10.8
REGISTER 10-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
IOCIE
TMR0IF
INT0IF
IOCIF
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:
Note:
A mismatch condition will continue to set the IOCIF bit. Reading PORTB/PORTC will end the
mismatch condition and allow the bit to be cleared.
Port change interrupts also require the individual pins IOCBx/IOCCx enables.
DS30000684B-page 114
PIC18(L)F2X/45K50
REGISTER 10-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
IOCIP
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:
DS30000684B-page 115
PIC18(L)F2X/45K50
REGISTER 10-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
x = Bit is unknown
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:
DS30000684B-page 116
PIC18(L)F2X/45K50
REGISTER 10-4:
R/W-0
R/W-0
R-0
R-0
R/W-0
R/W-0
R/W-0
R/W-0
ACTIF
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
DS30000684B-page 117
PIC18(L)F2X/45K50
REGISTER 10-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
DS30000684B-page 118
PIC18(L)F2X/45K50
REGISTER 10-6:
U-0
U-0
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
CTMUIF
USBIF
TMR3GIF
TMR1GIF
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-4
Unimplemented: Read as 0
bit 3
bit 2
bit 1
bit 0
x = Bit is unknown
DS30000684B-page 119
PIC18(L)F2X/45K50
REGISTER 10-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
ACTIE
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
DS30000684B-page 120
x = Bit is unknown
PIC18(L)F2X/45K50
REGISTER 10-8:
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
x = Bit is unknown
DS30000684B-page 121
PIC18(L)F2X/45K50
REGISTER 10-9:
U-0
U-0
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
CTMUIE
USBIE
TMR3GIE
TMR1GIE
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-4
Unimplemented: Read as 0
bit 3
bit 2
bit 1
bit 0
DS30000684B-page 122
x = Bit is unknown
PIC18(L)F2X/45K50
REGISTER 10-10: IPR1: PERIPHERAL INTERRUPT PRIORITY REGISTER 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
ACTIP
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
DS30000684B-page 123
PIC18(L)F2X/45K50
REGISTER 10-11: IPR2: PERIPHERAL INTERRUPT PRIORITY REGISTER 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
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
DS30000684B-page 124
x = Bit is unknown
PIC18(L)F2X/45K50
REGISTER 10-12: IPR3: PERIPHERAL INTERRUPT PRIORITY REGISTER 3
U-0
U-0
U-0
U-0
R/W-1
R/W-1
R/W-1
R/W-1
CTMUIP
USBIP
TMR3GIP
TMR1GIP
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-4
Unimplemented: Read as 0
bit 3
bit 2
bit 1
bit 0
x = Bit is unknown
DS30000684B-page 125
PIC18(L)F2X/45K50
10.9
EXAMPLE 10-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
DS30000684B-page 126
; Restore BSR
; Restore WREG
; Restore STATUS
PIC18(L)F2X/45K50
TABLE 10-1:
Name
ANSELB
INTCON
Bit 6
GIE/GIEH PEIE/GIEL
INTCON2
RBPU
INTEDG0
INTCON3
INT2IP
INT1IP
Bit 2
Bit 1
Bit 0
Register
on page
ANSB3
ANSB2
ANSB1
ANSB0
148
IOCIE
TMR0IF
INT0IF
IOCIF
114
Bit 5
Bit 4
Bit 3
ANSB5
ANSB4
TMR0IE
INT0IE
INTEDG1 INTEDG2
TMR0IP
IOCIP
115
INT2IE
INT1IE
INT2IF
INT1IF
116
IOCB
IOCB7
IOCB6
IOCB5
IOCB4
151
IOCC
IOCC7
IOCC6
IOCC5
IOCC4
IOCC2
IOCC1
IOCC0
151
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
124
IPR3
CTMUIP
USBIP
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
PIE3
CTMUIE
USBIE
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
118
PIR3
PORTB
RCON
Legend:
TMR3GIP TMR1GIP
125
TMR2IE
TMR1IE
120
TMR3IE
CCP2IE
121
TMR3GIE TMR1GIE
122
CTMUIF
USBIF
TMR3GIF
TMR1GIF
119
RB7
RB6
RB5
RB4
RB3
RB2
RB1
RB0
146
IPEN
SBOREN
RI
TO
PD
POR
BOR
64
= unimplemented locations, read as 0. Shaded bits are not used for interrupts.
TABLE 10-2:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
CONFIG3H
MCLRE
SDOMX
T3CMX
PBADEN
CCP2MX
376
CONFIG4L
DEBUG
XINST
ICPRT
LVP
STRVEN
377
Legend:
= unimplemented locations, read as 0. Shaded bits are not used for interrupts.
DS30000684B-page 127
PIC18(L)F2X/45K50
11.0
I/O PORTS
11.1
FIGURE 11-1:
RD LAT
Data
Bus
WR LAT
or Port
Q
I/O pin(1)
CK
Data Latch
D
WR TRIS
ANSELx
CK
TRIS Latch
Input
Buffer
RD TRIS
PORTA Registers
ENEN
EXAMPLE 11-1:
RD Port
Note 1:
MOVLB
CLRF
CLRF
MOVLW
MOVWF
DS30000684B-page 128
0xF
LATA
;
;
;
;
ANSELA ;
;
0CFh
;
;
;
TRISA
;
;
INITIALIZING PORTA
Set BSR for banked SFRs
Initialize PORTA by
clearing 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
PIC18(L)F2X/45K50
TABLE 11-1:
Pin Name
Function
RA0/C12IN0-/AN0
RA0
RA1/C12IN1-/AN1
RA2/C2IN+/AN2/
DACOUT/VREF-
RA3/C1IN+/AN3/
VREF+
RA4/C1OUT/SRQ/
T0CKI
RA5/C2OUT/
SRNQ/SS1/
HLVDIN/AN4
RA6/CLKO/OSC2
Legend:
TRIS ANSEL
Setting Setting
Pin
Type
Buffer
Type
Description
DIG
TTL
C12IN0-
AN
AN0
AN
Analog input 0.
RA1
DIG
TTL
C12IN1-
AN
AN1
AN
Analog input 1.
RA2
DIG
TTL
C2IN+
AN
AN2
AN
Analog output 2.
DACOUT
AN
VREF-
AN
RA3
DIG
TTL
C1IN+
AN
AN3
AN
Analog input 3.
VREF+
AN
RA4
DIG
ST
C1OUT
DIG
Comparator C1 output.
SR latch Q output; take priority over CCP 5 output.
SRQ
DIG
T0CKI
ST
RA5
DIG
TTL
C2OUT
DIG
Comparator C2 output.
SRNQ
DIG
SR latch Q output.
SS1
TTL
HLVDIN
AN
AN4
AN
A/D input 4.
RA6
DIG
TTL
CLKO
DIG
In RC mode, OSC2 pin outputs CLKO which has 1/4 the frequency of OSC1 and denotes the instruction cycle rate.
OSC2
XTAL
AN = Analog input or output; TTL = TTL compatible input; HV = High Voltage; OD = Open Drain; XTAL = Crystal; CMOS
= CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels; I2C = Schmitt Trigger input with
I2C.
DS30000684B-page 129
PIC18(L)F2X/45K50
TABLE 11-1:
Pin Name
Function
RA7/CLKI/OSC1
Legend:
TRIS ANSEL
Setting Setting
RA7
Pin
Type
Buffer
Type
Description
DIG
TTL
CLKI
AN
OSC1
XTAL
AN = Analog input or output; TTL = TTL compatible input; HV = High Voltage; OD = Open Drain; XTAL = Crystal; CMOS
= CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels; I2C = Schmitt Trigger input with
I2C.
TABLE 11-2:
Name
ANSELA
CM1CON0
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
C1ON
C1OUT
ANSA5
ANSA3
ANSA2
ANSA1
ANSA0
C1OE
C1POL
C1SP
C1R
C2SP
C2R
CM2CON0
C2ON
C2OUT
C2OE
C2POL
VREFCON1
DACEN
DACLPS
DACOE
VREFCON2
HLVDCON
PORTA
VDIRMAG
BGVST
IRVST
DACPSS<1:0>
147
C1CH<1:0>
307
C2CH<1:0>
307
DACNSS
DACR<4:0>
HLVDEN
Register
on page
334
335
HLVDL<3:0>
364
RA7
RA6
RA5
RA4
RA3
RA2
RA1
RA0
146
LATA7
LATA6
LATA5
LATA4
LATA3
LATA2
LATA1
LATA0
150
SLRCON
SLRE
SRCON0
SRLEN
LATA
SSP1CON1
SRCLK<2:0>
SLRD
SLRC
SLRB
SLRA
152
SRQEN
SRNQEN
SRPS
SRPR
328
WCOL
SSPOV
SSPEN
CKP
T0CON
TMR0ON
T08BIT
T0CS
T0SE
PSA
SSPM<3:0>
TRISA
TRISA7
TRISA6
TRISA5
TRISA4
TRISA3
252
T0PS<2:0>
TRISA2
TRISA1
153
TRISA0
149
Bit 0
Register
on page
Legend: = unimplemented locations, read as 0. Shaded bits are not used for PORTA.
TABLE 11-3:
Name
Bit 7
Bit 6
Bit 5
Bit 4
CONFIG1H
IESO
FCMEN
PCLKEN
Bit 3
Bit 2
Bit 1
FOSC<3:0>
373
Legend: = unimplemented locations, read as 0. Shaded bits are not used for PORTA.
DS30000684B-page 130
PIC18(L)F2X/45K50
11.1.1
DS30000684B-page 131
PIC18(L)F2X/45K50
TABLE 11-4:
Port bit
0
PORTA
PORTB
PORTC
RA0
SDA
SOSCO
PORTD(2)
PORTE(2)
RD0
RE0
RB0
RC0
1
RA1
SCL
SOSCI
SCK
CCP2(3)
(1)
RB1
2
DACOUT
RA2
RE1
RD1
P1C
RC1
CCP1
P1B(1)
P1A
RB2
CTPLS
RD2
RE2
RC2
3
RA3
SDO(3)
MCLR
CCP2(4)
RD3
VPP
RE3
RB3
4
SRQ
P1D(1)
C1OUT
RB4
DRD4
RA4
5
SRNQ
D+
C2OUT
P1B
RD5
RA5
RB5
6
OSC2
PGC
TX/CK
CLKO
ICDCK
P1C
RA6
RB6
RD6
OSC1
PGD
RA7
ICDDT
RC6
7
RB7
Note 1:
2:
3:
4:
RX/DT
P1D
RC7
RD7
PIC18(L)F2XK50 devices.
PIC18(L)F45K50 devices.
Function default pin.
Function alternate pin.
DS30000684B-page 132
PIC18(L)F2X/45K50
11.2
PORTB Registers
EXAMPLE 11-2:
MOVLB
CLRF
MOVLW
MOVWF
MOVLW
MOVWF
11.2.1
0xF
LATB
;
;
;
;
0F0h
;
ANSELB ;
;
;
;
0CFh
;
;
;
TRISB
;
;
;
INITIALIZING PORTB
Set BSR for banked SFRs
Initialize PORTB by
clearing output
data latches
Value for init
Enable RB<3:0> for
digital input pins
(not required if config bit
PBADEN is clear)
Value used to
initialize data
direction
Set RB<3:0> as inputs
RB<5:4> as outputs
RB<7:6> as inputs
11.3
11.3.1
WEAK PULL-UPS
11.3.2
INTERRUPT-ON-CHANGE
b)
Any read or write of PORTB to clear the mismatch condition (except when PORTB is the
source or destination of a MOVFF instruction).
Execute at least one instruction after reading or
writing PORTB, then clear the flag bit, IOCIF.
DS30000684B-page 133
PIC18(L)F2X/45K50
11.3.3
Note:
ALTERNATE FUNCTIONS
TABLE 11-5:
Pin
Function
RB0/INT0/FLT0/
SRI/SDA/SDI/AN12
RB0
Buffer
Type
Description
DIG
TTL
INT0
ST
External interrupt 0.
FLT0
ST
SRI
ST
SDA
I/O
I2C
SR latch input.
I2C Data I/O (MSSP).
SDI
ST
AN
RB1
DIG
TTL
INT1
ST
External Interrupt 1.
P1C(3)
DIG
SCK
DIG
ST
DIG
SCL
Note 1:
2:
3:
Pin
Type
AN12
RB1/INT1/P1C/
SCK/SCL/C12IN3-/
AN10
Legend:
TRIS ANSEL
Setting Setting
I C
C12IN3-
AN
AN10
AN
AN = Analog input or output; TTL = TTL compatible input; HV = High Voltage; OD = Open Drain; XTAL = Crystal;
CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels; I2C = Schmitt Trigger input with
I2C.
Default pin assignment for SDO when Configuration bit SDOMX is set.
Alternate pin assignment for T3CKI and CCP2 when Configuration bits T3CMX and CCP2MX are clear.
Function is on PORTD/PORTE for PIC18(L)F45K50 devices.
DS30000684B-page 134
PIC18(L)F2X/45K50
TABLE 11-5:
Pin
Function
RB2/INT2/CTED1/
P1B/AN8
RB2
RB3/CTED2/CCP2/
SDO/C12IN2-/AN9
RB4/IOCB4/P1D/
AN11
RB5/IOCB5/T3CKI/
T1G/AN13
RB6/IOCB6/PGC
RB7/IOCB7/PGD
Legend:
Note 1:
2:
3:
TRIS ANSEL
Setting Setting
Pin
Type
Buffer
Type
Description
DIG
TTL
INT2
ST
CTED1
ST
P1B(3)
DIG
AN8
AN
Analog input 8.
RB3
DIG
TTL
CTED2
ST
CCP2(2)
DIG
ST
Capture 2 input.
SDO(1)
DIG
C12IN2-
AN
AN9
AN
Analog input 9.
RB4
DIG
TTL
IOCB4
TTL
Interrupt-on-change pin.
P1D(3)
DIG
AN11
AN
RB5
DIG
TTL
IOCB5
TTL
Interrupt-on-change pin 1.
T3CKI(2)
ST
T1G
ST
AN13
AN
RB6
DIG
TTL
IOCB6
TTL
Interrupt-on-change pin.
PGC
ST
RB7
DIG
TTL
IOCB7
TTL
Interrupt-on-change pin.
PGD
DIG
ST
AN = Analog input or output; TTL = TTL compatible input; HV = High Voltage; OD = Open Drain; XTAL = Crystal;
CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels; I2C = Schmitt Trigger input with
I2C.
Default pin assignment for SDO when Configuration bit SDOMX is set.
Alternate pin assignment for T3CKI and CCP2 when Configuration bits T3CMX and CCP2MX are clear.
Function is on PORTD/PORTE for PIC18(L)F45K50 devices.
DS30000684B-page 135
PIC18(L)F2X/45K50
TABLE 11-6:
Name
ANSELB
ECCP1AS
Bit 6
ECCP1ASE
CCP1CON
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
ANSB5
ANSB4
ANSB3
ANSB2
ANSB1
ANSB0
ECCP1AS<2:0>
P1M<1:0>
PSS1AC<1:0>
PSS1BD<1:0>
DC1B<1:0>
CCP1M<3:0>
DC2B<1:0>
CCP2M<3:0>
Register
on page
148
201
197
INTCON
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
INTCON2
RBPU
INTEDG0
INTEDG1
INTEDG2
TMR0IP
IOCIP
115
INTCON3
INT2IP
INT1IP
INT2IE
INT1IE
INT2IF
INT1IF
116
IOCB
IOCB7
IOCB6
IOCB5
IOCB4
151
LATB
LATB7
LATB6
LATB5
LATB4
LATB3
LATB2
LATB1
LATB0
150
RB7
RB6
RB5
RB4
RB3
RB2
RB1
RB0
146
SLRC
SLRB
SLRA
152
CCP2CON
PORTB
SLRCON
T1GCON
TMR1GE
T1GPOL
T1GTM
T3CON
TMR3CS<1:0>
TRISB
WPUB
Legend:
Note 1:
T1GSPM
T3CKPS<1:0>
(1)
SLRD
T1GGO/DONE
T1GVAL
T1GSS<1:0>
SOSCEN
T3SYNC
RD16
TMR3ON
165
166
TRISB7
TRISB6
TRISB5
TRISB4
TRISB3
TRISB2
TRISB1
TRISB0
149
WPUB7
WPUB6
WPUB5
WPUB4
WPUB3
WPUB2
WPUB1
WPUB0
150
= unimplemented locations, read as 0. Shaded bits are not used for PORTB.
Available on PIC18(L)F45K50 devices only.
TABLE 11-7:
Name
Bit 6
CONFIG3H
MCLRE
CONFIG4L
DEBUG
Legend:
Note 1:
SLRE
(1)
197
Bit 5
Bit 4
Bit 3
SDOMX
T3CMX
XINST
ICPRT
Register
on page
Bit 2
Bit 1
Bit 0
PBADEN
CCP2MX
376
LVP(1)
STRVEN
377
= unimplemented locations, read as 0. Shaded bits are not used for PORTB.
Can only be changed when in high voltage programming mode.
DS30000684B-page 136
PIC18(L)F2X/45K50
11.4
PORTC Registers
11.4.1
11.4.2
INTERRUPT-ON-CHANGE
EXAMPLE 11-3:
MOVLB
CLRF
MOVLW
MOVWF
MOVLW
MOVWF
0xF
LATC
;
;
;
;
0CFh
;
;
;
TRISC
;
;
;
30h
;
;
ANSELC ;
;
;
INITIALIZING PORTC
Set BSR for banked SFRs
Initialize PORTC by
clearing 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
Value used to
enable digital inputs
RC<3:2> dig input enable
No ANSEL bits for RC<1:0>
RC<7:6> dig input enable
DS30000684B-page 137
PIC18(L)F2X/45K50
TABLE 11-8:
Pin Name
RC0/IOCC0/T3CKI/
T3G/T1CKI/SOSCO
Function
TRIS
Setting
ANSEL
setting
Pin
Type
Buffer
Type
Description
RC0
DIG
ST
TTL
Interrupt-on-change pin.
T3CKI(1)
ST
T3G
ST
IOCC0
RC1/IOCC1/CCP2/
SOSCI
T1CKI
ST
SOSCO
XTAL
RC1
DIG
ST
TTL
Interrupt-on-change pin.
DIG
ST
Capture 2 input.
SOSCI
XTAL
RC2
DIG
ST
IOCC1
CCP2
RC2/CTPLS/P1A/
CCP1/IOCC2/AN14
(1)
DIG
P1A
DIG
CCP1
DIG
ST
Capture 1 input.
TTL
Interrupt-on-change pin.
Analog input 14.
AN14
AN
D-
XCVR
XCVR
ST
XCVR
XCVR
ST
IOCC4
D+/IOCC5
D+
IOCC5
Legend:
Note 1:
2:
3:
CTPLS
IOCC2
D-/IOCC4
Interrupt-on-change pin.
USB bus differential minus line input.
USB bus differential minus line output.
Interrupt-on-change pin.
AN = Analog input or output; TTL = TTL compatible input; HV = High Voltage; OD = Open Drain; XTAL = Crystal;
CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels; I2C = Schmitt Trigger input
with I2C.
Default pin assignment for T3CKI and CCP2 when Configuration bits T3CMX and CCP2MX are set.
Alternate pin assignment for SDO when Configuration bit SDOMX is clear.
Function is on PORTD/PORTE for PIC18(L)F45K50 devices.
DS30000684B-page 138
PIC18(L)F2X/45K50
TABLE 11-8:
Pin Name
RC6/IOCC6/TX/CK/
AN18
Function
TRIS
Setting
ANSEL
setting
Pin
Type
Buffer
Type
Description
RC6
DIG
ST
TTL
Interrupt-on-change pin.
IOCC6
RC7/IOCC7/SDO/RX/
DT/AN19
Legend:
Note 1:
2:
3:
TX
DIG
CK
DIG
ST
AN18
AN
RC7
DIG
ST
IOCC7
TTL
Interrupt-on-change pin.
SDO(2)
DIG
RX
ST
DT
DIG
ST
AN19
AN
AN = Analog input or output; TTL = TTL compatible input; HV = High Voltage; OD = Open Drain; XTAL = Crystal;
CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels; I2C = Schmitt Trigger input
with I2C.
Default pin assignment for T3CKI and CCP2 when Configuration bits T3CMX and CCP2MX are set.
Alternate pin assignment for SDO when Configuration bit SDOMX is clear.
Function is on PORTD/PORTE for PIC18(L)F45K50 devices.
DS30000684B-page 139
PIC18(L)F2X/45K50
TABLE 11-9:
Name
ANSELC
ECCP1AS
Bit 6
ANSC7
ANSC6
ECCP1ASE
CCP1CON
Bit 5
Bit 4
Bit 3
Bit 2
ANSC2
ECCP1AS<2:0>
P1M<1:0>
Bit 1
Bit 0
Register
on page
148
PSS1AC<1:0>
PSS1BD<1:0>
DC1B<1:0>
CCP1M<3:0>
DC2B<1:0>
CCP2M<3:0>
201
197
CTMUEN
CTMUSIDL
TGEN
EDGEN
LATC7
LATC6
PORTC
RC7
RC6
RC2
RC1
RC0
146
RCSTA1
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
269
SLRCON
SLRE(1)
SLRD(1)
SLRC
SLRB
SLRA
152
WCOL
SSPOV
SSPEN
CKP
CCP2CON
CTMUCONH
LATC
SSP1CON1
197
EDGSEQEN IDISSEN
LATC2
LATC1
CTTRIG
322
LATC0
150
SSPM<3:0>
252
T1CON
TMR1CS<1:0>
T1CKPS<1:0>
SOSCEN
T1SYNC
RD16
TMR1ON
165
T3CON
TMR3CS<1:0>
T3CKPS<1:0>
SOSCEN
T3SYNC
RD16
TMR3ON
165
T3GCON
TRISC
TXSTA1
Legend:
Note 1:
TMR3GE
T3GPOL
T3GTM
T3GSPM T3GGO/DONE
T3GVAL
T3GSS
TRISC7
TRISC6
TRISC2
TRISC1
TRISC0
166
149
CSRC
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
268
= unimplemented locations, read as 0. Shaded bits are not used for PORTC.
Available on PIC18(L)F45K50 devices only.
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
MCLRE
SDOMX
T3CMX
PBADEN
CCP2MX
376
= unimplemented locations, read as 0. Shaded bits are not used for PORTC.
DS30000684B-page 140
PIC18(L)F2X/45K50
11.5
Note:
PORTD Registers
PORTD is only available on 40-pin and
44-pin devices.
11.5.1
EXAMPLE 11-4:
MOVLB
CLRF
MOVLW
MOVWF
MOVLW
MOVWF
0xF
LATD
;
;
;
;
0CFh
;
;
;
TRISD
;
;
;
30h
;
;
ANSELD ;
;
INITIALIZING PORTD
Set BSR for banked SFRs
Initialize PORTD by
clearing 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
Value used to
enable digital inputs
RD<3:0> dig input enable
RC<7:6> dig input enable
DS30000684B-page 141
PIC18(L)F2X/45K50
TABLE 11-11: PORTD I/O SUMMARY
Pin Name
RD0/AN20
RD0
RD1/AN21
RD2/AN22
RD3/AN23
RD4/AN24
RD5/P1B/AN25
RD6/P1C/AN26
RD7/P1D/AN27
Legend:
Function
Description
DIG
ST
AN20
AN
RD1
DIG
ST
AN21
AN
RD2
DIG
ST
AN22
AN
RD3
DIG
ST
AN23
AN
RD4
DIG
ST
AN24
AN
RD5
DIG
ST
P1B
DIG
AN25
AN
RD6
DIG
ST
P1C
DIG
AN26
AN
RD7
DIG
ST
P1D
DIG
AN27
AN
AN = Analog input or output; TTL = TTL compatible input; HV = High Voltage; OD = Open Drain; XTAL = Crystal;
CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels; I2C = Schmitt Trigger input
with I2C.
DS30000684B-page 142
PIC18(L)F2X/45K50
TABLE 11-12: REGISTERS ASSOCIATED WITH PORTD
Name
ANSELD(1)
CCP1CON
LATD(1)
PORTD(1)
(1)
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register on
page
ANSD7
ANSD6
ANSD5
ANSD4
ANSD3
ANSD2
ANSD1
ANSD0
148
P1M<1:0>
DC1B<1:0>
197
LATD7
LATD6
LATD5
LATD4
LATD3
LATD2
LATD1
LATD0
150
RD7
RD6
RD5
RD4
RD3
RD2
RD1
RD0
146
SLRD
SLRC
SLRB
SLRA
SLRE
SSP1CON1
WCOL
SSPOV
SSPEN
CKP
TRISD(1)
TRISD7
TRISD6 TRISD5
SLRCON
CCP1M<3:0>
TRISD4
SSPM<3:0>
TRISD3
TRISD2
TRISD1
152
252
TRISD0
149
Legend: = unimplemented locations, read as 0. Shaded bits are not used for PORTD.
Note 1: Available on PIC18(L)F45K50 devices only.
DS30000684B-page 143
PIC18(L)F2X/45K50
11.6
PORTE Registers
11.6.1
The fourth pin of PORTE (MCLR/VPP/RE3) is an inputonly pin. Its operation is controlled by the MCLRE
Configuration bit. When selected as a port pin
(MCLRE = 0), it functions as a digital input-only pin; as
such, it does not have TRIS or LAT bits associated with its
operation. Otherwise, it functions as the devices Master
Clear input. In either configuration, RE3 also functions as
the programming voltage input during programming.
Note:
EXAMPLE 11-5:
CLRF
CLRF
MOVLW
MOVWF
LATE
;
;
;
ANSELE ;
;
05h
;
;
;
TRISE
;
;
;
11.6.2
11.6.3
11.6.4
INITIALIZING PORTE
Initialize PORTE by
clearing 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
DS30000684B-page 144
PIC18(L)F2X/45K50
TABLE 11-13: PORTE I/O SUMMARY
Pin
Function
RE0/AN5
RE0
RE1/AN6
RE2/AN7
RE3/VPP/MCLR
Legend:
Buffer
Type
Description
DIG
ST
AN5
AN
Analog input 5.
RE1
DIG
ST
AN6
AN
Analog input 6.
RE2
DIG
ST
AN7
AN
Analog input 7.
RE3
ST
VPP
AN
MCLR
ST
AN = Analog input or output; TTL = TTL compatible input; HV = High Voltage; OD = Open Drain; XTAL = Crystal;
CMOS = CMOS compatible input or output; ST = Schmitt Trigger input with CMOS levels; I2C = Schmitt Trigger input
with I2C.
Bit 7
ANSELE(1)
INTCON2
RBPU
Bit 6
Bit 5
INTEDG0 INTEDG1
Bit 2
Bit 1
Bit 0
Register
on page
ANSE2
ANSE1
ANSE0
149
TMR0IP
IOCIP
115
Bit 4
Bit 3
INTEDG2
(1)
LATE
LATE2
LATE1
LATE0
150
PORTE
RE3
RE2(1)
RE1(1)
RE0(1)
147
SLRCON
SLRE(1)
SLRD(1)
SLRC
SLRB
SLRA
152
TRISE
WPUE3
(1)
TRISE2
TRISE1
(1)
TRISE0
(1)
149
Legend: = unimplemented locations, read as 0. Shaded bits are not used for PORTE.
Note 1: Available on PIC18(L)F45K50 devices only.
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
CONFIG3H
MCLRE
SDOMX
T3CMX
CONFIG4L
DEBUG
XINST
(1)
LVP
Bit 1
Bit 0
PBADEN CCP2MX
STRVEN
Register
on page
376
377
Legend: = unimplemented locations, read as 0. Shaded bits are not used for interrupts.
Note 1: Can only be changed when in high-voltage programming mode.
DS30000684B-page 145
PIC18(L)F2X/45K50
11.7
11.8
11.9
REGISTER 11-1:
R/W-u/x
R/W-u/x
R/W-u/x
R/W-u/x
R/W-u/x
R/W-u/x
R/W-u/x
R/W-u/x
Rx7
Rx6
Rx5
Rx4
Rx3
Rx2
Rx1
Rx0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS30000684B-page 146
PIC18(L)F2X/45K50
REGISTER 11-2:
U-0
U-0
U-0
U-0
R/W-u/x
R/W-u/x
R/W-u/x
R/W-u/x
RE3(1)
RE2(2), (3)
RE1(2), (3)
RE0(2), (3)
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
Unimplemented: Read as 0
bit 3
bit 2-0
Note 1:
2:
3:
REGISTER 11-3:
U-0
U-0
R/W-1
U-0
R/W-1
R/W-1
R/W-1
R/W-1
ANSA5
ANSA3
ANSA2
ANSA1
ANSA0
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
Unimplemented: Read as 0
bit 3-0
x = Bit is unknown
DS30000684B-page 147
PIC18(L)F2X/45K50
REGISTER 11-4:
U-0
U-0
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
ANSB5
ANSB4
ANSB3
ANSB2
ANSB1
ANSB0
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-0
REGISTER 11-5:
x = Bit is unknown
R/W-1
R/W-1
U-0
U-0
U-0
R/W-1
U-0
U-0
ANSC7
ANSC6
ANSC2
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-3
Unimplemented: Read as 0
bit 2
bit 1-0
Unimplemented: Read as 0
REGISTER 11-6:
x = Bit is unknown
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
ANSD7
ANSD6
ANSD5
ANSD4
ANSD3
ANSD2
ANSD1
ANSD0
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
DS30000684B-page 148
PIC18(L)F2X/45K50
REGISTER 11-7:
U-0
U-0
U-0
U-0
U-0
R/W-1
R/W-1
R/W-1
ANSE2(1)
ANSE1(1)
ANSE0(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-3
Unimplemented: Read as 0
bit 2-0
Note 1:
x = Bit is unknown
REGISTER 11-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
TRISx7
TRISx6
TRISx5
TRISx4
TRISx3
TRISx2
TRISx1
TRISx0
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
Note 1:
x = Bit is unknown
REGISTER 11-9:
R/W-1
WPUE3
U-0
U-0
U-0
R/W-1
TRISE2
(1)
R/W-1
(1)
TRISE1
R/W-1
TRISE0(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
bit 6-3
Unimplemented: Read as 0
bit 2-0
Note 1:
x = Bit is unknown
DS30000684B-page 149
PIC18(L)F2X/45K50
REGISTER 11-10: LATx: PORTx OUTPUT LATCH REGISTER(1)
R/W-x/u
R/W-x/u
R/W-x/u
R/W-x/u
R/W-x/u
R/W-x/u
R/W-x/u
R/W-x/u
LATx7
LATx6
LATx5
LATx4
LATx3
LATx2
LATx1
LATx0
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
Note 1:
2:
x = Bit is unknown
U-0
U-0
U-0
U-0
R/W-x/u
R/W-x/u
R/W-x/u
LATE2
LATE1
LATE0
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-3
Unimplemented: Read as 0
bit 2-0
Note 1:
2:
x = Bit is unknown
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
WPUB7
WPUB6
WPUB5
WPUB4
WPUB3
WPUB2
WPUB1
WPUB0
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
DS30000684B-page 150
PIC18(L)F2X/45K50
REGISTER 11-13: IOCB: INTERRUPT-ON-CHANGE PORTB CONTROL REGISTER
R/W-0
R/W-0
R/W-0
R/W-0
U-0
U-0
U-0
U-0
IOCB7
IOCB6
IOCB5
IOCB4
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-4
bit 3-0
Unimplemented: Read as 0
Note 1:
x = Bit is unknown
R/W-0
R/W-0
R/W-0
U-0
R/W-0
R/W-0
R/W-0
IOCC7
IOCC6
IOCC5
IOCC4
IOCC2
IOCC1
IOCC0
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-4
bit 3
Unimplemented: Read as 0
bit 2-0
Note 1:
x = Bit is unknown
DS30000684B-page 151
PIC18(L)F2X/45K50
REGISTER 11-15: SLRCON: SLEW RATE CONTROL REGISTER
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
DS30000684B-page 152
PIC18(L)F2X/45K50
12.0
TIMER0 MODULE
12.1
REGISTER 12-1:
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
TMR0ON
T08BIT
T0CS
T0SE
PSA
R/W-1
R/W-1
R/W-1
TOPS<2:0>
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
DS30000684B-page 153
PIC18(L)F2X/45K50
12.2
Timer0 Operation
12.3
FIGURE 12-1:
0
1
1
T0CKI pin
T0SE
T0CS
T0PS<2:0>
PSA
Note:
Programmable
Prescaler
Sync with
Internal
Clocks
TMR0L
Set
TMR0IF
on Overflow
(2 TCY Delay)
8
3
8
Upon Reset, Timer0 is enabled in 8-bit mode with clock input from T0CKI max. prescale.
DS30000684B-page 154
PIC18(L)F2X/45K50
FIGURE 12-2:
FOSC/4
0
1
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.4
Upon Reset, Timer0 is enabled in 8-bit mode with clock input from T0CKI max. prescale.
12.4.1
Prescaler
TABLE 12-1:
Name
INTCON
INTCON2
T0CON
12.5
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
T08BIT
T0CS
TMR0L
Bit 4
Bit 3
INT0IE
TMR0H
TRISA
SWITCHING PRESCALER
ASSIGNMENT
TRISA6
TRISA5
T0SE
Bit 0
Register
on page
INT0IF
IOCIF
114
IOCIP
115
Bit 2
Bit 1
IOCIE
TMR0IF
TMR0IP
PSA
T0PS<2:0>
153
TRISA4
TRISA3
TRISA2
TRISA1
TRISA0
149
Legend: = unimplemented locations, read as 0. Shaded bits are not used by Timer0.
DS30000684B-page 155
PIC18(L)F2X/45K50
13.0
FIGURE 13-1:
TxGSS<1:0>
TxG
00
Timer2 Match
PR2
01
TxGSPM
0
TxG_IN
TxGVAL
sync_C1OUT(7)
Single Pulse
10
sync_C2OUT(7)
CK
R
11
TMRxON
Acq. Control
Q1
Data Bus
D
Q
RD
TXGCON
EN
Interrupt
TxGGO/DONE
Set
TMRxGIF
det
TxGTM
TxGPOL
TMRxGE
Set flag bit
TMRxIF on
Overflow
TMRxON
To Comparator Module
TMRx(2),(4)
TMRxH
EN
TMRxL
TxCLK
Synchronized
clock input
1
Secondary
Oscillator
Module
See Figure 2-4
TMRxCS<1:0>
Reserved
1
(5) ,(6)
TxCKI
Note
TxCLK_EXT_SRC
(1)
0
SOSCEN
TxSYNC
SOSCOUT
11
Synchronize(3),(7)
Prescaler
1, 2, 4, 8
det
10
2
TxCKPS<1:0>
FOSC
Internal
Clock
01
FOSC/4
Internal
Clock
00
FOSC/2
Internal
Clock
Sleep input
1:
2:
3:
4:
5:
6:
7:
Synchronized comparator output should not be used in conjunction with synchronized TxCKI.
DS30000684B-page 156
PIC18(L)F2X/45K50
13.1
13.2.1
Timer1/3 Operation
TABLE 13-1:
13.2.2
Off
Off
Always On
Count Enabled
Note:
TABLE 13-2:
Timer1/3
Operation
TMRxGE
13.2
TIMER1/3 ENABLE
SELECTIONS
TMRxON
TMRxCS1
TMRxCS0
SOSCEN
Clock Source
DS30000684B-page 157
PIC18(L)F2X/45K50
13.3
Timer1/3 Prescaler
13.4
Secondary Oscillator
13.5
Timer1/3 Operation in
Asynchronous Counter Mode
13.5.1
13.6
DS30000684B-page 158
PIC18(L)F2X/45K50
FIGURE 13-2:
TIMER1/3 16-BIT
READ/WRITE MODE
BLOCK DIAGRAM
From
Timer1/3
Circuitry
Set
TMR1IF
on Overflow
TMR1
High Byte
TMR1L
Read TMR1L
Write TMR1L
13.7.2
TABLE 13-4:
TxGSS
TMR1H
8
8
Timer1/3 Gate
13.7.1
TABLE 13-3:
TxCLK
TxGPOL
TxG
Counts
Holds Count
Holds Count
Counts
01
10
11
13.7.2.1
00
13.7
13.7.2.2
13.7.2.3
13.7.2.4
DS30000684B-page 159
PIC18(L)F2X/45K50
13.7.3
When Timer1/3 Gate Toggle mode is enabled, it is possible to measure the full-cycle length of a Timer1/3 gate
signal, as opposed to the duration of a single level
pulse.
The Timer1/3 gate source is routed through a flip-flop
that changes state on every incrementing edge of the
signal. See Figure 13-5 for timing details.
Timer1/3 Gate Toggle mode is enabled by setting the
TxGTM bit of the TxGCON register. When the TxGTM
bit is cleared, the flip-flop is cleared and held clear. This
is necessary in order to control which edge is
measured.
Note:
13.7.4
13.7.5
13.7.6
DS30000684B-page 160
PIC18(L)F2X/45K50
13.8
Timer1/3 Interrupt
Note:
13.9
FIGURE 13-3:
Section 15.0
TXCKI = 1
when TMRx
Enabled
TXCKI = 0
when TMRX
Enabled
Note 1:
2:
DS30000684B-page 161
PIC18(L)F2X/45K50
FIGURE 13-4:
TMRxGE
TxGPOL
TxG_IN
TxCKI
TxGVAL
Timer1/3
FIGURE 13-5:
N+1
N+2
N+3
N+4
TMRxGE
TxGPOL
TxGTM
TxTxG_IN
TxCKI
TxGVAL
Timer1/3
DS30000684B-page 162
N+4
N+8
PIC18(L)F2X/45K50
FIGURE 13-6:
TMRxGE
TxGPOL
TxGSPM
TxGGO/
Cleared by hardware on
falling edge of TxGVAL
Set by software
DONE
Counting enabled on
rising edge of TxG
TxG_IN
TxCKI
TxGVAL
Timer1/3
TMRxGIF
Cleared by software
N+1
N+2
Set by hardware on
falling edge of TxGVAL
Cleared by
software
DS30000684B-page 163
PIC18(L)F2X/45K50
FIGURE 13-7:
TMRxGE
TxGPOL
TxGSPM
TxGTM
TxGGO/
Cleared by hardware on
falling edge of TxGVAL
Set by software
DONE
Counting enabled on
rising edge of TxG
TxG_IN
TxCKI
TxGVAL
Timer1/3
TMRxGIF
N+1
Cleared by software
N+2
N+3
Set by hardware on
falling edge of TxGVAL
N+4
Cleared by
software
DS30000684B-page 164
PIC18(L)F2X/45K50
13.13 Register Definitions: Timer1/3 Control
REGISTER 13-1:
R/W-0/u
R/W-0/u
R/W-0/u
TMRxCS<1:0>
R/W-0/u
TxCKPS<1:0>
R/W-0/u
R/W-0/u
R/W-0/0
R/W-0/u
SOSCEN
TxSYNC
RD16
TMRxON
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
bit 7-6
bit 5-4
bit 3
bit 2
bit 1
bit 0
DS30000684B-page 165
PIC18(L)F2X/45K50
REGISTER 13-2:
R/W-0/u
R/W-0/u
R/W-0/u
R/W-0/u
R/W/HC-0/u
R-x/x
TMRxGE
TxGPOL
TxGTM
TxGSPM
TxGGO/DONE
TxGVAL
R/W-0/u
R/W-0/u
TxGSS<1:0>
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1-0
DS30000684B-page 166
PIC18(L)F2X/45K50
TABLE 13-5:
Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
148
ANSELB
ANSB5
ANSB4
ANSB3
ANSB2
ANSB1
ANSB0
INTCON
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
124
IPR3
CTMUIP
USBIP
TMR3GIP
TMR1GIP
125
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
121
PIE3
CTMUIE
USBIE
TMR3GIE
TMR1GIE
122
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
118
PIR3
CTMUIF
USBIF
TMR3GIF
TMR1GIF
119
PMD0
UARTMD
USBMD
ACTMD
TMR3MD
TMR2MD
TMR1MD
61
T1CON
TMR1CS<1:0>
SOSCEN
T1SYNC
RD16
TMR1ON
165
T1GGO/DONE
T1GVAL
SOSCEN
T3SYNC
T3GGO/DONE
T3GVAL
T1GCON
TMR1GE
T3CON
T3GCON
T1GPOL
T1CKPS<1:0>
T1GTM
TMR3CS<1:0>
TMR3GE
T3GPOL
T1GSPM
T3CKPS<1:0>
T3GTM
TMRxH
TMRxL
T3GSPM
T1GSS<1:0>
RD16
TMR3ON
T3GSS<1:0>
166
165
166
TRISB
TRISB7
TRISB6
TRISB5
TRISB4
TRISB3
TRISB2
TRISB1
TRISB0
149
TRISC
TRISC7
TRISC6
TRISC2
TRISC1
TRISC0
149
TABLE 13-6:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
CONFIG3H
MCLRE
SDOMX
T3CMX
PBADEN
CCP2MX
376
DS30000684B-page 167
PIC18(L)F2X/45K50
14.0
TIMER2 MODULE
FIGURE 14-1:
FOSC/4
Prescaler
1:1, 1:4, 1:16
2
TMRx
Comparator
Sets Flag
bit TMRxIF
Reset
EQ
Postscaler
1:1 to 1:16
TxCKPS<1:0>
PRx
4
TxOUTPS<3:0>
DS30000684B-page 168
PIC18(L)F2X/45K50
14.1
Timer2 Operation
14.2
Timer2 Interrupt
14.3
Timer2 Output
14.4
14.5
DS30000684B-page 169
PIC18(L)F2X/45K50
14.6
REGISTER 14-1:
U-0
R/W-0
R/W-0
R/W-0
T2OUTPS<3:0>
R/W-0
R/W-0
TMR2ON
bit 7
R/W-0
T2CKPS<1:0>
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
bit 7
Unimplemented: Read as 0
bit 6-3
bit 2
bit 1-0
DS30000684B-page 170
PIC18(L)F2X/45K50
TABLE 14-1:
Name
INTCON
Bit 6
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
UARTMD
USBMD
ACTMD
TMR1MD
61
PMD0
PR2
T2CON
TMR2
GIE/GIEH PEIE/GIEL
Bit 5
TMR3MD TMR2MD
T2OUTPS<3:0>
TMR2ON
T2CKPS<1:0>
Timer2 Register
165
Legend: = unimplemented locations, read as 0. Shaded bits are not used by Timer2.
DS30000684B-page 171
PIC18(L)F2X/45K50
15.0
CAPTURE/COMPARE/PWM
MODULES
DS30000684B-page 172
15.1
Capture Mode
FIGURE 15-1:
CAPTURE MODE
OPERATION BLOCK
DIAGRAM
Prescaler
1, 4, 16
CCPx
pin
CCPRxH
and
Edge Detect
CCPRxL
Capture
Enable
TMRxH
TMRxL
CCPxM<3:0>
System Clock (FOSC)
PIC18(L)F2X/45K50
15.1.1
TABLE 15-1:
CCP OUTPUT
CCP2
CCP2MX
Bit Value
I/O pin
RB3
1(*)
RC1
Legend: * = Default
15.1.2
15.1.3
DS30000684B-page 173
PIC18(L)F2X/45K50
15.1.4
CCP PRESCALER
EXAMPLE 15-1:
CHANGING BETWEEN
CAPTURE PRESCALERS
DS30000684B-page 174
15.1.5
//Capture
// Prescale 4th
// rising edge
// Turn the CCP
// Module Off
// Turn CCP module
// on with new
// prescale value
PIC18(L)F2X/45K50
TABLE 15-2:
Name
CCP1CON
Bit 6
Bit 5
P1M<1:0>
CCP2CON
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
DC1B<1:0>
CCP1M<3:0>
197
DC2B<1:0>
CCP2M<3:0>
197
CCPR1H
CCPR1L
CCPR2H
CCPR2L
C2TSEL
C1TSEL
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
124
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
121
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
118
PMD0
UARTMD
USBMD
ACTMD
TMR3MD
TMR2MD
TMR1MD
61
PMD1
MSSPMD
CTMUMD
CMP2MD
CMP1MD
ADCMD
CCP2MD
CCP1MD
62
SOSCEN
T1SYNC
RD16
TMR1ON
165
CCPTMRS
INTCON
T1CON
TMR1CS<1:0>
T1GCON
TMR1GE
T3CON
T1GPOL
T1CKPS<1:0>
T1GTM
TMR3CS<1:0>
T3GCON
TMR3GE
T3GPOL
T1GSPM
T3CKPS<1:0>
T3GTM
T3GSPM
T1GGO/DONE
T1GVAL
SOSCEN
T3SYNC
T3GGO/DONE
T3GVAL
T1GSS<1:0>
RD16
TMR3ON
T3GSS<1:0>
200
166
165
166
TMR1H
Holding Register for the Most Significant Byte of the 16-bit TMR1 Register
TMR1L
Holding Register for the Least Significant Byte of the 16-bit TMR1 Register
TMR3H
Holding Register for the Most Significant Byte of the 16-bit TMR3 Register
TMR3L
Holding Register for the Least Significant Byte of the 16-bit TMR3 Register
TRISB
TRISB7
TRISB6
TRISB5
TRISB4
TRISB3
TRISB2
TRISB1
TRISB0
149
TRISC
TRISC7
TRISC6
TRISC2
TRISC1
TRISC0
149
Legend: = Unimplemented location, read as 0. Shaded bits are not used by Capture mode.
TABLE 15-3:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
CONFIG3H
MCLRE
SDOMX
T3CMX
PBADEN
CCP2MX
376
Legend: = Unimplemented location, read as 0. Shaded bits are not used by Capture mode.
DS30000684B-page 175
PIC18(L)F2X/45K50
15.2
15.2.1
Compare Mode
FIGURE 15-2:
15.2.2
S
R
Output
Logic
Comparator
Match
TRIS
Output Enable
TMRxH
CCPxM<3:0>
Mode Select
CCPx
Pin
COMPARE MODE
OPERATION BLOCK
DIAGRAM
15.2.3
TMRxL
DS30000684B-page 176
PIC18(L)F2X/45K50
15.2.4
15.2.5
DS30000684B-page 177
PIC18(L)F2X/45K50
TABLE 15-4:
Name
Bit 7
CCP1CON
Bit 6
Bit 5
P1M<1:0>
CCP2CON
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
DC1B<1:0>
CCP1M<3:0>
197
DC2B<1:0>
CCP2M<3:0>
197
CCPR1H
CCPR1L
CCPR2H
CCPR2L
ADCON1
TRIGSEL
INTCON
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
124
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
CCPTMRS
C2TSEL
PVCFG<1:0>
C1TSEL
NVCFG<1:0>
200
295
114
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
121
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
118
PMD0
UARTMD
USBMD
ACTMD
TMR3MD
TMR2MD
TMR1MD
61
PMD1
MSSPMD
CTMUMD
CMP2MD
CMP1MD
ADCMD
CCP2MD
CCP1MD
62
RD16
TMR1ON
165
T1CON
TMR1CS<1:0>
T1GCON
TMR1GE
T3CON
T1CKPS<1:0>
T1GTM
TMR3CS<1:0>
T3GCON
TMR1H
T1GPOL
TMR3GE
T3GPOL
T1GSPM
T3CKPS<1:0>
T3GTM
T3GSPM
SOSCEN
T1SYNC
T1GGO/DONE
T1GVAL
SOSCEN
T3SYNC
T3GGO/DONE
T3GVAL
T1GSS<1:0>
RD16
TMR3ON
T3GSS<1:0>
166
165
166
Holding Register for the Most Significant Byte of the 16-bit TMR1 Register
TMR1L
Holding Register for the Least Significant Byte of the 16-bit TMR1 Register
TMR3H
Holding Register for the Most Significant Byte of the 16-bit TMR3 Register
TMR3L
Holding Register for the Least Significant Byte of the 16-bit TMR3 Register
TRISB
TRISB7
TRISB6
TRISB5
TRISB4
TRISB3
TRISB2
TRISB1
TRISB0
149
TRISC
TRISC7
TRISC6
TRISC2
TRISC1
TRISC0
149
Legend: = Unimplemented location, read as 0. Shaded bits are not used by Capture mode.
TABLE 15-5:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
CONFIG3H
MCLRE
SDOMX
T3CMX
PBADEN
CCP2MX
376
Legend: = Unimplemented location, read as 0. Shaded bits are not used by Capture mode.
DS30000684B-page 178
PIC18(L)F2X/45K50
15.3
PWM Overview
FIGURE 15-3:
Period
Pulse Width
TMR2 = 0
FIGURE 15-4:
CCPRxH(2) (Slave)
CCPx
TMR2
(1)
S
TRIS
Comparator
PR2
Note 1:
Comparator
PR2 register
T2CON register
CCPRxL registers
CCPxCON registers
CCPxCON<5:4>
CCPRxL
TMR2 = PR2
TMR2 = CCPRxH:CCPxCON<5:4>
15.3.1
2:
15.3.2
Clear Timer,
toggle CCPx pin and
latch duty cycle
4.
DS30000684B-page 179
PIC18(L)F2X/45K50
5.
6.
15.3.3
PWM PERIOD
EQUATION 15-1:
PWM PERIOD
TOSC = 1/FOSC
15.3.4
EQUATION 15-2:
PULSE WIDTH
EQUATION 15-3:
CCPRxL:CCPxCON<5:4>
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 two 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 15-4).
DS30000684B-page 180
PIC18(L)F2X/45K50
15.3.5
PWM RESOLUTION
EQUATION 15-4:
TABLE 15-6:
1.95 kHz
PR2 Value
Maximum Resolution (bits)
7.81 kHz
31.25 kHz
125 kHz
250 kHz
333.3 kHz
16
0xFF
0xFF
0x3F
0x1F
0x17
10
10
10
6.6
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
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
15.3.7
0xFF
1.22 kHz
15.3.6
Note:
PWM Frequency
TABLE 15-8:
log 4 PR2 + 1
Resolution = ------------------------------------------ bits
log 2
PWM Frequency
TABLE 15-7:
PWM RESOLUTION
15.3.8
EFFECTS OF RESET
Any Reset will force all ports to Input mode and the
CCP registers to their Reset states.
DS30000684B-page 181
PIC18(L)F2X/45K50
TABLE 15-9:
Name
CCP1CON
Bit 6
Bit 5
P1M<1:0>
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
DC1B<1:0>
CCP1M<3:0>
197
DC2B<1:0>
CCP2M<3:0>
197
CCP2CON
CCPTMRS
C2TSEL
C1TSEL
200
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
124
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
121
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
118
PMD0
UARTMD
USBMD
ACTMD
TMR3MD
TMR2MD
TMR1MD
61
PMD1
MSSPMD
CTMUMD
CMP2MD
CMP1MD
ADCMD
CCP2MD
CCP1MD
62
INTCON
PR2
T2CON
TMR2
T2OUTPS<3:0>
TMR2ON
T2CKPS<1:0>
170
TRISB
TRISB7
TRISB6
TRISB5
TRISB4
TRISB3
TRISB2
TRISB1
TRISB0
149
TRISC
TRISC7
TRISC6
TRISC2
TRISC1
TRISC0
149
Legend: = Unimplemented location, read as 0. Shaded bits are not used by Capture mode.
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
CONFIG3H
MCLRE
SDOMX
T3CMX
PBADEN
CCP2MX
376
Legend: = Unimplemented location, read as 0. Shaded bits are not used by Capture mode.
DS30000684B-page 182
PIC18(L)F2X/45K50
15.4
The PWM outputs are multiplexed with I/O pins and are
designated PxA, PxB, PxC and PxD. The polarity of the
PWM pins is configurable and is selected by setting the
CCPxM bits in the CCPxCON register appropriately.
PR2 register
T2CON register
CCPRxL registers
CCPxCON registers
ECCPxAS registers
PSTRxCON registers
PWMxCON registers
Single PWM
Half-Bridge PWM
Full-Bridge PWM, Forward mode
Full-Bridge PWM, Reverse mode
Single PWM with PWM Steering mode
FIGURE 15-5:
DCxB<1:0>
CCPxM<3:0>
4
PxM<1:0>
2
CCPRxL
CCPx/PxA
CCPx/PxA
TRISx
CCPRxH (Slave)
PxB
R
Comparator
Output
Controller
PxB
TRISx
PxC
TMR2
Comparator
PR2
Note
(1)
PxC(2)
TRISx
S
PxD
Clear Timer,
toggle PWM pin and
latch duty cycle
PxD(2)
TRISx
PWMxCON
1:
The 8-bit timer TMR2 register is concatenated with the 2-bit internal Q clock, or two bits of the prescaler to create the 10-bit time
base.
2:
DS30000684B-page 183
PIC18(L)F2X/45K50
TABLE 15-11: EXAMPLE PIN ASSIGNMENTS FOR VARIOUS PWM ENHANCED MODES
ECCP Mode
PxM<1:0>
CCPx/PxA
Yes
PxC
(1)
Yes
PxD
(1)
Yes(1)
Single
00
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:
Yes
PxB
(1)
FIGURE 15-6:
PxM<1:0>
Signal
PRX+1
Pulse
Width
Period
00
(Single Output)
PxA Modulated
Delay(1)
Delay(1)
PxA Modulated
10
(Half-Bridge)
PxB Modulated
PxA Active
01
(Full-Bridge,
Forward)
PxB Inactive
PxC Inactive
PxD Modulated
PxA Inactive
11
(Full-Bridge,
Reverse)
PxB Modulated
PxC Active
PxD Inactive
Relationships:
Period = 4 * TOSC * (PRx + 1) * (TMRx Prescale Value)
Pulse Width = TOSC * (CCPRxL<7:0>:CCPxCON<5:4>) * (TMRx Prescale Value)
Delay = 4 * TOSC * (PWMxCON<6:0>)
Note 1: Dead-band delay is programmed using the PWMxCON register (Section 15.4.5 Programmable Dead-Band Delay
Mode).
DS30000684B-page 184
PIC18(L)F2X/45K50
FIGURE 15-7:
PxM<1:0>
PRx+1
Pulse
Width
Period
00
(Single Output)
PxA Modulated
PxA Modulated
10
(Half-Bridge)
Delay(1)
Delay(1)
PxB Modulated
PxA Active
01
(Full-Bridge,
Forward)
PxB Inactive
PxC Inactive
PxD Modulated
PxA Inactive
11
(Full-Bridge,
Reverse)
PxB Modulated
PxC Active
PxD Inactive
Relationships:
Period = 4 * TOSC * (PRx + 1) * (TMRx Prescale Value)
Pulse Width = TOSC * (CCPRxL<7:0>:CCPxCON<5:4>) * (TMRx Prescale Value)
Delay = 4 * TOSC * (PWMxCON<6:0>)
Note
1:
Dead-band delay is programmed using the PWMxCON register (Section 15.4.5 Programmable Dead-Band Delay
Mode).
DS30000684B-page 185
PIC18(L)F2X/45K50
15.4.1
HALF-BRIDGE MODE
Since the PxA and PxB outputs are multiplexed with the
PORT data latches, the associated TRIS bits must be
cleared to configure PxA and PxB as outputs.
FIGURE 15-8:
Period
Period
Pulse Width
PxA(2)
td
td
PxB(2)
(1)
(1)
(1)
td = Dead-Band Delay
Note 1:
2:
FIGURE 15-9:
PxA
Load
FET
Driver
PxB
FET
Driver
FET
Driver
PxA
FET
Driver
Load
FET
Driver
PxB
DS30000684B-page 186
PIC18(L)F2X/45K50
15.4.2
FULL-BRIDGE MODE
FIGURE 15-10:
FET
Driver
QC
QA
FET
Driver
PxA
Load
PxB
FET
Driver
PxC
FET
Driver
QD
QB
VPxD
DS30000684B-page 187
PIC18(L)F2X/45K50
FIGURE 15-11:
Forward Mode
Period
PxA
(2)
Pulse Width
PxB(2)
PxC(2)
PxD(2)
(1)
(1)
Reverse Mode
Period
Pulse Width
PxA(2)
PxB(2)
PxC(2)
PxD(2)
(1)
Note 1:
2:
(1)
DS30000684B-page 188
PIC18(L)F2X/45K50
15.4.2.1
FIGURE 15-12:
Signal
Period
PxA (Active-High)
PxB (Active-High)
Pulse Width
PxC (Active-High)
(2)
PxD (Active-High)
Pulse Width
Note 1:
2:
The direction bit PxM1 of the CCPxCON register is written any time during the PWM cycle.
When changing directions, the PxA and PxC signals switch before the end of the current PWM cycle. The
modulated PxB and PxD signals are inactive at this time. The length of this time is (Timer2 Prescale)/FOSC.
DS30000684B-page 189
PIC18(L)F2X/45K50
FIGURE 15-13:
t1
Reverse Period
PxA
PxB
PW
PxC
PxD
PW
TON
External Switch C
TOFF
External Switch D
Potential
Shoot-Through Current
Note 1:
15.4.3
T = TOFF TON
2:
3:
DS30000684B-page 190
PIC18(L)F2X/45K50
FIGURE 15-14:
Timer
Overflow
Missing Pulse
(ECCPxASE not clear)
Timer
Overflow
Timer
Overflow
Timer
Overflow
PWM Period
PWM Activity
Start of
PWM Period
Shutdown Event
ECCPxASE bit
Shutdown
Event Occurs
15.4.4
AUTO-RESTART MODE
FIGURE 15-15:
Shutdown
Event Clears
PWM
Resumes
ECCPxASE
Cleared by
Firmware
Timer
Overflow
Missing Pulse
(ECCPxASE not clear)
Timer
Overflow
Timer
Overflow
Timer
Overflow
PWM Period
PWM Activity
Start of
PWM Period
Shutdown Event
ECCPxASE bit
PWM
Resumes
Shutdown
Event Occurs
Shutdown
Event Clears
ECCPxASE
Cleared by
Hardware
DS30000684B-page 191
PIC18(L)F2X/45K50
15.4.5
PROGRAMMABLE DEAD-BAND
DELAY MODE
FIGURE 15-16:
Period
Period
Pulse Width
PxA(2)
td
td
PxB(2)
(1)
(1)
(1)
td = Dead-Band Delay
Note 1:
In Half-Bridge mode, a digitally programmable deadband delay is available to avoid shoot-through current
from destroying the bridge power switches. The delay
occurs at the signal transition from the non-active state
to the active state. See Figure 15-16 for illustration.
The lower seven bits of the associated PWMxCON
register (Register 15-5) sets the delay period in terms
of microcontroller instruction cycles (TCY or 4 TOSC).
FIGURE 15-17:
2:
+
V
-
PxA
Load
FET
Driver
+
V
-
PxB
V-
DS30000684B-page 192
PIC18(L)F2X/45K50
15.4.6
Note:
FIGURE 15-18:
SIMPLIFIED STEERING
BLOCK DIAGRAM
STRxA
PxA Signal
CCPxM1
PORT Data
PxA pin
STRxB
CCPxM0
PORT Data
STRxC
CCPxM1
PORT Data
PORT Data
PxB pin
TRIS
PxC pin
TRIS
STRxD
CCPxM0
TRIS
PxD pin
1
0
TRIS
Note 1:
2:
15.4.6.1
Steering Synchronization
DS30000684B-page 193
PIC18(L)F2X/45K50
15.4.7
START-UP CONSIDERATIONS
The PxA, PxB, PxC and PxD output latches may not be
in the proper states when the PWM module is
initialized. Enabling the PWM pin output drivers at the
same time as the Enhanced PWM modes may cause
damage to the application circuit. The Enhanced PWM
FIGURE 15-19:
PWM
STRx
P1<D:A>
PORT Data
PORT Data
P1n = PWM
FIGURE 15-20:
PWM
STRx
P1<D:A>
PORT Data
PORT Data
P1n = PWM
DS30000684B-page 194
PIC18(L)F2X/45K50
15.4.8
2.
3.
4.
5.
6.
7.
8.
9.
DS30000684B-page 195
PIC18(L)F2X/45K50
TABLE 15-12: REGISTERS ASSOCIATED WITH ENHANCED PWM
Name
ECCP1AS
Bit 7
ECCP1ASE
CCP1CON
CCPTMRS
Bit 6
Bit 5
Bit 4
ECCP1AS<2:0>
P1M<1:0>
Bit 3
Bit 2
Bit 1
PSS1AC<1:0>
DC1B<1:0>
Bit 0
PSS1BD<1:0>
201
200
CCP1M<3:0>
C2TSEL
Register on
page
197
C1TSEL
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
124
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
121
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
118
PMD0
UARTMD
USBMD
ACTMD
TMR3MD
TMR2MD
TMR1MD
61
PMD1
MSSPMD
CTMUMD
CMP2MD
CMP1MD
ADCMD
CCP2MD
CCP1MD
62
STR1SYNC
STR1D
STR1C
STR1B
STR1A
202
INTCON
PR2
PSTR1CON
PWM1CON
P1RSEN
T2CON
TMR2
P1DC<6:0>
T2OUTPS<3:0>
202
TMR2ON
T2CKPS<1:0>
170
TRISB
TRISB7
TRISB6
TRISB5
TRISB4
TRISC
TRISC7
TRISC6
TRISD(1)
TRISD7
TRISD6
TRISD5
TRISD4
TRISB3
TRISB2
TRISB1
TRISB0
149
TRISC2
TRISC1
TRISC0
149
TRISD3
TRISD2
TRISD1
TRISD0
149
Legend: = Unimplemented location, read as 0. Shaded bits are not used by Capture mode.
Note 1:
These registers/bits are available on PIC18(L)F45K50 devices.
DS30000684B-page 196
PIC18(L)F2X/45K50
15.5
REGISTER 15-1:
U-0
U-0
R/W-0
R/W-0
R/W-0
DCxB<1:0>
R/W-0
R/W-0
R/W-0
CCPxM<3:0>
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
bit 7-6
Unused
bit 5-4
bit 3-0
1000 = Compare mode: set output on compare match (CCPx pin is set, CCPxIF is set)
1001 = Compare mode: clear output on compare match (CCPx pin is cleared, CCPxIF is set)
1010 = Compare mode: generate software interrupt on compare match (CCPx pin is unaffected,
CCPxIF is set)
1011 = Compare mode: Special Event Trigger (CCPx pin is unaffected, CCPxIF is set)
TimerX (selected by CxTSEL bits) is reset
ADON is set, starting A/D conversion if A/D module is enabled and TRIGSEL
is clear(1)
11xx =: PWM mode
Note 1:
DS30000684B-page 197
PIC18(L)F2X/45K50
REGISTER 15-2:
R/x-0
PxM<1:0>
R/W-0
R/W-0
DCxB<1:0>
R/W-0
R/W-0
R/W-0
R/W-0
CCPxM<3:0>
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
bit 7-6
bit 5-4
Note 1:
DS30000684B-page 198
PIC18(L)F2X/45K50
REGISTER 15-2:
bit 3-0
1000 = Compare mode: set output on compare match (CCPx pin is set, CCPxIF is set)
1001 = Compare mode: clear output on compare match (CCPx pin is cleared, CCPxIF is set)
1010 = Compare mode: generate software interrupt on compare match (CCPx pin is unaffected,
CCPxIF is set)
1011 = Compare mode: Special Event Trigger (CCPx pin is unaffected, CCPxIF is set)
TimerX is reset
Half-Bridge ECCP Modules(1):
1100 = PWM mode: PxA active-high; PxB active-high
1101 = PWM mode: PxA active-high; PxB active-low
1110 = PWM mode: PxA active-low; PxB active-high
1111 = PWM mode: PxA active-low; PxB active-low
Full-Bridge ECCP Modules(1):
1100 = PWM mode: PxA, PxC active-high; PxB, PxD active-high
1101 = PWM mode: PxA, PxC active-high; PxB, PxD active-low
1110 = PWM mode: PxA, PxC active-low; PxB, PxD active-high
1111 = PWM mode: PxA, PxC active-low; PxB, PxD active-low
Note 1:
See Table 15-1 to determine full-bridge and half-bridge ECCPs for the device being used.
DS30000684B-page 199
PIC18(L)F2X/45K50
REGISTER 15-3:
U-0
U-0
U-0
U-0
R/W-0
U-0
U-0
R/W-0
C2TSEL
C1TSEL
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
bit 7-4
Unimplemented: Read as 0
bit 3
bit 2-1
Unimplemented: Read as 0
bit 0
DS30000684B-page 200
PIC18(L)F2X/45K50
REGISTER 15-4:
R/W-0
ECCPxASE
R/W-0
R/W-0
ECCPxAS<2:0>
R/W-0
R/W-0
R/W-0
PSSxAC<1:0>
R/W-0
PSSxBD<1:0>
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6-4
bit 3-2
bit 1-0
Note 1:
If C1SYNC or C2SYNC bits in the CM2CON1 register are enabled, the shutdown will be delayed by Timer1.
DS30000684B-page 201
PIC18(L)F2X/45K50
REGISTER 15-5:
R/W-0
R/W-0
R/W-0
PxRSEN
R/W-0
R/W-0
R/W-0
R/W-0
PxDC<6:0>
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6-0
REGISTER 15-6:
U-0
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-1
STRxSYNC
STRxD
STRxC
STRxB
STRxA
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
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:
The PWM Steering mode is available only when the CCPxCON register bits CCPxM<3:2> = 11 and
PxM<1:0> = 00.
DS30000684B-page 202
PIC18(L)F2X/45K50
16.0
16.1
MASTER SYNCHRONOUS
SERIAL PORT (MSSP)
MODULE
Module Overview
Master mode
Slave mode
Clock Parity
Slave Select Synchronization (Slave mode only)
Daisy chain connection of slave devices
FIGURE 16-1:
Write
SSPxBUF Reg
SDI
SSPxSR Reg
SDO
bit 0
SS
SS Control
Enable
Shift
Clock
2 (CKP, CKE)
Clock Select
Edge
Select
SSPxM<3:0>
4
SCK
Edge
Select
TRIS bit
( TMR22Output )
Prescaler TOSC
4, 16, 64
Baud Rate
Generator
(SSPxADD)
DS30000684B-page 203
PIC18(L)F2X/45K50
The I2C interface supports the following modes and
features:
Master mode
Slave mode
Byte NACKing (Slave mode)
Limited Multi-master support
7-bit and 10-bit addressing
Start and Stop interrupts
Interrupt masking
Clock stretching
Bus collision detection
[SSPxM 3:0]
Write
SSPxBUF
Baud Rate
Generator
(SSPxADD)
SDA
Shift
Clock
SDA in
SCL
SCL in
Bus Collision
DS30000684B-page 204
LSb
Clock Cntl
SSPxSR
MSb
FIGURE 16-2:
PIC18(L)F2X/45K50
FIGURE 16-3:
Write
SSPxBUF Reg
SCL
Shift
Clock
SSPxSR Reg
SDA
MSb
LSb
SSPxMSK Reg
Match Detect
Addr Match
SSPxADD Reg
Start and
Stop bit Detect
Set, Reset
S, P bits
(SSPxSTAT Reg)
DS30000684B-page 205
PIC18(L)F2X/45K50
16.2
DS30000684B-page 206
PIC18(L)F2X/45K50
FIGURE 16-4:
SPI Master
SCLK
SDO
SDI
SDI
SDO
General I/O
General I/O
SS
General I/O
SCLK
SDI
SDO
SPI Slave
#1
SPI Slave
#2
SS
SCLK
SDI
SDO
SPI Slave
#3
SS
and
The
The
The
DS30000684B-page 207
PIC18(L)F2X/45K50
Any serial port function that is not desired may be
overridden by programming the corresponding data
direction (TRIS) register to the opposite value.
FIGURE 16-5:
SDI
SDI
Shift Register
(SSPxSR)
MSb
LSb
SCK
General I/O
Processor 1
DS30000684B-page 208
SDO
Serial Clock
Slave Select
(optional)
Shift Register
(SSPxSR)
MSb
LSb
SCK
SS
Processor 2
PIC18(L)F2X/45K50
16.2.3
FIGURE 16-6:
Write to
SSPxBUF
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 7
bit 0
Input
Sample
(SMP = 1)
SSPIF
SSPxSR to
SSPxBUF
DS30000684B-page 209
PIC18(L)F2X/45K50
16.2.4
16.2.5
SLAVE SELECT
SYNCHRONIZATION
DS30000684B-page 210
PIC18(L)F2X/45K50
FIGURE 16-7:
SCLK
SPI Master
SDO
SDI
SDI
SPI Slave
#1
SDO
General I/O
SS
SCLK
SDI
SPI Slave
#2
SDO
SS
SCLK
SDI
SPI Slave
#3
SDO
SS
FIGURE 16-8:
SS
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
Write to
SSPxBUF
SSPxBUF to
SSPxSR
SDO
bit 7
bit 6
bit 7
SDI
bit 6
bit 0
bit 0
bit 7
bit 7
Input
Sample
SSPIF
Interrupt
Flag
SSPxSR to
SSPxBUF
DS30000684B-page 211
PIC18(L)F2X/45K50
FIGURE 16-9:
SS
Optional
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
Write to
SSPxBUF
Valid
SDO
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
SDI
bit 0
bit 7
Input
Sample
SSPIF
Interrupt
Flag
SSPxSR to
SSPxBUF
Write Collision
detection active
FIGURE 16-10:
SS
Not Optional
SCK
(CKP = 0
CKE = 1)
SCK
(CKP = 1
CKE = 1)
Write to
SSPxBUF
Valid
SDO
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
SDI
bit 7
bit 0
Input
Sample
SSPIF
Interrupt
Flag
SSPxSR to
SSPxBUF
Write Collision
detection active
DS30000684B-page 212
PIC18(L)F2X/45K50
16.2.6 SPI OPERATION IN SLEEP MODE
TABLE 16-1:
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
ANSELA
ANSA5
ANSA3
ANSA2
ANSA1
ANSA0
147
ANSELB
ANSB5
ANSB4
ANSB3
ANSB2
ANSB1
ANSB0
148
INTCON
Name
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
PMD1
MSSPMD
CMP1MD
ADCMD
CCP2MD
CCP1MD
62
SSP1BUF
CTMUMD CMP2MD
SSP1CON1
WCOL
SSPOV
SSPEN
CKP
SSP1CON3
ACKTIM
PCIE
SCIE
BOEN
SSP1STAT
SSPM<3:0>
SDAHT
SBCDE
AHEN
252
DHEN
255
251
SMP
CKE
D/A
R/W
UA
BF
TRISA
TRISA7
TRISA6
TRISA5
TRISA4
TRISA3
TRISA2
TRISA1
TRISA0
149
TRISB
TRISB7
TRISB6
TRISB5
TRISB4
TRISB3
TRISB2
TRISB1
TRISB0
149
TRISC7
TRISC6
TRISC2
TRISC1
TRISC0
149
TRISC
Legend:
DS30000684B-page 213
PIC18(L)F2X/45K50
16.3
VDD
SCL
DS30000684B-page 214
I2C MASTER/
SLAVE CONNECTION
FIGURE 16-11:
SCL
VDD
Master
Slave
SDA
SDA
PIC18(L)F2X/45K50
When one device is transmitting a logical one, or letting
the line float, and a second device is transmitting a
logical zero, or holding the line low, the first device can
detect that the line is not a logical one. This detection,
when used on the SCL line, is called clock stretching.
Clock stretching give slave devices a mechanism to
control the flow of data. When this detection is used on
the SDA line, it is called arbitration. Arbitration ensures
that there is only one master device communicating at
any single time.
16.3.1
CLOCK STRETCHING
16.3.2
ARBITRATION
Each master device must monitor the bus for Start and
Stop bits. If the device detects that the bus is busy, it
cannot begin a new message until the bus returns to an
Idle state.
However, two master devices may try to initiate a
transmission on or about the same time. When this
occurs, the process of arbitration begins. Each
transmitter checks the level of the SDA data line and
compares it to the level that it expects to find. The first
transmitter to observe that the two levels do not match,
loses arbitration, and must stop transmitting on the
SDA line.
For example, if one transmitter holds the SDA line to a
logical one (lets it float) and a second transmitter holds
it to a logical zero (pulls it low), the result is that the
SDA line will be low. The first transmitter then observes
that the level of the line is different than expected and
concludes that another transmitter is communicating.
The first transmitter to notice this difference is the one
that loses arbitration and must stop driving the SDA
line. If this transmitter is also a master device, it also
must stop driving the SCL line. It then can monitor the
lines for a Stop condition before trying to reissue its
transmission. In the meantime, the other device that
has not noticed any difference between the expected
and actual levels on the SDA line continues with its
original transmission. It can do so without any complications, because so far, the transmission appears
exactly as expected with no other transmitter disturbing
the message.
Slave Transmit mode can also be arbitrated, when a
master addresses multiple slaves, but this is less
common.
If two master devices are sending a message to two
different slave devices at the address stage, the master
sending the lower slave address always wins
arbitration. When two master devices send messages
to the same slave address, and addresses can
sometimes refer to multiple slaves, the arbitration
process must continue into the data stage.
Arbitration usually occurs very rarely, but it is a
necessary process for proper multi-master support.
DS30000684B-page 215
PIC18(L)F2X/45K50
16.4
DS30000684B-page 216
TABLE 16-2:
TERM
Transmitter
PIC18(L)F2X/45K50
16.4.5 START CONDITION
FIGURE 16-12:
SDA
SCL
S
Start
P
Change of
Change of
Data Allowed
Data Allowed
Condition
FIGURE 16-13:
Stop
Condition
Sr
Change of
Change of
Data Allowed
Restart
Data Allowed
Condition
DS30000684B-page 217
PIC18(L)F2X/45K50
I2C Slave Mode Operation
16.5
16.5.1.1
DS30000684B-page 218
PIC18(L)F2X/45K50
16.5.2 SLAVE RECEPTION
DS30000684B-page 219
DS30000684B-page 220
SSPOV
BF
SSPIF
A7
A6
A5
A4
A3
A2
A1
ACK
D7
D6
D4
D3
D2
D1
SSPxBUF is read
Cleared by software
D5
Receiving Data
D6
First byte
of data is
available
in SSPxBUF
D0 ACK D7
D4
D3
D2
D1
Cleared by software
D5
Receiving Data
D0
ACK = 1
FIGURE 16-14:
SCL
SDA
Receiving Address
PIC18(L)F2X/45K50
I2C SLAVE, 7-BIT ADDRESS, RECEPTION (SEN = 0, AHEN = 0, DHEN = 0)
CKP
SSPOV
BF
SSPIF
SCL
A7
A6
A5
A4
A3
A2
A1
R/W=0 ACK
SEN
2
D6
D5
D4
D3
D2
D1
D0
SSPxBUF is read
Cleared by software
D7
Receive Data
ACK
SEN
3
D5
D4
D3
First byte
of data is
available
in SSPxBUF
D2
D1
Cleared by software
D6
D7
Receive Data
D0
ACK
FIGURE 16-15:
SDA
Receive Address
PIC18(L)F2X/45K50
DS30000684B-page 221
DS30000684B-page 222
ACKTIM
CKP
ACKDT
BF
SSPIF
Receiving Address
Slave software
clears ACKDT to
Address is
read from
SSBUF
If AHEN = 1:
SSPIF is set
When AHEN=1:
CKP is cleared by hardware
and SCL is stretched
A7 A6 A5 A4 A3 A2 A1
Receiving Data
9
2
ACKTIM cleared by
hardware in 9th
rising edge of SCL
When DHEN=1:
CKP is cleared by
hardware on 8th falling
edge of SCL
SSPIF is set on
9th falling edge of
SCL, after ACK
ACK D7 D6 D5 D4 D3 D2 D1 D0
Received Data
Slave software
sets ACKDT to
not ACK
Cleared by software
D7 D6 D5 D4 D3 D2 D1 D0
ACK
No interrupt
after not ACK
from Slave
ACK=1
Master sends
Stop condition
FIGURE 16-16:
SCL
SDA
PIC18(L)F2X/45K50
I2C SLAVE, 7-BIT ADDRESS, RECEPTION (SEN = 0, AHEN = 1, DHEN = 1)
ACKTIM
CKP
ACKDT
BF
SSPIF
Receiving Address
4
5
6 7
When AHEN = 1;
on the 8th falling edge
of SCL of an address
byte, CKP is cleared
Received
address is loaded into
SSPxBUF
2 3
A7 A6 A5 A4 A3 A2 A1
ACK
Receive Data
2 3
6 7
When DHEN = 1;
on the 8th falling edge
of SCL of a received
data byte, CKP is cleared
Received data is
available on SSPxBUF
Cleared by software
D7 D6 D5 D4 D3 D2 D1 D0
ACK
Receive Data
1
3 4
6 7
Set by software,
release SCL
Slave sends
not ACK
SSPxBUF can be
read any time before
next byte is loaded
D7 D6 D5 D4 D3 D2 D1 D0
ACK
No interrupt after
if not ACK
from Slave
Master sends
Stop condition
FIGURE 16-17:
SCL
SDA
R/W = 0
Master releases
SDA to slave for ACK sequence
PIC18(L)F2X/45K50
DS30000684B-page 223
PIC18(L)F2X/45K50
16.5.3
SLAVE TRANSMISSION
16.5.3.2
7-Bit Transmission
1.
16.5.3.1
DS30000684B-page 224
D/A
R/W
ACKSTAT
CKP
BF
SSPIF
Receiving Address
Indicates an address
has been received
R/W = 1 Automatic
ACK
Received address
is read from SSPxBUF
A7 A6 A5 A4 A3 A2 A1
Transmitting Data
Automatic
Set by software
Data to transmit is
loaded into SSPxBUF
Cleared by software
D7 D6 D5 D4 D3 D2 D1 D0 ACK
Transmitting Data
CKP is not
held for not
ACK
BF is automatically
cleared after 8th falling
edge of SCL
D7 D6 D5 D4 D3 D2 D1 D0
9
ACK
FIGURE 16-18:
SCL
SDA
Master sends
Stop condition
PIC18(L)F2X/45K50
DS30000684B-page 225
PIC18(L)F2X/45K50
16.5.3.3
DS30000684B-page 226
D/A
R/W
ACKTIM
CKP
ACKSTAT
ACKDT
BF
SSPIF
Receiving Address
Slave clears
ACKDT to ACK
address
ACK
When R/W = 1;
CKP is always
cleared after ACK
R/W = 1
Received address
is read from SSPxBUF
When AHEN = 1;
CKP is cleared by hardware
after receiving matching
address.
A7 A6 A5 A4 A3 A2 A1
3
Cleared by software
Set by software,
releases SCL
Data to transmit is
loaded into SSPxBUF
Transmitting Data
Automatic
D7 D6 D5 D4 D3 D2 D1 D0 ACK
ACKTIM is cleared
on 9th rising edge of SCL
Automatic
Transmitting Data
Masters ACK
response is copied
to SSPxSTAT
BF is automatically
cleared after 8th falling
edge of SCL
D7 D6 D5 D4 D3 D2 D1 D0
9
ACK
Master sends
Stop condition
FIGURE 16-19:
SCL
SDA
PIC18(L)F2X/45K50
DS30000684B-page 227
PIC18(L)F2X/45K50
16.5.4 SLAVE MODE 10-BIT ADDRESS
RECEPTION
3.
4.
5.
6.
7.
8.
DS30000684B-page 228
CKP
UA
BF
SSPIF
0 A9 A8
Set by hardware
on 9th falling edge
When UA = 1;
SCL is held low
ACK
If address matches
SSPxADD it is loaded into
SSPxBUF
A7 A6 A5 A4 A3 A2 A1 A0 ACK
9
1
Data is read
from SSPxBUF
D7 D6 D5 D4 D3 D2 D1 D0 ACK
Receive Data
Set by software,
When SEN = 1;
releasing SCL
CKP is cleared after
9th falling edge of received byte
Receive address is
read from SSPxBUF
Cleared by software
D7 D6 D5 D4 D3 D2 D1 D0 ACK
Receive Data
FIGURE 16-20:
SCL
SDA
Master sends
Stop condition
PIC18(L)F2X/45K50
DS30000684B-page 229
DS30000684B-page 230
ACKTIM
CKP
UA
ACKDT
BF
A9
A8
Set by hardware
on 9th falling edge
If when AHEN = 1;
on the 8th falling edge
of SCL of an address
byte, CKP is cleared
R/W = 0
ACK
UA
A6
A5
A4
A3
A2
A1
Update to SSPxADD is
not allowed until 9th
falling edge of SCL
SSPxBUF can be
read anytime before
the next received byte
Cleared by software
A7
A0
ACK
UA
D6
D5
D4
D2
D1
Update of SSPxADD,
clears UA and releases
SCL
D3
Receive Data
Cleared by software
D7
Received data
is read from
SSPxBUF
D6 D5
Receive Data
D0 ACK D7
FIGURE 16-21:
SSPIF
SCL
SDA
PIC18(L)F2X/45K50
I2C SLAVE, 10-BIT ADDRESS, RECEPTION (SEN = 0, AHEN = 1, DHEN = 0)
D/A
R/W
ACKSTAT
CKP
UA
BF
SSPIF
Set by hardware
Indicates an address
has been received
UA indicates SSPxADD
must be updated
SSPxBUF loaded
with received address
SCL
1
3
7 8
After SSPxADD is
updated, UA is cleared
and SCL is released
Cleared by software
A7 A6 A5 A4 A3 A2 A1 A0 ACK
1
4
7 8
Set by hardware
2 3
When R/W = 1;
CKP is cleared on
9th falling edge of SCL
Received address is
read from SSPxBUF
Sr
1 1 1 1 0 A9 A8
ACK
Set by software
releases SCL
Data to transmit is
loaded into SSPxBUF
D7 D6 D5 D4 D3 D2 D1 D0
Master sends
Stop condition
ACK = 1
Master sends
not ACK
FIGURE 16-22:
SDA
Master sends
Restart event
PIC18(L)F2X/45K50
DS30000684B-page 231
PIC18(L)F2X/45K50
16.5.6 CLOCK STRETCHING
FIGURE 16-23:
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 1
DX
SCL
CKP
Master device
asserts clock
Master device
releases clock
WR
SSPxCON1
DS30000684B-page 232
PIC18(L)F2X/45K50
16.5.8 GENERAL CALL ADDRESS SUPPORT
FIGURE 16-24:
SDA
SCL
S
Receiving Data
ACK
D6
D5
D4
D3
D2
D1
D0
SSPIF
BF (SSPxSTAT<0>)
Cleared by software
GCEN (SSPxCON2<7>)
SSPxBUF is read
1
DS30000684B-page 233
PIC18(L)F2X/45K50
16.6
DS30000684B-page 234
PIC18(L)F2X/45K50
16.6.2 CLOCK ARBITRATION
Clock arbitration occurs when the master, during any
receive, transmit or Repeated Start/Stop condition,
releases the SCL pin (SCL allowed to float high). When
the SCL pin is allowed to float high, the Baud Rate Generator (BRG) is suspended from counting until the SCL
pin is actually sampled high. When the SCL pin is sampled high, the Baud Rate Generator is reloaded with
the contents of SSPxADD<7:0> and begins counting.
This ensures that the SCL high time will always be at
least one BRG rollover count in the event that the clock
is held low by an external device (Figure 16-25).
FIGURE 16-25:
SDA
DX 1
DX
SCL deasserted but slave holds
SCL low (clock arbitration)
SCL
BRG decrements on
Q2 and Q4 cycles
BRG
Value
03h
02h
01h
03h
02h
DS30000684B-page 235
PIC18(L)F2X/45K50
16.6.4 I2C MASTER MODE START
CONDITION TIMING
To initiate a Start condition, the user sets the Start
Enable bit, SEN, of the SSPxCON2 register. If the
SDA and SCL pins are sampled high, the Baud Rate
Generator is reloaded with the contents of
SSPxADD<7:0> and starts its count. If SCL and SDA
are both sampled high when the Baud Rate Generator
times out (TBRG), the SDA pin is driven low. The action
of the SDA being driven low while SCL is high is the
Start condition and causes the S bit of the SSPxSTAT1
register to be set. Following this, the Baud Rate Generator is reloaded with the contents of SSPxADD<7:0>
and resumes its count. When the Baud Rate Generator times out (TBRG), the SEN bit of the SSPxCON2
register will be automatically cleared by hardware; the
Baud Rate Generator is suspended, leaving the SDA
line held low and the Start condition is complete.
Note 1: If at the beginning of the Start condition,
the SDA and SCL pins are already sampled low, or if during the Start condition,
the SCL line is sampled low before the
SDA line is driven low, a bus collision
occurs, the Bus Collision Interrupt Flag,
BCLIF, is set, the Start condition is
aborted and the I2C module is reset into
its Idle state.
2: The Philips I2C Specification states that a
bus collision cannot occur on a Start.
FIGURE 16-26:
SDA = 1,
SCL = 1
TBRG
TBRG
SDA
2nd bit
1st bit
TBRG
SCL
S
DS30000684B-page 236
TBRG
PIC18(L)F2X/45K50
16.6.5 I2C MASTER MODE REPEATED
START CONDITION TIMING
A Repeated Start condition occurs when the RSEN bit
of the SSPxCON2 register is programmed high and the
master state machine is no longer active. When the
RSEN bit is set, the SCL pin is asserted low. When the
SCL pin is sampled low, the Baud Rate Generator is
loaded and begins counting. The SDA pin is released
(brought high) for one Baud Rate Generator count
(TBRG). When the Baud Rate Generator times out, if
SDA is sampled high, the SCL pin will be deasserted
(brought high). When SCL is sampled high, the Baud
Rate Generator is reloaded and begins counting. SDA
and SCL must be sampled high for one TBRG. This
action is then followed by assertion of the SDA pin
(SDA= 0) for one TBRG while SCL is high. SCL is
asserted low. Following this, the RSEN bit of the SSPxCON2 register will be automatically cleared and the
Baud Rate Generator will not be reloaded, leaving the
SDA pin held low. As soon as a Start condition is
detected on the SDA and SCL pins, the S bit of the
SSPxSTAT register will be set. The SSPIF bit will not be
set until the Baud Rate Generator has timed out.
Note 1: If RSEN is programmed while any other
event is in progress, it will not take effect.
2: A bus collision during the Repeated Start
condition occurs if:
SDA is sampled low when SCL
goes from low-to-high.
SCL goes low before SDA is
asserted low. This may indicate
that another master is attempting to
transmit a data 1.
FIGURE 16-27:
Write to SSPxCON2
occurs here
SDA = 1,
SCL (no change)
SDA = 1,
SCL = 1
TBRG
TBRG
TBRG
1st bit
SDA
Sr
TBRG
Repeated Start
DS30000684B-page 237
PIC18(L)F2X/45K50
16.6.6 I2C MASTER MODE TRANSMISSION
16.6.6.3
16.6.6.1
BF Status Flag
7.
8.
9.
10.
11.
12.
13.
16.6.6.2
DS30000684B-page 238
R/W
PEN
SEN
BF (SSPxSTAT<0>)
SSPIF
SCL
SDA
A6
A5
A4
A3
A2
A1
Cleared by software
SSPxBUF written
D7
1
SCL held low
while CPU
responds to SSPIF
ACK = 0
R/W = 0
A7
D5
D4
D3
D2
D1
D0
D6
ACKSTAT in
SSPxCON2 = 1
Cleared by software
ACK
FIGURE 16-28:
SEN = 0
PIC18(L)F2X/45K50
DS30000684B-page 239
PIC18(L)F2X/45K50
16.6.7
16.6.7.1
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
16.6.7.3
1.
BF Status Flag
16.6.7.2
DS30000684B-page 240
12.
13.
14.
15.
RCEN
ACKEN
SSPOV
BF
(SSPxSTAT<0>)
SDA = 0, SCL = 1
while CPU
responds to SSPIF
SSPIF
SCL
SDA
A7
4
5
Cleared by software
A6 A5 A4 A3 A2
7
8
ACK
D0
ACK
RCEN cleared
automatically
5
6
Cleared by software
Cleared in
software
ACK
RCEN cleared
automatically
P
Set SSPIF interrupt
at end of Acknowledge sequence
Bus master
terminates
transfer
Set P bit
(SSPxSTAT<4>)
and SSPIF
PEN bit = 1
written here
D0
RCEN cleared
automatically
D7 D6 D5 D4 D3 D2 D1
Cleared by software
Cleared by software
D7 D6 D5 D4 D3 D2 D1
A1 R/W
RCEN = 1, start
next receive
FIGURE 16-29:
RCEN cleared
automatically
SEN = 0
Write to SSPxBUF occurs here,
ACK from Slave
start XMIT
Write to SSPxCON2<4>
to start Acknowledge sequence
SDA = ACKDT (SSPxCON2<5>) = 0
PIC18(L)F2X/45K50
DS30000684B-page 241
PIC18(L)F2X/45K50
16.6.8
ACKNOWLEDGE SEQUENCE
TIMING
16.6.9
16.6.8.1
16.6.9.1
FIGURE 16-30:
TBRG
SDA
ACK
D0
SCL
SSPIF
SSPIF set at
the end of receive
Cleared in
software
Cleared in
software
SSPIF set at the end
of Acknowledge sequence
FIGURE 16-31:
Write to SSPxCON2,
set PEN
Falling edge of
9th clock
TBRG
SCL
SDA
ACK
P
TBRG
TBRG
TBRG
DS30000684B-page 242
PIC18(L)F2X/45K50
16.6.10
SLEEP OPERATION
2
16.6.11
EFFECTS OF A RESET
16.6.12
MULTI-MASTER MODE
Address Transfer
Data Transfer
A Start Condition
A Repeated Start Condition
An Acknowledge Condition
DS30000684B-page 243
PIC18(L)F2X/45K50
16.6.13
FIGURE 16-32:
SDA
SCL
BCLIF
DS30000684B-page 244
PIC18(L)F2X/45K50
16.6.13.1
FIGURE 16-33:
SDA
SCL
Set SEN, enable Start
condition if SDA = 1, SCL = 1
SEN
BCLIF
SSPIF
SSPIF and BCLIF are
cleared by software
DS30000684B-page 245
PIC18(L)F2X/45K50
FIGURE 16-34:
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 16-35:
SDA
SCL
TBRG
SEN
BCLIF
Set SSPIF
SSPIF
SDA = 0, SCL = 1,
set SSPIF
DS30000684B-page 246
Interrupts cleared
by software
PIC18(L)F2X/45K50
16.6.13.2
FIGURE 16-36:
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
S
SSPIF
FIGURE 16-37:
TBRG
SDA
SCL
BCLIF
RSEN
S
SSPIF
DS30000684B-page 247
PIC18(L)F2X/45K50
16.6.13.3
b)
FIGURE 16-38:
TBRG
TBRG
SDA
SDA sampled
low after TBRG,
set BCLIF
SSPIF
FIGURE 16-39:
TBRG
TBRG
SDA
Assert SDA
SCL
PEN
BCLIF
P
SSPIF
DS30000684B-page 248
PIC18(L)F2X/45K50
TABLE 16-3:
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
ANSELB
ANSB5
ANSB4
ANSB3
ANSB2
ANSB1
ANSB0
148
INTCON
Name
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
124
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
121
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
118
MSSPMD
CTMUMD
CMP2MD
CMP1MD
ADCMD
CCP2MD
CCP1MD
PMD1
SSP1ADD
SSP1 Address Register in I2C Slave Mode. SSP1 Baud Rate Reload Register in I2C Master mode.
SSP1BUF
62
257
SSP1CON1
WCOL
SSPOV
SSPEN
CKP
SSP1CON2
GCEN
ACKSTAT
ACKDT
ACKEN
RCEN
PEN
RSEN
SEN
254
SSP1CON3
ACKTIM
PCIE
SCIE
BOEN
SDAHT
SBCDE
AHEN
DHEN
255
SSP1MSK
SSP1STAT
TRISB
Legend:
SSPM<3:0>
252
256
SMP
CKE
D/A
R/W
UA
BF
251
TRISB7
TRISB6
TRISB5
TRISB4
TRISB3
TRISB2
TRISB1
TRISB0
149
DS30000684B-page 249
PIC18(L)F2X/45K50
16.7
The MSSP module has a Baud Rate Generator available for clock generation in both I2C and SPI Master
modes. The Baud Rate Generator (BRG) reload value
is placed in the SSPxADD register (Register 16-6).
When a write occurs to SSPxBUF, the Baud Rate Generator will automatically begin counting down.
EQUATION 16-1:
FOSC
FCLOCK = ------------------------------------------------ SSPxADD + 1 4
FIGURE 16-40:
SSPxM<3:0>
Reload
SCL
Control
SSPxCLK
SSPxADD<7:0>
Reload
FOSC/2
TABLE 16-4:
Note 1:
FOSC
FCY
BRG Value
FCLOCK
(2 Rollovers of BRG)
32 MHz
8 MHz
13h
400 kHz(1)
32 MHz
8 MHz
19h
308 kHz
32 MHz
8 MHz
4Fh
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
09h
100 kHz
The I C interface does not conform to the 400 kHz I C 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.
DS30000684B-page 250
PIC18(L)F2X/45K50
16.8
REGISTER 16-1:
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
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5
bit 4
P: Stop bit
(I2C mode only. This bit is cleared when the MSSP module is disabled, SSPxEN is cleared.)
1 = Indicates that a Stop bit has been detected last (this bit is 0 on Reset)
0 = Stop bit was not detected last
bit 3
S: Start bit
(I2C mode only. This bit is cleared when the MSSP module is disabled, SSPxEN is cleared.)
1 = Indicates that a Start bit has been detected last (this bit is 0 on Reset)
0 = Start bit was not detected last
bit 2
bit 1
bit 0
DS30000684B-page 251
PIC18(L)F2X/45K50
REGISTER 16-2:
R/C/HS-0
R/C/HS-0
R/W-0
R/W-0
WCOL
SSPOV
SSPEN
CKP
R/W-0
R/W-0
R/W-0
R/W-0
SSPM<3:0>
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
C = User cleared
bit 7
bit 6
bit 5
bit 4
DS30000684B-page 252
PIC18(L)F2X/45K50
REGISTER 16-2:
bit 3-0
Note 1:
2:
3:
4:
In Master mode, the overflow bit is not set since each new reception (and transmission) is initiated by writing to the
SSPxBUF register.
When enabled, these pins must be properly configured as input or output.
When enabled, the SDA and SCL pins must be configured as inputs.
SSPxADD values of 0, 1 or 2 are not supported for I2C mode.
DS30000684B-page 253
PIC18(L)F2X/45K50
REGISTER 16-3:
R/W-0
R-0
R/W-0
R/S/HC-0
R/S/HC-0
R/S/HC-0
R/S/HC-0
R/W/HC-0
GCEN
ACKSTAT
ACKDT
ACKEN(1)
RCEN(1)
PEN(1)
RSEN(1)
SEN(1)
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
HC = Cleared by hardware
S = User set
bit 7
GCEN: General Call Enable bit (in I2C Slave mode only)
1 = Enable interrupt when a general call address (0x00 or 00h) is received in the SSPxSR
0 = General call address disabled
bit 6
bit 5
bit 4
ACKEN(1): Acknowledge Sequence Enable bit (in I2C Master mode only)
In Master Receive mode:
1 = Initiate Acknowledge sequence on SDA and SCL pins, and transmit ACKDT data bit.
Automatically cleared by hardware.
0 = Acknowledge sequence idle
bit 3
bit 2
PEN(1): Stop Condition Enable bit (in I2C Master mode only)
SCK Release Control:
1 = Initiate Stop condition on SDA and SCL pins. Automatically cleared by hardware.
0 = Stop condition Idle
bit 1
RSEN(1): Repeated Start Condition Enabled bit (in I2C Master mode only)
1 = Initiate Repeated Start condition on SDA and SCL pins. Automatically cleared by hardware.
0 = Repeated Start condition Idle
bit 0
SEN(1): Start Condition Enabled bit (in I2C Master mode only)
In Master mode:
1 = Initiate Start condition on SDA and SCL pins. Automatically cleared by hardware.
0 = Start condition Idle
In Slave mode:
1 = Clock stretching is enabled for both slave transmit and slave receive (stretch enabled)
0 = Clock stretching is disabled
Note 1:
For bits ACKEN, RCEN, PEN, RSEN, SEN: If the I2C module is not in the Idle mode, this bit may not be
set (no spooling) and the SSPxBUF may not be written (or writes to the SSPxBUF are disabled).
DS30000684B-page 254
PIC18(L)F2X/45K50
REGISTER 16-4:
R-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
ACKTIM
PCIE
SCIE
BOEN
SDAHT
SBCDE
AHEN
DHEN
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
SBCDE: Slave Mode Bus Collision Detect Enable bit (I2C Slave mode only)
If on the rising edge of SCL, SDA is sampled low when the module is outputting a high state, the BCLIF
bit of the PIR2 register is set, and bus goes idle
1 = Enable slave bus collision interrupts
0 = Slave bus collision interrupts are disabled
AHEN: Address Hold Enable bit (I2C Slave mode only)
1 = Following the 8th falling edge of SCL for a matching received address byte; CKP bit of the SSPxCON1 register will be cleared and the SCL will be held low.
0 = Address holding is disabled
bit 1
Note 1:
2:
3:
For daisy-chained SPI operation; allows the user to ignore all but the last received byte. SSPOV is still set
when a new byte is received and BF = 1, but hardware continues to write the most recent byte to
SSPxBUF.
This bit has no effect in Slave modes for which Start and Stop condition detection is explicitly listed as
enabled.
The ACKTIM Status bit is active only when the AHEN bit or DHEN bit is set.
DS30000684B-page 255
PIC18(L)F2X/45K50
REGISTER 16-4:
bit 0
Note 1:
2:
3:
For daisy-chained SPI operation; allows the user to ignore all but the last received byte. SSPOV is still set
when a new byte is received and BF = 1, but hardware continues to write the most recent byte to
SSPxBUF.
This bit has no effect in Slave modes for which Start and Stop condition detection is explicitly listed as
enabled.
The ACKTIM Status bit is active only when the AHEN bit or DHEN bit is set.
REGISTER 16-5:
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
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
bit 7-1
bit 0
DS30000684B-page 256
PIC18(L)F2X/45K50
SSPxADD: MSSP ADDRESS AND BAUD RATE REGISTER (I2C MODE)
REGISTER 16-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
ADD<7:0>
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
Master mode:
bit 7-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
DS30000684B-page 257
PIC18(L)F2X/45K50
17.0
ENHANCED UNIVERSAL
SYNCHRONOUS
ASYNCHRONOUS RECEIVER
TRANSMITTER (EUSART)
FIGURE 17-1:
TXIE
Interrupt
TXIF
TXREGx Register
8
MSb
LSb
(8)
TX/CK pin
Pin Buffer
and Control
TXEN
TRMT
FOSC
TX9
BRG16
+1
SPBRGHx
SPBRGx
DS30000684B-page 258
Multiplier
x4
x16 x64
SYNC
1 X 0 0
BRGH
X 1 1 0
BRG16
X 1 0 1
TX9D
PIC18(L)F2X/45K50
FIGURE 17-2:
RX/DT pin
Data
Recovery
FOSC
BRG16
SPBRGHx
SPBRGx
Multiplier
x4
x16 x64
SYNC
1 X 0 0
BRGH
X 1 1 0
BRG16
X 1 0 1
Stop
RCIDL
RSR Register
MSb
Pin Buffer
and Control
+1
OERR
(8)
LSb
0 START
RX9
FERR
RX9D
RCREGx Register
8
FIFO
Data Bus
RCIF
RCIE
Interrupt
DS30000684B-page 259
PIC18(L)F2X/45K50
17.1
17.1.1.2
Transmitting Data
17.1.1.3
17.1.1
17.1.1.4
EUSART ASYNCHRONOUS
TRANSMITTER
17.1.1.1
Note:
DS30000684B-page 260
PIC18(L)F2X/45K50
17.1.1.5
TSR Status
17.1.1.7
1.
2.
3.
4.
Note:
17.1.1.6
5.
8.
FIGURE 17-3:
Write to TXREGx
BRG Output
(Shift Clock)
TX/CK pin
TXIF bit
(Transmit Buffer
Reg. Empty Flag)
TRMT bit
(Transmit Shift
Reg. Empty Flag)
6.
7.
9.
ASYNCHRONOUS TRANSMISSION
Word 1
Start bit
bit 0
bit 1
bit 7/8
Stop bit
Word 1
1 TCY
Word 1
Transmit Shift Reg
DS30000684B-page 261
PIC18(L)F2X/45K50
FIGURE 17-4:
Write to TXREGx
Word 2
Word 1
BRG Output
(Shift Clock)
TX/CK pin
Start bit
bit 0
bit 1
Word 1
1 TCY
TXIF bit
(Interrupt Reg. Flag)
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
Note:
TABLE 17-1:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
BAUDCON1
ABDOVF
RCIDL
RXDTP
TXCKP
BRG16
WUE
ABDEN
270
INTCON
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
PMD0
USBMD
ACTMD
TMR3MD
TMR2MD TMR1MD
61
SREN
CREN
ADDEN
FERR
RCSTA1
SPEN
UARTMD
RX9
OERR
RX9D
269
SPBRG1
SPBRGH1
TXREG1
TXSTA1
Legend:
CSRC
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
268
= unimplemented locations, read as 0. Shaded bits are not used for asynchronous transmission.
DS30000684B-page 262
PIC18(L)F2X/45K50
17.1.2
EUSART ASYNCHRONOUS
RECEIVER
17.1.2.1
17.1.2.2
Receiving Data
17.1.2.3
DS30000684B-page 263
PIC18(L)F2X/45K50
17.1.2.4
Receive Interrupts
17.1.2.5
17.1.2.7
17.1.2.8
Address Detection
17.1.2.6
DS30000684B-page 264
PIC18(L)F2X/45K50
17.1.2.9
1.
17.1.2.10
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
DS30000684B-page 265
PIC18(L)F2X/45K50
FIGURE 17-5:
ASYNCHRONOUS RECEPTION
Start
bit
bit 0
RX/DT pin
bit 1
Start
bit
Rcv Shift
Reg
Rcv Buffer Reg
bit 0
Start
bit
Word 2
RCREGx
Word 1
RCREGx
RCIDL
Read Rcv
Buffer Reg
RCREGx
RCIF
(Interrupt Flag)
OERR bit
CREN
This timing diagram shows three words appearing on the RX/DT input. The RCREGx (receive buffer) is read after the third
word, causing the OERR (overrun) bit to be set.
Note:
TABLE 17-2:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
BAUDCON1
ABDOVF
RCIDL
RXDTP
TXCKP
BRG16
WUE
ABDEN
270
INTCON
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
PMD0
UARTMD
USBMD
ACTMD
TMR3MD
TMR2MD
TMR1MD
61
RCREG1
RCSTA1
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
269
SPBRG1
SPBRGH1
TRISC
TXSTA1
Legend:
TRISC7
TRISC6
TRISC2
TRISC1
TRISC0
149
CSRC
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
268
= unimplemented locations, read as 0. Shaded bits are not used for asynchronous reception.
DS30000684B-page 266
PIC18(L)F2X/45K50
17.2
DS30000684B-page 267
PIC18(L)F2X/45K50
17.3
REGISTER 17-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:
DS30000684B-page 268
PIC18(L)F2X/45K50
REGISTER 17-2:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R-0
R-0
R-0
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
DS30000684B-page 269
PIC18(L)F2X/45K50
REGISTER 17-3:
R/W-0
R-1
R/W-0
R/W-0
R/W-0
U-0
R/W-0
R/W-0
ABDOVF
RCIDL
RXDTP
TXCKP
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
DS30000684B-page 270
PIC18(L)F2X/45K50
17.4
EXAMPLE 17-1:
16000000
-----------------------9600
= ------------------------ 1
64
= 25.042 = 25
16000000
Calculated Baud Rate = --------------------------64 25 + 1
TABLE 17-3:
CALCULATING BAUD
RATE ERROR
= 9615
Calc. Baud Rate Desired Baud Rate
Error = -------------------------------------------------------------------------------------------Desired Baud Rate
9615 9600
= ---------------------------------- = 0.16%
9600
Configuration Bits
BRG/EUSART Mode
8-bit/Asynchronous
FOSC/[64 (n+1)]
8-bit/Asynchronous
16-bit/Asynchronous
SYNC
BRG16
BRGH
0
0
0
16-bit/Asynchronous
8-bit/Synchronous
16-bit/Synchronous
1
Legend:
FOSC/[16 (n+1)]
FOSC/[4 (n+1)]
DS30000684B-page 271
PIC18(L)F2X/45K50
TABLE 17-4:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
BAUDCON1
ABDOVF
RCIDL
RXDTP
TXCKP
BRG16
WUE
ABDEN
270
UARTMD
USBMD
ACTMD
SPEN
RX9
SREN
CREN
ADDEN
PMD0
RCSTA1
SPBRG1
SPBRGH1
PIR1
TXSTA1
Legend:
OERR
61
RX9D
269
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
CSRC
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
268
TABLE 17-5:
BAUD
RATE
300
Actual
Rate
%
Error
SPBRxG
value
(decimal)
1200
0.00
239
1202
0.16
207
1200
0.00
143
Actual
Rate
%
Error
SPBRGx
value
(decimal)
Actual
Rate
%
Error
SPBRGx
value
(decimal)
Actual
Rate
%
Error
SPBRGx
value
(decimal)
1200
2400
2400
0.00
119
2404
0.16
103
2400
0.00
71
9600
9615
0.16
77
9600
0.00
29
9615
0.16
25
9600
0.00
17
10417
10417
0.00
71
10286
-1.26
27
10417
0.00
23
10165
-2.42
16
19.2k
19.23k
0.16
38
19.20k
0.00
14
19.23k
0.16
12
19.20k
0.00
57.6k
57.69k
0.16
12
57.60k
0.00
57.60k
0.00
115.2k
%
Error
SPBRGx
value
(decimal)
%
Error
SPBRGx
value
(decimal)
Actual
Rate
%
Error
SPBRGx
value
(decimal)
Actual
Rate
%
Error
SPBRGx
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
DS30000684B-page 272
PIC18(L)F2X/45K50
TABLE 17-5:
BAUD
RATE
%
Error
SPBRGx
value
(decimal)
%
Error
SPBRGx
value
(decimal)
%
Error
SPBRGx
value
(decimal)
Actual
Rate
%
Error
SPBRGx
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
155
19.20k
0.00
59
19.23k
0.16
51
19.20k
0.00
35
57.6k
57.97k
0.16
51
57.60k
0.00
19
58.82k
2.12
16
57.60k
0.00
11
115.2k
115.39k
0.16
25
115.2k
0.00
111.1k
-3.55
115.2k
0.00
%
Error
SPBRGx
value
(decimal)
Actual
Rate
%
Error
SPBRGx
value
(decimal)
Actual
Rate
%
Error
SxBRGx
value
(decimal)
Actual
Rate
%
Error
SPBRGx
value
(decimal)
207
300
300
0.16
1200
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
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
SPBRGHx:
SPBRGx
(decimal)
Actual
Rate
%
Error
SPBRGHx:
SPBRGx
(decimal)
%
Error
SPBRGHx
:SPBRGx
(decimal)
Actual
Rate
%
Error
SPBRGHx:
SPBRGx
(decimal)
300
300.0
0.00
9999
300.0
0.00
3839
300.03
0.01
3332
300.0
0.00
2303
1200
1200
0.00
2499
1200
0.00
959
1200.5
0.04
832
1200
0.00
575
2400
2400
0.00
1249
2400
0.00
479
2398
-0.08
416
2400
0.00
287
9600
9585
-0.16
312
9600
0.00
119
9615
0.16
103
9600
0.00
71
10417
10417
0.00
287
10378
-0.37
110
10417
0.00
95
10473
0.53
65
19.2k
19.23k
0.16
155
19.20k
0.00
59
19.23k
0.16
51
19.20k
0.00
35
57.6k
57.69k
0.16
51
57.60k
0.00
19
58.82k
2.12
16
57.60k
0.00
11
115.2k
115.39k
0.16
25
115.2k
0.00
111.11k
-3.55
115.2k
0.00
DS30000684B-page 273
PIC18(L)F2X/45K50
TABLE 17-5:
BAUD
RATE
Actual
Rate
%
Error
SPBRGHx:
SPBRGx
(decimal)
Actual
Rate
%
Error
SPBRGHx:
SPBRGx
(decimal)
Actual
Rate
%
Error
SPBRGHx
:SPBRGx
(decimal)
Actual
Rate
%
Error
SPBRGHx:
SPBRGx
(decimal)
207
300
299.9
-0.02
1666
300.1
0.04
832
300.0
0.00
767
300.5
0.16
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
%
Error
SPBRGHx:
SPBRGx
(decimal)
%
Error
SPBRGHx:
SPBRGx
(decimal)
%
Error
SPBRGHx
:SPBRGx
(decimal)
Actual
Rate
%
Error
SPBRGHx:
SPBRGx
(decimal)
300
300
0.00
39999
300.0
0.00
15359
300.0
0.00
13332
300.0
0.00
9215
1200
1200
0.00
9999
1200
0.00
3839
1200.1
0.01
3332
1200
0.00
2303
2400
2400
0.00
4999
2400
0.00
1919
2399.5
-0.02
1666
2400
0.00
1151
9600
9600
0.00
1249
9600
0.00
479
9592
-0.08
416
9600
0.00
287
10417
10417
0.00
1151
10425
0.08
441
10417
0.00
383
10433
0.16
264
143
19.2k
19.2k
0.00
624
19.20k
0.00
239
19.23k
0.16
207
19.20k
0.00
57.6k
57.69k
0.16
207
57.60k
0.00
79
57.97k
0.64
68
57.60k
0.00
47
115.2k
115.39k
0.16
103
115.2k
0.00
39
114.29k
-0.79
34
115.2k
0.00
23
%
Error
SPBRGHx:
SPBRGx
(decimal)
Actual
Rate
%
Error
SPBRGHx:
SPBRGx
(decimal)
Actual
Rate
%
Error
SPBRGHx
:SPBRGx
(decimal)
Actual
Rate
%
Error
SPBRGHx:
SPBRGx
(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
DS30000684B-page 274
PIC18(L)F2X/45K50
17.4.1
AUTO-BAUD DETECT
TABLE 17-6:
FIGURE 17-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
0000h
RX/DT pin
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
RCREGx
SPBRGx
XXh
1Ch
SPBRGHx
XXh
00h
Note 1:
The ABD sequence requires the EUSART module to be configured in Asynchronous mode.
DS30000684B-page 275
PIC18(L)F2X/45K50
17.4.2
AUTO-BAUD OVERFLOW
17.4.3.1
Special Considerations
Break Character
17.4.3
AUTO-WAKE-UP ON BREAK
DS30000684B-page 276
PIC18(L)F2X/45K50
FIGURE 17-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:
FIGURE 17-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:
Sleep Ends
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.
DS30000684B-page 277
PIC18(L)F2X/45K50
17.4.4
17.4.4.1
17.4.5
FIGURE 17-9:
Write to TXREGx
BRG Output
(Shift Clock)
TX/CK (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)
DS30000684B-page 278
Auto Cleared
PIC18(L)F2X/45K50
17.5
17.5.1
SYNC = 1
CSRC = 1
SREN = 0 (for transmit); SREN = 1 (for receive)
CREN = 0 (for transmit); CREN = 1 (for receive)
SPEN = 1
17.5.1.2
Clock Polarity
17.5.1.3
17.5.1.4
Data Polarity
17.5.1.1
Master Clock
DS30000684B-page 279
PIC18(L)F2X/45K50
17.5.1.5
1.
2.
3.
4.
5.
6.
7.
FIGURE 17-10:
8.
9.
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
TXREGx Reg
Write Word 1
Write Word 2
TXIF bit
(Interrupt Flag)
TRMT bit
TXEN bit
Note:
1
Sync Master mode, SPBRGx = 0, continuous transmission of two 8-bit words.
FIGURE 17-11:
bit 0
bit 1
bit 2
bit 6
bit 7
TX/CK pin
Write to
TXREGx reg
TXIF bit
TRMT bit
TXEN bit
DS30000684B-page 280
PIC18(L)F2X/45K50
TABLE 17-7:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
BAUDCON1
ABDOVF
RCIDL
RXDTP
TXCKP
BRG16
WUE
ABDEN
270
INTCON
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
PMD0
UARTMD
USBMD
ACTMD
SPEN
RX9
SREN
CREN
ADDEN
RCSTA1
OERR
RX9D
61
269
SPBRG1
SPBRGH1
TRISC
TXREG1
TXSTA1
Legend:
TRISC7
TRISC6
TRISC2
TRISC1
TRISC0
TX9
149
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
268
= unimplemented locations, read as 0. Shaded bits are not used for synchronous master transmission.
DS30000684B-page 281
PIC18(L)F2X/45K50
17.5.1.6
17.5.1.7
Slave Clock
17.5.1.8
DS30000684B-page 282
17.5.1.9
17.5.1.10
1.
PIC18(L)F2X/45K50
FIGURE 17-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
RCREGx
Note:
Timing diagram demonstrates Sync Master mode with bit SREN = 1 and bit BRGH = 0.
TABLE 17-8:
Name
Bit 6
BAUDCON1
ABDOVF
RCIDL
INTCON
GIE/GIEH PEIE/GIEL
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
RXDTP
TXCKP
BRG16
WUE
ABDEN
270
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
UARTMD
USBMD
ACTMD
TMR3MD
TMR2MD
TMR1MD
61
CREN
ADDEN
FERR
OERR
RX9D
269
PMD0
RCREG1
RCSTA1
RX9
SREN
SPBRG1
SPBRGH1
TXSTA1
Legend:
CSRC
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
268
= unimplemented locations, read as 0. Shaded bits are not used for synchronous master reception.
DS30000684B-page 283
PIC18(L)F2X/45K50
17.5.2
SYNC = 1
CSRC = 0
SREN = 0 (for transmit); SREN = 1 (for receive)
CREN = 0 (for transmit); CREN = 1 (for receive)
SPEN = 1
17.5.2.1
5.
17.5.2.2
1.
2.
3.
4.
5.
6.
7.
8.
DS30000684B-page 284
PIC18(L)F2X/45K50
TABLE 17-9:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
BAUDCON1
ABDOVF
RCIDL
RXDTP
TXCKP
BRG16
WUE
ABDEN
270
INTCON
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
PIR1
ACTIF
ADIF
RCIF
TXIF
SSP1F
CCP1IF
TMR2IF
TMR1IF
117
PMD0
UARTMD
USBMD
ACTMD
TMR3MD
TMR2MD
TMR1MD
61
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
269
RCSTA1
SPBRG1
SPBRGH1
TRISC
TXREG1
TXSTA1
Legend:
TRISC7
TRISC6
TRISC2
TRISC1
TRISC0
149
TX9
TXEN
SYNC
SENDB
BRGH
TRMT
TX9D
268
= unimplemented locations, read as 0. Shaded bits are not used for synchronous slave transmission.
DS30000684B-page 285
PIC18(L)F2X/45K50
17.5.2.3
17.5.2.4
1.
2.
3.
4.
5.
6.
7.
8.
9.
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
BAUDCON1
ABDOVF
RCIDL
RXDTP
TXCKP
BRG16
WUE
ABDEN
270
INTCON
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
PMD0
UARTMD
USBMD
ACTMD
TMR3MD
TMR2MD
TMR1MD
61
RCREG1
RCSTA1
RX9
SREN
CREN
SPBRG1
SPBRGH1
TXSTA1
Legend:
CSRC
TX9
TXEN
SYNC
ADDEN
FERR
OERR
RX9D
269
SENDB
BRGH
TRMT
TX9D
268
= unimplemented locations, read as 0. Shaded bits are not used for synchronous slave reception.
DS30000684B-page 286
PIC18(L)F2X/45K50
18.0
ANALOG-TO-DIGITAL
CONVERTER (ADC) MODULE
FIGURE 18-1:
FVR BUF2
11111
DAC
11110
CTMU
11101
Temperature Diode
AN27(1)
CHS<4:0>
11100
11011
ADCMD
AN5(1)
00101
AN4
00100
AN3
00011
AN2
AN1
AN0
ADON
10-Bit ADC
GO/DONE
10
00010
ADFM
00001
0 = Left Justify
1 = Right Justify
00000
10
2
PVCFG<1:0>
ADRESH
AVDD
VREF+/AN3
01
FVR BUF2
10
Reserved
11
2
AVSS
VREF-/AN2
ADRESL
00
NVCFG<1:0>
00
01
Reserved
10
Reserved
11
Note: Additional ADC channels AN5-AN7 and AN20-AN27 are only available on PIC18(L)F45K50 devices.
DS30000684B-page 287
PIC18(L)F2X/45K50
18.1
ADC Configuration
Port configuration
Channel selection
ADC voltage reference selection
ADC conversion clock source
Interrupt control
Results formatting
18.1.1
PORT CONFIGURATION
18.1.2
CHANNEL SELECTION
DS30000684B-page 288
18.1.3
18.1.4
PIC18(L)F2X/45K50
18.1.5
CONVERSION CLOCK
18.1.6
FOSC/2
FOSC/4
FOSC/8
FOSC/16
FOSC/32
FOSC/64
FRC (dedicated internal oscillator)
Note:
TABLE 18-1:
ADCS<2:0>
000
100
ns(2)
83.3
ns(2)
ns(2)
FOSC/8
001
166.7
FOSC/16
101
333.3 ns(2)
FOSC/32
010
ns(2)
FOSC/64
110
FRC
Legend:
Note 1:
2:
3:
4:
Note:
INTERRUPTS
011
666.7
1.3 s
1-4
s(1,4)
16 MHz
4 MHz
1 MHz
2.0 s
125
ns(2)
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)
4.0 s(3)
1-4
s(1,4)
500
8.0
1-4
ns(2)
DS30000684B-page 289
PIC18(L)F2X/45K50
18.1.7
RESULT FORMATTING
FIGURE 18-2:
(ADFM = 0)
ADRESL
MSB
LSB
bit 7
bit 0
bit 7
Unimplemented: Read as 0
MSB
(ADFM = 1)
bit 7
Unimplemented: Read as 0
DS30000684B-page 290
bit 0
LSB
bit 0
bit 7
bit 0
10-bit A/D Result
PIC18(L)F2X/45K50
18.2
ADC Operation
18.2.1
STARTING A CONVERSION
FIGURE 18-3:
Note:
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 18-4:
TAD Cycles
TACQT Cycles
1
Automatic
Acquisition
Time
10
11
b9
b8
b7
b6
b5
b4
b3
b2
b1
b0
Conversion starts
(Holding capacitor is disconnected from analog input)
Set GO bit
(Holding capacitor continues
acquiring input)
2 TAD
Discharge
DS30000684B-page 291
PIC18(L)F2X/45K50
18.2.2
COMPLETION OF A CONVERSION
18.2.3
DISCHARGE
18.2.4
TERMINATING A CONVERSION
18.2.5
18.2.6
DS30000684B-page 292
18.2.7
18.2.8
18.2.9
PIC18(L)F2X/45K50
18.2.10
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).
EXAMPLE 18-1:
A/D CONVERSION
DS30000684B-page 293
PIC18(L)F2X/45K50
18.3
Note:
REGISTER 18-1:
U-0
R/W-0
R/W-0
R/W-0
R/W-0
CHS<4:0>
R/W-0
R/W-0
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
Unimplemented: Read as 0
bit 6-2
bit 1
bit 0
Note 1:
2:
DS30000684B-page 294
PIC18(L)F2X/45K50
REGISTER 18-2:
R/W-0
U-0
U-0
U-0
TRIGSEL
R/W-0
R/W-0
R/W-0
PVCFG<1:0>
R/W-0
NVCFG<1:0>
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-4
Unimplemented: Read as 0
bit 3-2
bit 1-0
x = Bit is unknown
DS30000684B-page 295
PIC18(L)F2X/45K50
REGISTER 18-3:
R/W-0
U-0
ADFM
R/W-0
R/W-0
R/W-0
R/W-0
ACQT<2:0>
R/W-0
R/W-0
ADCS<2:0>
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.
DS30000684B-page 296
PIC18(L)F2X/45K50
REGISTER 18-4:
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
ADRES<9:2>
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 18-5:
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
ADRES<1:0>
bit 7
bit 0
Legend:
r = Reserved bit
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 18-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
ADRES<9:8>
bit 7
bit 0
Legend:
r = Reserved bit
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 18-7:
R/W-x
x = Bit is unknown
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
ADRES<7:0>
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
DS30000684B-page 297
PIC18(L)F2X/45K50
18.4
EQUATION 18-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.05 s/ 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.
DS30000684B-page 298
PIC18(L)F2X/45K50
FIGURE 18-5:
ANx
RIC 1k
CPIN
5 pF
I LEAKAGE(1)
Sampling
Switch
SS Rss
CHOLD = 13.5 pF
Legend: CPIN
= Input Capacitance
I LEAKAGE = Leakage current at the pin due to
various junctions
= Interconnect Resistance
RIC
SS
= Sampling Switch
CHOLD
= Sample/Hold Capacitance
Note 1:
VDD
Discharge
Switch
VSS/VREF-
3.5V
3.0V
2.5V
2.0V
1.5V
.1
1
10
Rss (k)
100
FIGURE 18-6:
Full-Scale Range
3FFh
3FEh
ADC Output Code
3FDh
3FCh
3FBh
Full-Scale
Transition
004h
003h
002h
001h
000h
VSS/VREF-
Zero-Scale
Transition
VDD/VREF+
DS30000684B-page 299
PIC18(L)F2X/45K50
TABLE 18-2:
Name
Bit 6
Bit 5
ADCON0
ADCON1
TRIGSEL
ADFM
ADCON2
ADRESL
Bit 3
Bit 2
CHS<4:0>
ADRESH
ANSELA
Bit 4
PVCFG<1:0>
Bit 1
Bit 0
GO/DONE
ADON
NVCFG<1:0>
ACQT<2:0>
ADCS<2:0>
Register
on page
294
295
296
297
297
ANSA5
ANSA3
ANSA2
ANSA1
ANSA0
147
148
ANSELB
ANSB5
ANSB4
ANSB3
ANSB2
ANSB1
ANSB0
ANSELC
ANSC7
ANSC6
ANSC2
148
ANSELD(1)
ANSD7
ANSD6
ANSD5
ANSD4
ANSD3
ANSD2
ANSD1
ANSD0
148
ANSELE(1)
ANSE2
ANSE1
ANSE0
149
322
CTMUCONH
CTMUEN
CTMUSIDL
TGEN
EDGEN
EDGSEQEN
IDISSEN
CTTRIG
INTCON
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR1
ACTIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
123
PIE1
ACTIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
120
PIR1
ACTIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
117
PMD1
MSSPMD
CTMUMD
CMP2MD
CMP1MD
ADCMD
CCP2MD
CCP1MD
62
TRISA
TRISA7
TRISA6
TRISA5
TRISA4
TRISA3
TRISA2
TRISA1
TRISA0
149
149
TRISB
TRISB7
TRISB6
TRISB5
TRISB4
TRISB3
TRISB2
TRISB1
TRISB0
TRISC
TRISC7
TRISC6
TRISC2
TRISC1
TRISC0
149
TRISD(1)
TRISD7
TRISD6
TRISD5
TRISD4
TRISD3
TRISD2
TRISD1
TRISD0
149
TRISE
WPUE3
TRISE2(1)
TRISE1(1)
TRISE0(1)
149
Legend:
= unimplemented locations, read as 0. Shaded bits are not used by this module.
Available on PIC18(L)F45K50 devices.
Note 1:
TABLE 18-3:
Name
CONFIG3H
Legend:
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
MCLRE
SDOMX
T3CMX
PBADEN
CCP2MX
376
= unimplemented locations, read as 0. Shaded bits are not used by the ADC module.
DS30000684B-page 300
PIC18(L)F2X/45K50
19.0
COMPARATOR MODULE
19.1
Comparator Overview
FIGURE 19-1:
SINGLE COMPARATOR
VIN+
VIN-
Output
VINVIN+
Output
Note:
DS30000684B-page 301
PIC18(L)F2X/45K50
FIGURE 19-2:
CxCH<1:0>
2
C12IN0-
C12IN1-
C12IN2-
CxON(1)
CxSP
D
CxVIN-
C12IN3-
CxVIN+
Q1
(2),(3)
EN
Cx
+
D
Q3(2)
DAC Output
Read or Write
of CMxCON0
FVR BUF1 1
To Interrupts
(CxIF)
Reset
0
1
EN
CL
CxR
CxIN+
To CMxCON0 (CxOUT)
CM2CON1 (MCxOUT)
async_CXOUT
CxPOL
CxSYNC
CXVREF
to PWM Logic
CxOE
TRIS bit
0
CXRSEL
CxOUT
Timer1 Clock
sync_CxOUT
- to SR Latch
- to TxG MUX(4)
Note 1:
2:
3:
4:
When C1ON = 0, the C1 comparator will produce a 0 output to the XOR Gate.
Q1 and Q3 are phases of the four-phase system clock (FOSC).
Q1 is held high during Sleep mode.
Synchronized comparator output should not be used to gate Timer1 in conjunction with synchronized T1CKI.
DS30000684B-page 302
PIC18(L)F2X/45K50
19.2
Comparator Control
Enable
Input selection
Reference selection
Output selection
Output polarity
Speed selection
19.2.1
COMPARATOR ENABLE
19.2.2
19.2.3
COMPARATOR REFERENCE
SELECTION
19.2.4
COMPARATOR OUTPUT
SELECTION
19.2.5
TABLE 19-1:
COMPARATOR OUTPUT
STATE VS. INPUT
CONDITIONS
Input Condition
CxPOL
CxOUT
19.2.6
19.3
DS30000684B-page 303
PIC18(L)F2X/45K50
19.4
DS30000684B-page 304
19.4.1
FIGURE 19-3:
COMPARATOR
INTERRUPT TIMING W/O
CMxCON0 READ
Q1
Q3
CxIN+
TRT
CxIN
Set CxIF (edge)
CxIF
Reset by Software
FIGURE 19-4:
COMPARATOR
INTERRUPT TIMING WITH
CMxCON0 READ
Q1
Q3
CxIN+
TRT
CxOUT
Set CxIF (edge)
CxIF
Cleared by CMxCON0 Read
Reset by Software
PIC18(L)F2X/45K50
19.5
19.7
19.6
Effects of a Reset
FIGURE 19-5:
Rs < 10K
RIC
To Comparator
AIN
VA
CPIN
5 pF
VT 0.6V
ILEAKAGE(1)
Vss
Legend: CPIN
= Input Capacitance
ILEAKAGE = Leakage Current at the pin due to various junctions
= Interconnect Resistance
RIC
RS
= Source Impedance
= Analog Voltage
VA
= Threshold Voltage
VT
Note 1: See Section 29.0 Electrical Specifications.
DS30000684B-page 305
PIC18(L)F2X/45K50
19.8
19.8.1
SIMULTANEOUS COMPARATOR
OUTPUT READ
19.8.2
INTERNAL REFERENCE
SELECTION
19.8.3
SYNCHRONIZING COMPARATOR
OUTPUT TO TIMER1
DS30000684B-page 306
PIC18(L)F2X/45K50
19.9
REGISTER 19-1:
R/W-0
R-0
R/W-0
R/W-0
R/W-1
R/W-0
CxON
CxOUT
CxOE
CxPOL
CxSP
CxR
R/W-0
R/W-0
CxCH<1:0>
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: CxOE = 1, CxON = 1 and corresponding port
TRIS bit = 0.
DS30000684B-page 307
PIC18(L)F2X/45K50
REGISTER 19-2:
R-0
R-0
R/W-0
R/W-0
U-0
U-0
R/W-0
R/W-0
MC1OUT
MC2OUT
C1RSEL
C2RSEL
C1SYNC
C2SYNC
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-2
bit 1
bit 0
DS30000684B-page 308
PIC18(L)F2X/45K50
TABLE 19-2:
Name
ANSELA
ANSELB
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
ANSA5
ANSA3
ANSA2
ANSA1
ANSA0
147
ANSB5
ANSB4
ANSB3
ANSB2
ANSB1
ANSB0
148
CM2CON1
MC1OUT
MC2OUT
C1RSEL
C2RSEL
C1HYS
C2HYS
C1SYNC
C2SYNC
308
CM1CON0
C1ON
C1OUT
C1OE
C1POL
C1SP
C1R
C1CH<1:0>
307
CM2CON0
C2ON
C2OUT
C2OE
C2POL
C2SP
C2R
C2CH<1:0>
307
VREFCON1
DACEN
DACLPS
DACOE
VREFCON2
FVREN
FVRST
VREFCON0
INTCON
GIE/GIEH PEIE/GIEL
DACPSS<1:0>
DACNSS
DACR<4:0>
FVRS<1:0>
334
335
331
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
124
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
121
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
118
PMD1
MSSPMD
TRISA
TRISA7
TRISA6
TRISA5
TRISA4
TRISA3
TRISA2
TRISA1
TRISA0
149
TRISB
TRISB7
TRISB6
TRISB5
TRISB4
TRISB3
TRISB2
TRISB1
TRISB0
149
ADCMD
CCP2MD CCP1MD
62
Legend: = unimplemented locations, read as 0. Shaded bits are not used by the comparator module.
DS30000684B-page 309
PIC18(L)F2X/45K50
20.0
CHARGE TIME
MEASUREMENT UNIT (CTMU)
FIGURE 20-1:
CTMUCONH/CTMUCONL
EDGEN
EDGSEQEN
EDG1SELx
EDG1POL
EDG2SELx
EDG2POL
CTED1
CTED2
CCP2
ECCP1
CTMUICON
ITRIM<5:0>
IRNG<1:0>
EDG1STAT
EDG2STAT
Edge
Control
Logic
Current Source
Current
Control
TGEN
IDISSEN
CTTRIG
CTMU
Control
Logic
Pulse
Generator
CTPLS
Comparator 2 Output
Comparator C1/C2 Input
A/D Converter
A/D Special Event Trigger
DS30000684B-page 310
PIC18(L)F2X/45K50
20.1
CTMU Operation
20.1.2
CURRENT SOURCE
If the CTMU is being used as a time delay, both capacitance and current source are fixed, as well as the voltage
supplied to the comparator circuit. The delay of a signal
is determined by the amount of time it takes the voltage
to charge to the comparator threshold voltage.
20.1.1
20.1.3
THEORY OF OPERATION
dV
dT
t = C V I
or by:
C = I t V
using a fixed time that the current source is applied to
the circuit.
DS30000684B-page 311
PIC18(L)F2X/45K50
20.1.4
EDGE STATUS
20.1.5
INTERRUPTS
20.2
DS30000684B-page 312
PIC18(L)F2X/45K50
20.3
FIGURE 20-2:
20.3.1
4.
5.
6.
PIC18(L)FXXK50 Device
CTMU
Current Source
A/D Converter
ANx
RCAL
A/D
MUX
DS30000684B-page 313
PIC18(L)F2X/45K50
EXAMPLE 20-1:
#include "p18cxxx.h"
/**************************************************************************/
/*Set up CTMU *****************************************************************/
/**************************************************************************/
void setup(void)
{ //CTMUCONH/1 - CTMU Control registers
CTMUCONH = 0x00;
//make sure CTMU is disabled
CTMUCONL = 0x90;
//CTMU continues to run when emulator is stopped,CTMU continues
//to run in idle mode,Time Generation mode disabled, Edges are blocked
//No edge sequence order, Analog current source not grounded, trigger
//output disabled, Edge2 polarity = positive level, Edge2 source =
//source 0, Edge1 polarity = positive level, Edge1 source = source 0,
// ADCON1
ADCON1bits.PVCFG0 =0;
ADCON1bits.NVCFG1 =0;
// ADCON0
ADCON0bits.CHS=2;
ADCON0bits.ADON=1;
// Vref+ = AVdd
// Vref- = AVss
// Select ADC channel
// Turn on ADC
DS30000684B-page 314
PIC18(L)F2X/45K50
EXAMPLE 20-2:
#include "p18cxxx.h"
#define COUNT 500
#define DELAY for(i=0;i<COUNT;i++)
#define RCAL .027
DELAY;
CTMUCONLbits.EDG1STAT = 0;
PIR1bits.ADIF = 0;
ADCON0bits.GO=1;
while(!PIR1bits.ADIF);
Vread = ADRES;
PIR1bits.ADIF = 0;
VTot += Vread;
}
Vavg = (float)(VTot/10.000);
Vcal = (float)(Vavg/ADSCALE*ADREF);
CTMUISrc = Vcal/RCAL;
//Average of 10 readings
//CTMUISrc is in 1/100ths of uA
DS30000684B-page 315
PIC18(L)F2X/45K50
20.3.2
CAPACITANCE CALIBRATION
DS30000684B-page 316
PIC18(L)F2X/45K50
EXAMPLE 20-3:
#include "p18cxxx.h"
#define
#define
#define
#define
bits
#define
#define
COUNT 25
ETIME COUNT*2.5
DELAY for(i=0;i<COUNT;i++)
ADSCALE 1023
ADREF 3.3
RCAL .027
int main(void)
{
int i;
int j = 0;
//index for loop
unsigned int Vread = 0;
float CTMUISrc, CTMUCap, Vavg, VTot, Vcal;
//assume CTMU and A/D have been set up correctly
//see Example 25-1 for CTMU & A/D setup
setup();
CTMUCONHbits.CTMUEN = 1;
CTMUCONLbits.EDG1STAT = 0;
CTMUCONLbits.EDG2STAT = 0;
for(j=0;j<10;j++)
{
CTMUCONHbits.IDISSEN = 1;
DELAY;
CTMUCONHbits.IDISSEN = 0;
CTMUCONLbits.EDG1STAT = 1;
DELAY;
CTMUCONLbits.EDG1STAT = 0;
PIR1bits.ADIF = 0;
ADCON0bits.GO=1;
while(!PIR1bits.ADIF);
Vread = ADRES;
PIR1bits.ADIF = 0;
VTot += Vread;
}
Vavg = (float)(VTot/10.000);
Vcal = (float)(Vavg/ADSCALE*ADREF);
CTMUISrc = Vcal/RCAL;
CTMUCap = (CTMUISrc*ETIME/Vcal)/100;
//Average of 10 readings
//CTMUISrc is in 1/100ths of uA
DS30000684B-page 317
PIC18(L)F2X/45K50
20.4
20.4.1
ABSOLUTE CAPACITANCE
MEASUREMENT
8.
DS30000684B-page 318
20.4.2
RELATIVE CHARGE
MEASUREMENT
PIC18(L)F2X/45K50
EXAMPLE 20-4:
#include "p18cxxx.h"
#define
#define
#define
#define
COUNT 500
DELAY for(i=0;i<COUNT;i++)
OPENSW 1000
TRIP 300
#define HYST 65
#define PRESSED 1
#define UNPRESSED 0
int main(void)
{
unsigned int Vread;
unsigned int switchState;
int i;
CTMUCONLbits.EDG1STAT = 1;
DELAY;
CTMUCONLbits.EDG1STAT = 0;
PIR1bits.ADIF = 0;
ADCON0bits.GO=1;
while(!PIR1bits.ADIF);
Vread = ADRES;
DS30000684B-page 319
PIC18(L)F2X/45K50
20.5
FIGURE 20-3:
EDG1
CTED2
EDG2
Current Source
Output Pulse
ANX
A/D Converter
CAD
RPR
DS30000684B-page 320
PIC18(L)F2X/45K50
20.6
FIGURE 20-4:
4.
5.
Initialize Comparator 2.
Initialize the comparator voltage reference.
Initialize the CTMU and enable time delay
generation by setting the TGEN bit.
Set EDG1STAT.
When CPULSE charges to the value of the voltage
reference trip point, an output pulse is generated
on CTPLS.
EDG1
CTMU
CTPLS
Current Source
Comparator
C12IN1-
CPULSE
20.7
20.7.1
C2
CVREF
20.7.2
IDLE MODE
20.8
DS30000684B-page 321
PIC18(L)F2X/45K50
20.9
20.10 Registers
CTMUCONH
CTMUCONL
CTMUICON
R/W-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
U-0
CTMUEN
CTMUSIDL
TGEN
EDGEN
EDGSEQEN
IDISSEN
CTTRIG
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
Unimplemented: Read as 0
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
DS30000684B-page 322
x = Bit is unknown
PIC18(L)F2X/45K50
REGISTER 20-2:
R/W-0
R/W-0
EDG2POL
R/W-0
EDG2SEL<1:0>
R/W-0
EDG1POL
R/W-0
R/W-0
EDG1SEL<1:0>
R/W-0
R/W-0
EDG2STAT
EDG1STAT
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-5
bit 4
bit 3-2
bit 1
bit 0
x = Bit is unknown
DS30000684B-page 323
PIC18(L)F2X/45K50
REGISTER 20-3:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
ITRIM<5:0>
R/W-0
IRNG<1:0>
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
TABLE 20-1:
Name
x = Bit is unknown
Bit 6
Bit 5
CTMUSIDL
CTMUCONH
CTMUEN
CTMUCONL
EDG2POL
EDG2SEL<1:0>
CTMUICON
Bit 4
Bit 3
Bit 2
TGEN
EDGEN
EDGSEQEN
EDG1POL
EDG1SEL<1:0>
ITRIM<5:0>
Bit 0
Register
on page
IDISSEN
CTTRIG
322
EDG2STAT
EDG1STAT
323
Bit 1
IRNG<1:0>
324
IPR3
CTMUIP
USBIP
TMR3GIP
TMR1GIP
125
PIE3
CTMUIE
USBIE
TMR3GIE
TMR1GIE
122
USBIF
TMR3GIF
TMR1GIF
119
ADCMD
CCP2MD
CCP1MD
62
PIR3
CTMUIF
PMD1
MSSPMD
CTMUMD
CMP2MD
CMP1MD
Legend:
= Unimplemented, read as 0. Shaded bits are not used during CTMU operation.
DS30000684B-page 324
PIC18(L)F2X/45K50
21.0
SR LATCH
21.1
Latch Operation
21.2
Latch Output
21.3
21.4
Effects of a Reset
DS30000684B-page 325
PIC18(L)F2X/45K50
FIGURE 21-1:
3
SRCLK<2:0>
Programmable
SRCLK divider
1:4 to 1:512
Peripheral
Clock
t0
t0+4
t0+8
DIVSRCLK
4-512 cycles
...
t0+12
Tosc
SRCLK<2:0> = "001"
1:8
FIGURE 21-2:
SRPS
Pulse
Gen(2)
SRLEN
SRQEN
SRI
S
SRSPE
DIVSRCLK
Q
SRQ
SRSCKE
sync_C2OUT(3)
SRSC2E
sync_C1OUT(3)
SRSC1E
SRPR
SR
Latch(1)
Pulse
Gen(2)
SRI
SRRPE
DIVSRCLK
SRRCKE
sync_C2OUT(3)
SRRC2E
Q
SRNQ
SRLEN
SRNQEN
sync_C1OUT(3)
SRRC1E
Note 1:
2:
3:
DS30000684B-page 326
If R = 1 and S = 1 simultaneously, Q = 0, Q = 1
Pulse generator causes a pulse width of 2 TOSC clock cycles.
Name denotes the connection point at the comparator output.
PIC18(L)F2X/45K50
TABLE 21-1:
SRCLK<2:0>
Divider
FOSC = 20 MHz
FOSC = 16 MHz
111
512
25.6 s
32 s
64 s
128 s
512 s
110
256
12.8 s
16 s
32 s
64 s
256 s
101
128
6.4 s
8 s
16 s
32 s
128 s
100
64
3.2 s
4 s
8 s
16 s
64 s
011
32
1.6 s
2 s
4 s
8 s
32 s
010
16
0.8 s
1 s
2 s
4 s
16 s
001
0.4 s
0.5 s
1 s
2 s
8 s
000
0.2 s
0.25 s
0.5 s
1 s
4 s
FOSC = 1 MHz
DS30000684B-page 327
PIC18(L)F2X/45K50
21.5
REGISTER 21-1:
R/W-0
SRLEN
R/W-0
R/W-0
SRCLK<2:0>
R/W-0
R/W-0
R/W-0
R/W-0
SRQEN
SRNQEN
SRPS
SRPR
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-4
bit 3
bit 2
bit 1
bit 0
Note 1:
2:
Changing the SRCLK bits while the SR latch is enabled may cause false triggers to the Set and Reset
inputs of the latch.
Set only, always reads back 0.
DS30000684B-page 328
PIC18(L)F2X/45K50
REGISTER 21-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
SRSPE
SRSCKE
SRSC2E
SRSC1E
SRRPE
SRRCKE
SRRC2E
SRRC1E
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
bit 4
bit 3
bit 2
bit 1
bit 0
TABLE 21-2:
Name
SRCON0
SRLEN
SRCON1
SRSPE
Bit 6
Bit 5
Bit 4
SRCLK<2:0>
SRSCKE
SRSC2E SRSC1E
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
SRQEN
SRNQEN
SRPS
SRPR
328
SRRPE
SRRCKE
SRRC2E
SRRC1E
329
TRISA
TRISA7
TRISA6
TRISA5
TRISA4
TRISA3
TRISA2
TRISA1
TRISA0
149
TRISB
TRISB7
TRISB6
TRISB5
TRISB4
TRISB3
TRISB2
TRISB1
TRISB0
149
WPUB
WPUB7
WPUB6
WPUB5
WPUB4
WPUB3
WPUB2
WPUB1
WPUB0
150
DS30000684B-page 329
PIC18(L)F2X/45K50
22.0
22.1
22.2
FIGURE 22-1:
X1
FVRS<1:0>
2
X1
X2
X4
FVREN
FVRST
DS30000684B-page 330
FVR BUF2
(To ADC Module)
+
_
FVR BUF1
(To Comparators, DAC)
1.024V Fixed
Reference
PIC18(L)F2X/45K50
22.3
REGISTER 22-1:
R/W-0
R/W-0
FVREN
FVRST
R/W-0
R/W-1
U-0
U-0
U-0
U-0
FVRS<1:0>
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5-4
bit 3-2
bit 1-0
Unimplemented: Read as 0.
TABLE 22-1:
Name
VREFCON0
Legend:
Bit 6
FVREN
FVRST
Bit 5
Bit 4
FVRS<1:0>
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
331
= unimplemented locations, read as 0. Shaded bits are not used by the FVR module.
DS30000684B-page 331
PIC18(L)F2X/45K50
23.0
DIGITAL-TO-ANALOG
CONVERTER (DAC) MODULE
23.4
23.1
EQUATION 23-1:
DACR<4:0>
VOUT = VSRC+ VSRC- ------------------------------- + VSRC5
23.2
23.3
DS30000684B-page 332
23.5
23.6
PIC18(L)F2X/45K50
FIGURE 23-1:
11
10
FVR BUF1
VREF+
VSRC+
01
00
VDD
DACR<4:0>
5
R
DACPSS<1:0>
DACEN
DACLPS
11111
11110
R
32
Steps
R
32-to-1 MUX
R
R
00001
DACOUT
00000
DACOE
DACNSS
FIGURE 23-2:
VREF-
VSS
DAC Output
(to Comparators and
ADC Modules)
VSRC-
DAC
Module
R
Voltage
Reference
Output
Impedance
DACOUT
DS30000684B-page 333
PIC18(L)F2X/45K50
23.7
23.8
23.9
Effects of a Reset
REGISTER 23-1:
R/W-0
R/W-0
R/W-0
U-0
DACEN
DACLPS
DACOE
R/W-0
R/W-0
U-0
R/W-0
DACNSS
DACPSS<1:0>
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
bit 7
bit 6
bit 5
bit 4
Unimplemented: Read as 0
bit 3-2
bit 1
Unimplemented: Read as 0
bit 0
DS30000684B-page 334
PIC18(L)F2X/45K50
REGISTER 23-2:
U-0
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
DACR<4:0>
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
u = Bit is unchanged
x = Bit is unknown
1 = Bit is set
0 = Bit is cleared
bit 7-5
Unimplemented: Read as 0
bit 4-0
TABLE 23-1:
Name
Bit 6
Bit 5
Bit 4
VREFCON1
DACEN
DACLPS
DACOE
VREFCON2
Legend:
Bit 3
Bit 2
DACPSS<1:0>
Bit 1
Bit 0
DACNSS
DACR<4:0>
Register
on page
334
335
= Unimplemented locations, read as 0. Shaded bits are not used by the DAC module.
DS30000684B-page 335
PIC18(L)F2X/45K50
UNIVERSAL SERIAL BUS
(USB)
host and the PIC microcontroller. The SIE can be interfaced directly to the USB by utilizing the internal transceiver.
24.0
24.1
FIGURE 24-1:
PIC18(L)F2XK50/PIC18(L)F45K50 Family
VUSB3V3(3)
3.3V LDO Regulator
(2)
FSEN
UPUEN
UTRDIS
P
Internal Pull-ups
Transceiver
FS
UOE
USB Bus
D+
D-
1 kbyte
USB RAM
Note 1:
The internal pull-up resistors should be disabled (UPUEN = 0) if external pull-up resistors are used.
2:
3:
See Section 2.4 Voltage Regulator Pins (VUSB3V3) for details on how to connect this pin.
DS30000684B-page 336
PIC18(L)F2X/45K50
24.2
24.2.1
DS30000684B-page 337
PIC18(L)F2X/45K50
REGISTER 24-1:
U-0
R/W-0
R-x
R/C-0
R/W-0
R/W-0
R/W-0
U-0
PPBRST
SE0
PKTDIS
USBEN(1)
RESUME
SUSPND
bit 7
bit 0
Legend:
C = Clearable bit
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
Unimplemented: Read as 0
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
Unimplemented: Read as 0
Note 1:
This bit cannot be set if the USB module does not have an appropriate clock source.
DS30000684B-page 338
PIC18(L)F2X/45K50
The PPBRST bit (UCON<6>) controls the Reset status
when Double-Buffering mode (ping-pong buffering) is
used. When the PPBRST bit is set, all Ping-Pong Buffer Pointers are set to the Even buffers. PPBRST has
to be cleared by firmware. This bit is ignored in buffering modes not using ping-pong buffering.
The PKTDIS bit (UCON<4>) is a flag indicating that the
SIE has disabled packet transmission and reception.
This bit is set by the SIE when a SETUP token is
received to allow setup processing. This bit cannot be
set by the microcontroller, only cleared; clearing it
allows the SIE to continue transmission and/or
reception. Any pending events within the Buffer
Descriptor Table will still be available, indicated within
the USTAT registers FIFO buffer.
The RESUME bit (UCON<2>) allows the peripheral to
perform a remote wake-up by executing Resume
signaling. To generate a valid remote wake-up,
firmware must set RESUME for 10 ms and then clear
the bit. For more information on resume signaling,
see the Universal Serial Bus Specification
Revision 2.0.
The SUSPND bit (UCON<1>) places the module and
supporting circuitry in a Low-Power mode. The input
clock to the SIE is also disabled. This bit should be set
by the software in response to an IDLEIF interrupt. It
should be reset by the microcontroller firmware after an
ACTVIF interrupt is observed. When this bit is active,
the device remains attached to the bus but the transceiver outputs remain Idle. The voltage on the VUSB3V3
pin may vary depending on the value of this bit. Setting
this bit before a IDLEIF request will result in unpredictable bus behavior.
Note:
24.2.2
24.2.2.1
Internal Transceiver
DS30000684B-page 339
PIC18(L)F2X/45K50
REGISTER 24-2:
R/W-0
R/W-0
U-0
UTEYE
UOEMON
R/W-0
R/W-0
UPUEN(1,2) UTRDIS(1,3)
R/W-0
R/W-0
FSEN(1)
R/W-0
PPB<1:0>
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
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1-0
Note 1:
2:
3:
The UPUEN, UTRDIS and FSEN bits should never be changed while the USB module is enabled. These
values must be preconfigured prior to enabling the module.
This bit is only valid when the on-chip transceiver is active (UTRDIS = 0); otherwise, it is ignored.
If UTRDIS is set, the UOE signal will be active, independent of the UOEMON bit setting.
DS30000684B-page 340
PIC18(L)F2X/45K50
24.2.2.2
24.2.2.3
FIGURE 24-2:
EXTERNAL CIRCUITRY
PIC
Microcontroller
24.2.2.4
24.2.2.5
Host
Controller/HUB
VUSB
1.5 k
D+
D-
Note:
DS30000684B-page 341
PIC18(L)F2X/45K50
24.2.3
REGISTER 24-3:
U-0
FIGURE 24-3:
USTAT FIFO
USTAT from SIE
Clearing TRNIF
Advances FIFO
4-Byte FIFO
for USTAT
Data Bus
R-x
R-x
R-x
ENDP<3:0>
R-x
R-x
U-0
DIR
PPBI(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
Unimplemented: Read as 0
bit 6-3
bit 2
bit 1
bit 0
Unimplemented: Read as 0
Note 1:
This bit is only valid for endpoints with available Even and Odd BD registers.
DS30000684B-page 342
PIC18(L)F2X/45K50
24.2.4
REGISTER 24-4:
U-0
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
EPHSHK
EPCONDIS
EPOUTEN
EPINEN
EPSTALL(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-5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1:
DS30000684B-page 343
PIC18(L)F2X/45K50
24.2.5
FIGURE 24-4:
24.2.6
24.3
IMPLEMENTATION OF
USB RAM IN DATA
MEMORY SPACE
000h
User Data
Banks 4 to 7
(USB RAM)
Banks 8
to 14
Buffer Descriptors,
USB Data or User Data
USB Data or
User Data
3FFh
400h
4FFh
500h
7FFh
800h
Unused
USB RAM
Banks 15
SFRs
F52h
F53h
F5Fh
F60h
FFFh
DS30000684B-page 344
PIC18(L)F2X/45K50
24.4
The registers in Bank 4 are used specifically for endpoint buffer control in a structure known as the Buffer
Descriptor Table (BDT). This provides a flexible method
for users to construct and control endpoint buffers of
various lengths and configuration.
The BDT is composed of Buffer Descriptors (BD) which
are used to define and control the actual buffers in the
USB RAM space. Each BD, in turn, consists of four
registers, where n represents one of the 64 possible
BDs (range of 0 to 63):
24.4.1
Buffer descriptors not only define the size of an endpoint buffer, but also determine its configuration and
control. Most of the configuration is done with the BD
Status register, BDnSTAT. Each BD has its own unique
and correspondingly numbered BDnSTAT register.
FIGURE 24-5:
Buffer
Descriptor
EXAMPLE OF A BUFFER
DESCRIPTOR
Address
Registers
400h
BD0STAT
(xxh)
Contents
401h
BD0CNT
40h
402h
BD0ADRL
00h
403h
BD0ADRH
05h
Size of Block
Starting
Address
500h
USB Data
Buffer
53Fh
Note:
24.4.1.1
Buffer Ownership
DS30000684B-page 345
PIC18(L)F2X/45K50
When UOWN is set, the user can no longer depend on
the values that were written to the BDs. From this point,
the SIE updates the BDs as necessary, overwriting the
original BD values. The BDnSTAT register is updated
by the SIE with the token PID and the transfer count,
BDnCNT, is updated.
Note:
24.4.1.2
TABLE 24-1:
OUT Packet
from Host
BDnSTAT Settings
DTSEN
DTS
Handshake
UOWN
TRNIF
ACK
Updated
DATA0
DATA1
ACK
Not Updated
DATA0
ACK
Not Updated
DATA1
ACK
Updated
Either
ACK
Updated
NAK
Not Updated
DS30000684B-page 346
PIC18(L)F2X/45K50
REGISTER 24-5:
R/W-x
UOWN(1)
U-0
U-0
(2)
(3)
(3)
DTS
R/W-x
R/W-x
R/W-x
R/W-x
DTSEN
BSTALL
BC9
BC8
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-0
Note 1:
2:
3:
This bit must be initialized by the user to the desired value prior to enabling the USB module.
This bit is ignored unless DTSEN = 1.
If these bits are set, USB communication may not work. Hence, these bits should always be maintained as
0.
DS30000684B-page 347
PIC18(L)F2X/45K50
24.4.1.3
When the BD and its buffer are owned by the SIE, most
of the bits in BDnSTAT take on a different meaning. The
configuration is shown in Register 24-6. Once the
UOWN bit is set, any data or control settings previously
written there by the user will be overwritten with data
from the SIE.
The BDnSTAT register is updated by the SIE with the
token Packet Identifier (PID) which is stored in
BDnSTAT<5:3>. The transfer count in the corresponding BDnCNT register is updated. Values that overflow
the 8-bit register carry over to the two Most Significant
digits of the count, stored in BDnSTAT<1:0>.
24.4.2
BD BYTE COUNT
24.4.3
BD ADDRESS VALIDATION
REGISTER 24-6:
R/W-x
U-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
UOWN
PID3
PID2
PID1
PID0
BC9
BC8
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-2
bit 1-0
DS30000684B-page 348
PIC18(L)F2X/45K50
24.4.4
PING-PONG BUFFERING
No ping-pong support
Ping-pong buffer support for OUT Endpoint 0 only
Ping-pong buffer support for all endpoints
Ping-pong buffer support for all other Endpoints
except Endpoint 0
FIGURE 24-6:
PPB<1:0> = 01
Ping-Pong Buffer
on EP0 OUT
PPB<1:0> = 00
No Ping-Pong
Buffers
400h
400h
EP0 OUT
Descriptor
400h
EP0 OUT Even
Descriptor
EP0 IN
Descriptor
EP0 IN
Descriptor
EP0 IN Even
Descriptor
EP0 IN Odd
Descriptor
EP1 IN Even
Descriptor
EP1 IN Odd
Descriptor
EP1 OUT
Descriptor
EP0 IN
Descriptor
EP1 IN
Descriptor
EP1 OUT
Descriptor
EP1 IN
Descriptor
EP15 IN
Descriptor
47Fh
Available
as
Data RAM
Note:
EP0 OUT
Descriptor
EP1 IN Odd
Descriptor
Available
as
Data RAM
4FFh
Maximum Memory
Used: 128 Bytes
Maximum BDs:
32 (BD0 to BD31)
400h
EP1 IN Even
Descriptor
EP15 IN
Descriptor
483h
4FFh
PPB<1:0> = 11
Ping-Pong Buffers
on all Other EPs
Except EP0
Maximum Memory
Used: 132 Bytes
Maximum BDs:
33 (BD0 to BD32)
EP15 IN Odd
Descriptor
4F7h
EP15 IN Odd
Descriptor
4FFh
Maximum Memory
Used: 256 Bytes
Maximum BDs:
64 (BD0 to BD63)
Available
as
Data RAM
4FFh
Maximum Memory
Used: 248 Bytes
Maximum BDs:
62 (BD0 to BD61)
DS30000684B-page 349
PIC18(L)F2X/45K50
TABLE 24-2:
Mode 0
(No Ping-Pong)
Endpoint
Mode 1
(Ping-Pong on EP0 OUT)
Mode 2
(Ping-Pong on all EPs)
Mode 3
(Ping-Pong on all other EPs,
except EP0)
Out
In
Out
In
Out
In
Out
In
0 (E), 1 (O)
0 (E), 1 (O)
2 (E), 3 (O)
4 (E), 5 (O)
6 (E), 7 (O)
2 (E), 3 (O)
4 (E), 5 (O)
8 (E), 9 (O)
10 (E), 11 (O)
6 (E), 7 (O)
8 (E), 9 (O)
12 (E), 13 (O)
14 (E), 15 (O)
10
16 (E), 17 (O)
18 (E), 19 (O)
10
11
11
12
20 (E), 21 (O)
22 (E), 23 (O)
12
13
13
14
24 (E), 25 (O)
26 (E), 27 (O)
14
15
15
16
28 (E), 29 (O)
16
17
17
18
32 (E), 33 (O)
34 (E), 35 (O)
18
19
19
20
36 (E), 37 (O)
38 (E), 39 (O)
10
20
21
21
22
40 (E), 41 (O)
42 (E), 43 (O)
11
22
23
23
24
44 (E), 45 (O)
46 (E), 47 (O)
12
24
25
25
26
48 (E), 49 (O)
50 (E), 51 (O)
13
26
27
27
28
52 (E), 53 (O)
54 (E), 55 (O)
14
28
29
29
30
56 (E), 57 (O)
58 (E), 59 (O)
15
30
31
31
32
60 (E), 61 (O)
62 (E), 63 (O)
TABLE 24-3:
Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
BDnSTAT(1)
UOWN
DTS(4)
PID3(2)
PID2(2)
PID1(2)
DTSEN(3)
PID0(2)
BSTALL(3)
BC9
BC8
BDnCNT(1)
Byte Count
BDnADRL(1)
BDnADRH(1)
Note 1:
2:
3:
4:
For buffer descriptor registers, n may have a value of 0 to 63. For the sake of brevity, all 64 registers are
shown as one generic prototype. All registers have indeterminate Reset values (xxxx xxxx).
Bits 5 through 2 of the BDnSTAT register are used by the SIE to return PID<3:0> values once the register
is turned over to the SIE (UOWN bit is set). Once the registers have been under SIE control, the values
written for DTSEN and BSTALL are no longer valid.
Prior to turning the buffer descriptor over to the SIE (UOWN bit is cleared), bits 5 through 2 of the
BDnSTAT register are used to configure the DTSEN and BSTALL settings.
This bit is ignored unless DTSEN = 1.
DS30000684B-page 350
PIC18(L)F2X/45K50
24.5
USB Interrupts
The USB module can generate multiple interrupt conditions. To accommodate all of these interrupt sources,
the module is provided with its own interrupt logic
structure, similar to that of the microcontroller. USB
interrupts are enabled with one set of control registers
and trapped with a separate set of flag registers. All
sources are funneled into a single USB interrupt
request, USBIF (PIR3<2>), in the microcontrollers
interrupt logic.
FIGURE 24-7:
BTSEF
BTSEE
TRNIF
TRNIE
BTOEF
BTOEE
USBIF
IDLEIF
IDLEIE
DFN8EF
DFN8EE
UERRIF
UERRIE
CRC16EF
CRC16EE
STALLIF
STALLIE
CRC5EF
CRC5EE
PIDEF
PIDEE
ACTVIF
ACTVIE
URSTIF
URSTIE
FIGURE 24-8:
From Host
To Host
SETUP Token
Data
ACK
To Host
From Host
Data
ACK
From Host
To Host
Empty Data
ACK
From Host
IN Token
USB Reset
URSTIF
From Host
Start-of-Frame (SOF)
SOFIF
OUT Token
Set TRNIF
Set TRNIF
Set TRNIF
Transaction
Transaction
Complete
RESET
SOF
SETUP
DATA
SOF
STATUS
Differential Data
Control Transfer(1)
1 ms Frame
Note
1:
The control transfer shown here is only an example showing events that can occur for every transaction. Typical control transfers
will spread across multiple frames.
DS30000684B-page 351
PIC18(L)F2X/45K50
24.5.1
REGISTER 24-7:
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R-0
R/W-0
SOFIF
STALLIF
IDLEIF(1)
TRNIF(2)
ACTVIF(3)
UERRIF(4)
URSTIF
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
Unimplemented: Read as 0
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1:
2:
3:
4:
Once an Idle state is detected, the user may want to place the USB module in Suspend mode.
Clearing this bit will cause the USTAT FIFO to advance (valid only for IN, OUT and SETUP tokens).
This bit is typically unmasked only following the detection of a UIDLE interrupt event.
Only error conditions enabled through the UEIE register will set this bit. This bit is a status bit only and
cannot be set or cleared by the user.
DS30000684B-page 352
PIC18(L)F2X/45K50
24.5.1.1
EXAMPLE 24-1:
Assembly:
BCF
LOOP:
BTFSS
BRA
BCF
BRA
DONE:
UCON, SUSPND
UIR, ACTVIF
DONE
UIR, ACTVIF
LOOP
C:
UCONbits.SUSPND = 0;
while (UIRbits.ACTVIF) { UIRbits.ACTVIF = 0; }
DS30000684B-page 353
PIC18(L)F2X/45K50
24.5.2
REGISTER 24-8:
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
SOFIE
STALLIE
IDLEIE
TRNIE
ACTVIE
UERRIE
URSTIE
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
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
DS30000684B-page 354
x = Bit is unknown
PIC18(L)F2X/45K50
24.5.3
REGISTER 24-9:
R/C-0
U-0
U-0
R/C-0
R/C-0
R/C-0
R/C-0
R/C-0
BTSEF
BTOEF
DFN8EF
CRC16EF
CRC5EF
PIDEF
bit 7
bit 0
Legend:
R = Readable bit
C = Clearable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
bit 6-5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
DS30000684B-page 355
PIC18(L)F2X/45K50
24.5.4
As with the UIE register, the enable bits only affect the
propagation of an interrupt condition to the microcontrollers interrupt logic. The flag bits are still set by
their interrupt conditions, allowing them to be polled
and serviced without actually generating an interrupt.
The
USB
Error
Interrupt
Enable
register
(Register 24-10) contains the enable bits for each of
the USB error interrupt sources. Setting any of these
bits will enable the respective error interrupt source in
the UEIR register to propagate into the UERR bit at
the top level of the interrupt logic.
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
BTSEE
BTOEE
DFN8EE
CRC16EE
CRC5EE
PIDEE
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-5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
DS30000684B-page 356
x = Bit is unknown
PIC18(L)F2X/45K50
24.6
24.6.2
24.6.1
SELF-POWER ONLY
FIGURE 24-10:
VSELF
SELF-POWER ONLY
VDD
VUSB
VSS
FIGURE 24-9:
VBUS
VDD
VUSB
VSS
DS30000684B-page 357
PIC18(L)F2X/45K50
24.6.3
24.6.4
FIGURE 24-11:
VBUS
~5V
VDD
100 k
VSELF
~5V
Note:
VUSB
VSS
DS30000684B-page 358
PIC18(L)F2X/45K50
EQUATION 24-1:
Legend:
VUSB:
PZERO:
Percentage (in decimal) of the IN traffic bits sent by the PIC device that are a value of 0.
PIN:
Percentage (in decimal) of total bus bandwidth that is used for IN traffic.
LCABLE:
Length (in meters) of the USB cable. The USB 2.0 specification requires that full-speed applications
use cables no longer than 5m.
IPULLUP:
Current which the nominal, 1.5 k pull-up resistor (when enabled) must supply to the USB cable. On
the host or hub end of the USB cable, 15 k nominal resistors (14.25 k to 24.8 k) are present which
pull both the D+ and D- lines to ground. During bus Idle conditions (such as between packets or during
USB Suspend mode), this results in up to 218 A of quiescent current drawn at 3.3V.
IPULLUP is also dependant on bus traffic conditions and can be as high as 2.2 mA when the USB bandwidth
is fully utilized (either IN or OUT traffic) for data that drives the lines to the K state most of the time.
EXAMPLE 24-2:
For this example, the following assumptions are made about the application:
3.3V will be applied to VUSB3V3 and VDD, with the core voltage regulator enabled.
This is a full-speed application that uses one interrupt IN endpoint that can send one packet of 64 bytes every
1 ms, with no restrictions on the values of the bytes being sent. The application may or may not have additional traffic on OUT endpoints.
A regular USB B or mini-B connector will be used on the application circuit board.
In this case, PZERO = 100% = 1, because there should be no restriction on the value of the data moving through
the IN endpoint. All 64 kBps of data could potentially be bytes of value, 00h. Since 0 bits cause toggling of the
output state of the transceiver, they cause the USB transceiver to consume extra current charging/discharging the
cable. In this case, 100% of the data bits sent can be of value 0. This should be considered the max value, as
normal data will consist of a fair mix of ones and zeros.
This application uses 64 kBps for IN traffic out of the total bus bandwidth of 1.5 MBps (12 Mbps), therefore:
64 kBps
Pin =
= 4.3% = 0.043
1.5 MBps
Since a regular B or mini-B connector is used in this application, the end user may plug in any type of cable up
to the maximum allowed 5 m length. Therefore, we use the worst-case length:
LCABLE = 5 meters
Assume IPULLUP = 2.2 mA. The actual value of IPULLUP will likely be closer to 218 A, but allow for the worst-case.
USB bandwidth is shared between all the devices which are plugged into the root port (via hubs). If the application
is plugged into a USB 1.1 hub that has other devices plugged into it, your device may see host to device traffic on
the bus, even if it is not addressed to your device. Since any traffic, regardless of source, can increase the IPULLUP
current above the base 218 A, it is safest to allow for the worst-case of 2.2 mA.
Therefore:
IXCVR =
The calculated value should be considered an approximation and additional guardband or application-specific product testing is recommended. The transceiver current is in addition to the rest of the current consumed by the
PIC18F2X/45K50 device that is needed to run the core, drive the other I/O lines, power the various modules, etc.
DS30000684B-page 359
PIC18(L)F2X/45K50
24.7
Oscillator
24.8
24.9
DS30000684B-page 360
PIC18(L)F2X/45K50
TABLE 24-4:
Name
INTCON
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
114
IPR3
CTMUIP
USBIP
TMR3GIP
TMR1GIP
125
PIR3
CTMUIF
USBIF
TMR3GIF
TMR1GIF
119
PIE3
CTMUIE
USBIE
TMR3GIE
TMR1GIE
122
UCON
PPBRST
SE0
PKTDIS
USBEN
RESUME
SUSPND
338
UCFG
UTEYE
UOEMON
UPUEN
UTRDIS
FSEN
USTAT
UADDR
ENDP<3:0>
DIR
PPB<1:0>1
PPBI
ADDR<6:0>
UFRML
344
FRM<7:0>
UFRMH
UIR
SOFIF
STALLIF
IDLEIF
TRNIF
340
342
337
FRM<10:8>
ACTVIF
337
UERRIF
URSTIF
352
SOFIE
STALLIE
IDLEIE
TRNIE
ACTVIE
UERRIE
URSTIE
354
UEIR
BTSEF
BTOEF
DFN8EF
CRC16EF
CRC5EF
PIDEF
355
UEIE
BTSEE
BTOEE
DFN8EE
CRC16EE
CRC5EE
PIDEE
356
UEP0
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UEP1
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UEP2
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UEP3
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UEP4
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UEP5
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UEP6
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UEP7
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UEP8
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UEP9
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UEP10
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UEP11
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UEP12
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UEP13
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UEP14
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
EPHSHK
EPCONDIS EPOUTEN
EPINEN
EPSTALL
343
UIE
UEP15
Legend:
Note 1:
= unimplemented, read as 0. Shaded cells are not used by the USB module.
This table includes only those hardware mapped SFRs located in Bank 15 of the data memory space. The Buffer
Descriptor registers, which are mapped into Bank 4 and are not true SFRs, are listed separately in Table 24-3.
DS30000684B-page 361
PIC18(L)F2X/45K50
24.10 Overview of USB
24.10.3
24.10.1
LAYERED FRAMEWORK
24.10.2
TRANSFERS
24.10.4
POWER
FRAMES
FIGURE 24-12:
USB LAYERS
Device
Configuration
To other Interfaces (if any)
Interface
Interface
Endpoint
DS30000684B-page 362
Endpoint
Endpoint
Endpoint
Endpoint
PIC18(L)F2X/45K50
The USB specification limits the power taken from the
bus. Each device is ensured 100 mA at approximately
5V (one unit load). Additional power may be requested,
up to a maximum of 500 mA. Note that power above
one unit load is a request and the host or hub is not
obligated to provide the extra current. Thus, a device
capable of consuming more than one unit load must be
able to maintain a low-power configuration of a one unit
load or less, if necessary.
The USB specification also defines a Suspend mode.
In this situation, current must be limited to 500 A,
averaged over 1 second. A device must enter a
Suspend state after 3 ms of inactivity (i.e., no SOF
tokens for 3 ms). A device entering Suspend mode
must drop current consumption within 10 ms after
Suspend. Likewise, when signaling a wake-up, the
device must signal a wake-up within 10 ms of drawing
current above the Suspend limit.
24.10.5
ENUMERATION
2.
3.
4.
5.
6.
7.
8.
24.10.6
DESCRIPTORS
24.10.6.1
Device Descriptor
24.10.6.2
Configuration Descriptor
24.10.6.3
Interface Descriptor
The interface descriptor details the number of endpoints used in this interface, as well as the class of the
interface. There may be more than one interface for a
configuration.
24.10.6.4
Endpoint Descriptor
24.10.6.5
String Descriptor
24.10.7
BUS SPEED
24.10.8
DS30000684B-page 363
PIC18(L)F2X/45K50
25.0
HIGH/LOW-VOLTAGE DETECT
(HLVD)
The PIC18(L)F2X/45K50 devices have a High/LowVoltage Detect module (HLVD). This is a programmable
circuit that sets both a device voltage trip point and the
direction of change from that point. If the device
experiences an excursion past the trip point in that
direction, an interrupt flag is set. If the interrupt is
enabled, the program execution branches to the
interrupt vector address and the software responds to
the interrupt.
25.1
REGISTER 25-1:
R/W-0
R-0
R-0
R/W-0
VDIRMAG
BGVST
IRVST
HLVDEN
R/W-0
R/W-1
R/W-0
R/W-1
HLVDL<3:0>
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:
DS30000684B-page 364
PIC18(L)F2X/45K50
The module is enabled by setting the HLVDEN bit
(HLVDCON<4>). Each time the HLVD module is
enabled, the circuitry requires some time to stabilize.
The IRVST bit (HLVDCON<5>) is a read-only bit used
to indicate when the circuit is stable. The module can
only generate an interrupt after the circuit is stable and
IRVST is set.
25.2
Operation
FIGURE 25-1:
VDD
Externally Generated
Trip Point
VDD
HLVDL<3:0>
HLVDCON
Register
HLVDEN
VDIRMAG
Set
HLVDIF
16-to-1 MUX
HLVDIN
HLVDEN
BOREN
Internal Voltage
Reference
1.024V Typical
DS30000684B-page 365
PIC18(L)F2X/45K50
25.3
HLVD Setup
25.4
Current Consumption
25.5
DS30000684B-page 366
PIC18(L)F2X/45K50
FIGURE 25-2:
CASE 1:
Enable HLVD
TIRVST
IRVST
VDD
VHLVD
HLVDIF
Enable HLVD
TIRVST
IRVST
Internal Reference is stable
DS30000684B-page 367
PIC18(L)F2X/45K50
FIGURE 25-3:
CASE 1:
Enable HLVD
TIRVST
IRVST
IRVST
Internal Reference is stable
Applications
DS30000684B-page 368
FIGURE 25-4:
TYPICAL LOW-VOLTAGE
DETECT APPLICATION
VA
VB
Voltage
25.6
Time
TA
TB
PIC18(L)F2X/45K50
25.7
25.8
TABLE 25-1:
Effects of a Reset
Name
Bit 7
Bit 6
HLVDCON
VDIRMAG
BGVST
INTCON
GIE/GIEH PEIE/GIEL
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
HLVDL<3:0>
Register
on page
IRVST
HLVDEN
TMR0IE
INT0IE
IOCIE
TMR0IF
INT0IF
IOCIF
364
114
IPR2
OSCFIP
C1IP
C2IP
EEIP
BCLIP
HLVDIP
TMR3IP
CCP2IP
124
PIE2
OSCFIE
C1IE
C2IE
EEIE
BCLIE
HLVDIE
TMR3IE
CCP2IE
121
PIR2
OSCFIF
C1IF
C2IF
EEIF
BCLIF
HLVDIF
TMR3IF
CCP2IF
118
TRISA
TRISA7
TRISA6
TRISA5
TRISA4
TRISA3
TRISA2
TRISA1
TRISA0
149
Legend: = Unimplemented locations, read as 0. Shaded bits are unused by the HLVD module.
DS30000684B-page 369
PIC18(L)F2X/45K50
26.0
SPECIAL FEATURES OF
THE CPU
26.1
Configuration Bits
DS30000684B-page 370
PIC18(L)F2X/45K50
TABLE 26-1:
Address
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
300000h
CONFIG1L
LS48MHZ
CPUDIV<1:0>
300001h
CONFIG1H
IESO
FCMEN
PCLKEN
300002h
CONFIG2L
LPBOR
300003h
CONFIG2H
300004h
CONFIG3L
300005h
CONFIG3H
MCLRE
300006h
CONFIG4L
DEBUG
300007h
CONFIG4H
Bit 2
Bit 1
Bit 0
Default/
Unprogrammed
Value
CFGPLLEN
PLLSEL
0000 0000
FOSC<3:0>
BORV<1:0>
BOREN<1:0>
WDTPS<3:0>
0010 0101
PWRTEN
0101 1111
WDTEN<1:0>
0011 1111
0000 0000
SDOMX
T3CMX
PBADEN
CCP2MX
1101 0011
XINST
ICPRT(5)
LVP(1)
STRVEN
1010 0101
1111 1111
CP2(2)
300008h
CONFIG5L
CP3(2)
CP1
CP0
0000 1111
300009h
CONFIG5H
CPD
CPB
1100 0000
30000Ah
CONFIG6L
WRT3(2)
WRT2(2)
WRT1
WRT0
0000 1111
30000Bh
CONFIG6H
WRTD
WRTB
WRTC(3)
1110 0000
30000Ch
CONFIG7L
EBTR3(2)
EBTR2(2)
EBTR1
EBTR0
0000 1111
30000Dh
CONFIG7H
EBTRB
3FFFFEh
DEVID1(4)
3FFFFFh
DEVID2(4)
Legend:
Note 1:
2:
3:
4:
5:
DEV<2:0>
REV<4:0>
DEV<10:3>
0100 0000
qqqq qqqq
0101 1100
DS30000684B-page 371
PIC18(L)F2X/45K50
26.2
REGISTER 26-1:
U-0
U-0
R/P-0
LS48MHZ
R/P-0
R/P-0
CPUDIV<1:0>
U-0
R/P-0
R/P-0
CFGPLLEN
PLLSEL
bit 7
bit 0
Legend:
R = Readable bit
P = Programmable bit
bit 7-6
Unimplemented: Read as 0
bit 5
bit 4-3
bit 2
Unimplemented: Read as 0
bit 1
bit 0
Note 1:
See Table 3-1 for conditions under which the CFGPLLEN fuse is available.
DS30000684B-page 372
PIC18(L)F2X/45K50
REGISTER 26-2:
R/P-0
R/P-0
R/P-1
U-0
IESO
FCMEN
PCLKEN
R/P-0
R/P-1
R/P-0
R/P-1
FOSC<3:0>
bit 7
bit 0
Legend:
R = Readable bit
P = Programmable bit
bit 7
bit 6
bit 5
bit 4
Unimplemented: Read as 0
bit 3-0
Note 1:
When FOSC<3:0> is configured for HS, XT, or LP oscillator and FCMEN bit is set, then the IESO bit
should also be set to prevent a false failed clock indication and to enable automatic clock switch over from
the internal oscillator block to the external oscillator when the OST times out.
DS30000684B-page 373
PIC18(L)F2X/45K50
REGISTER 26-3:
U-0
R/P-1
U-0
LPBOR
R/P-1
R/P-1
BORV<1:0>(1)
R/P-1
R/P-1
BOREN<1:0>(2)
R/P-1
PWRTEN(2)
bit 7
bit 0
Legend:
R = Readable bit
P = Programmable bit
bit 7
Unimplemented: Read as 0
bit 6
bit 5
Unimplemented: Read as 0
bit 4-3
bit 2-1
bit 0
Note
1:
2:
DS30000684B-page 374
PIC18(L)F2X/45K50
REGISTER 26-4:
U-0
U-0
R/P-1
R/P-1
R/P-1
R/P-1
WDTPS<3:0>
R/P-1
R/P-1
WDTEN<1:0>
bit 7
bit 0
Legend:
R = Readable bit
P = Programmable bit
bit 7-6
Unimplemented: Read as 0
bit 5-2
bit 1-0
DS30000684B-page 375
PIC18(L)F2X/45K50
REGISTER 26-5:
R/P-1
R/P-1
U-0
R/P-1
U-0
U-0
R/P-1
R/P-1
MCLRE
SDOMX
T3CMX
PBADEN
CCP2MX
bit 7
bit 0
Legend:
R = Readable bit
P = Programmable bit
bit 7
bit 6
bit 5
Unimplemented: Read as 0
bit 4
bit 3-2
Unimplemented: Read as 0
bit 1
bit 0
DS30000684B-page 376
PIC18(L)F2X/45K50
REGISTER 26-6:
R/P-1
DEBUG
(2)
XINST
R/P-1
ICPRT
U-0
(3)
U-0
R/P-1
LVP
(1)
U-0
R/P-1
STVREN
bit 7
bit 0
Legend:
R = Readable bit
P = Programmable bit
bit 7
bit 6
bit 5
bit 4-3
Unimplemented: Read as 0
bit 2
bit 1
Unimplemented: Read as 0
bit 0
Note 1:
2:
3:
DS30000684B-page 377
PIC18(L)F2X/45K50
REGISTER 26-7:
U-0
U-0
U-0
U-0
R/C-1
R/C-1
R/C-1
R/C-1
CP3(1)
CP2(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 26-8:
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
DS30000684B-page 378
PIC18(L)F2X/45K50
REGISTER 26-9:
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:
DS30000684B-page 379
PIC18(L)F2X/45K50
REGISTER 26-10: CONFIG6H: CONFIGURATION REGISTER 6 HIGH
R/C-1
R/C-1
WRTD
WRTB
R/C-1
(1)
WRTC
U-0
U-0
U-0
U-0
U-0
bit 7
bit 0
Legend:
R = Readable bit
bit 7
bit 6
bit 5
bit 4-0
Note 1:
Unimplemented: Read as 0
This bit is read-only in normal execution mode; it can be written only in ICSP mode.
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:
DS30000684B-page 380
PIC18(L)F2X/45K50
REGISTER 26-12: CONFIG7H: CONFIGURATION REGISTER 7 HIGH
U-0
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
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
DS30000684B-page 381
PIC18(L)F2X/45K50
TABLE 26-2:
DEV<10:3>
0101 1100
DS30000684B-page 382
DEV<2:0>
Part Number
000
PIC18F45K50
001
PIC18F25K50
011
PIC18F24K50
100
PIC18LF45K50
101
PIC18LF25K50
111
PIC18LF24K50
PIC18(L)F2X/45K50
26.3
FIGURE 26-1:
SWDTEN
WDTEN
INTRC Source
Wake-up
from Power
Managed Modes
128
CLRWDT
Reset
WDT
Reset
Sleep
DS30000684B-page 383
PIC18(L)F2X/45K50
26.3.1
CONTROL REGISTER
26.4
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
Note 1:
x = Bit is unknown
This bit has no effect unless the Configuration bit, WDTEN<1:0>, is set to 10b (SWDTEN enabled).
TABLE 26-3:
Name
RCON
WDTCON
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Register
on page
IPEN
SBOREN
RI
TO
PD
POR
BOR
64
SWDTEN
384
Legend: = unimplemented, read as 0. Shaded bits are not used by the Watchdog Timer.
TABLE 26-4:
Name
Bit 7
Bit 6
CONFIG2H
Bit 5
Bit 4
Bit 3
WDTPS<3:0>
Bit 2
Bit 1
Bit 0
WDTEN<1:0>
Register
on page
375
Legend: = unimplemented, read as 0. Shaded bits are not used by the Watchdog Timer.
DS30000684B-page 384
PIC18(L)F2X/45K50
26.5
FIGURE 26-2:
Boot Block
(000h-7FFh)
Boot Block
(000h-7FFh)
Block 0
(800h-1FFFh)
Block 0
(800h-1FFFh)
Block 1
(2000h-3FFFh)
Block 1
(2000h-3FFFh)
Block 2
(4000h-5FFFh)
Block 3
(6000h-7FFFh)
Unimplemented
Read 0s
(4000h-1FFFFFh)
Unimplemented
Read 0s
(8000h-1FFFFFh)
TABLE 26-5:
(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(2)
30000Ch
CONFIG7L
EBTR3(1)
EBTR2(1)
EBTR1
EBTR0
30000Dh
CONFIG7H
EBTRB
DS30000684B-page 385
PIC18(L)F2X/45K50
26.5.1
PROGRAM MEMORY
CODE PROTECTION
FIGURE 26-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.
DS30000684B-page 386
PIC18(L)F2X/45K50
FIGURE 26-4:
Register Values
Program Memory
TBLPTR = 0008FFh
WRTB, EBTRB = 11
WRT0, EBTR0 = 10
001FFFh
002000h
PC = 003FFEh
WRT1, EBTR1 = 11
TBLRD*
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 26-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
DS30000684B-page 387
PIC18(L)F2X/45K50
26.5.2
DATA EEPROM
CODE PROTECTION
26.5.3
CONFIGURATION REGISTER
PROTECTION
26.6
ID Locations
26.7
26.8
In-Circuit Debugger
TABLE 26-6:
DEBUGGER RESOURCES
I/O pins:
DS30000684B-page 388
RB6, RB7
MCLR/VPP/RE3
VDD
VSS
RB7
RB6
26.9
26.9.1
PIC18(L)F2X/45K50
TABLE 26-7:
Pin Name
Legacy
Port
Dedicated
Port
MCLR/VPP/
RE3
Pin Function
RB6/IOCB6/ NC/ICCK/
PGC
ICPGC
Serial Clock
RB7/IOCB7/ NC/ICDT/
PGD
ICPGD
I/O
Serial Data
Legend:
NC/ICRST/
ICVPP
Pin
Type
DS30000684B-page 389
PIC18(L)F2X/45K50
27.0
27.1
Byte-oriented operations
Bit-oriented operations
Literal operations
Control operations
DS30000684B-page 390
PIC18(L)F2X/45K50
TABLE 27-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
DS30000684B-page 391
PIC18(L)F2X/45K50
FIGURE 27-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
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
n<7:0> (literal)
12 11
CALL MYFUNC
0
n<19:8> (literal)
1111
S = Fast bit
15
OPCODE
15
OPCODE
DS30000684B-page 392
11 10
n<10:0> (literal)
8 7
n<7:0> (literal)
BRA MYFUNC
0
BC MYFUNC
PIC18(L)F2X/45K50
TABLE 27-2:
Mnemonic,
Operands
Cycles
MSb
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:
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
0010
0001
0110
0001
0110
0110
0110
0000
0010
0100
0010
0011
0100
0001
0101
1100
1111
0110
0000
0110
0011
0100
0011
0100
0110
0101
01da
00da
01da
101a
11da
001a
010a
000a
01da
11da
11da
10da
11da
10da
00da
00da
ffff
ffff
111a
001a
110a
01da
01da
00da
00da
100a
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
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
DS30000684B-page 393
PIC18(L)F2X/45K50
TABLE 27-2:
Mnemonic,
Operands
Description
Cycles
MSb
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, b, 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
k, 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:
DS30000684B-page 394
1
1
2
TO, PD
C
None
None
None
None
None
None
All
GIE/GIEH,
PEIE/GIEL
kkkk None
001s None
0011 TO, PD
PIC18(L)F2X/45K50
TABLE 27-2:
Mnemonic,
Operands
Description
Cycles
MSb
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.
DS30000684B-page 395
PIC18(L)F2X/45K50
27.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
ffff
ffff
Words:
Cycles:
15h
Before Instruction
W
= 10h
After Instruction
01da
Description:
Q Cycle Activity:
Decode
f {,d {,a}}
25h
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).
DS30000684B-page 396
PIC18(L)F2X/45K50
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 27.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
=
REG, 0, 1
1
02h
4Dh
0
02h
50h
DS30000684B-page 397
PIC18(L)F2X/45K50
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:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
Example:
ANDWF
Before Instruction
W
=
REG
=
After Instruction
W
REG
=
=
DS30000684B-page 398
17h
C2h
02h
C2h
REG, 0, 0
1110
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
If No Jump:
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
BC
address (HERE)
=
=
=
=
1;
address (HERE + 12)
0;
address (HERE + 2)
PIC18(L)F2X/45K50
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:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write
register f
Example:
BCF
Before Instruction
FLAG_REG =
After Instruction
FLAG_REG =
FLAG_REG,
7, 0
1110
Description:
0110
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
If No Jump:
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
BN
Jump
address (HERE)
=
=
=
=
1;
address (Jump)
0;
address (HERE + 2)
DS30000684B-page 399
PIC18(L)F2X/45K50
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
DS30000684B-page 400
BNC
Jump
address (HERE)
=
=
=
=
0;
address (Jump)
1;
address (HERE + 2)
Example:
HERE
Before Instruction
PC
After Instruction
If NEGATIVE
PC
If NEGATIVE
PC
BNN
Jump
address (HERE)
=
=
=
=
0;
address (Jump)
1;
address (HERE + 2)
PIC18(L)F2X/45K50
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:
Example:
If No Jump:
HERE
Before Instruction
PC
=
After Instruction
If OVERFLOW =
PC
=
If OVERFLOW =
PC
=
BNOV Jump
address (HERE)
0;
address (Jump)
1;
address (HERE + 2)
Example:
HERE
Before Instruction
PC
After Instruction
If ZERO
PC
If ZERO
PC
BNZ
Jump
address (HERE)
=
=
=
=
0;
address (Jump)
1;
address (HERE + 2)
DS30000684B-page 401
PIC18(L)F2X/45K50
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:
bbba
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Decode
f, b {,a}
Q Cycle Activity:
HERE
Before Instruction
PC
After Instruction
PC
BRA
Jump
address (HERE)
address (Jump)
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write
register f
Example:
BSF
Before Instruction
FLAG_REG
After Instruction
FLAG_REG
DS30000684B-page 402
FLAG_REG, 7, 1
0Ah
8Ah
PIC18(L)F2X/45K50
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: Three 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
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
BTFSS
:
:
FLAG, 1, 0
address (HERE)
=
=
=
=
0;
address (FALSE)
1;
address (TRUE)
DS30000684B-page 403
PIC18(L)F2X/45K50
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,
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
No
operation
4, 0
Before Instruction:
PORTC =
0111 0101 [75h]
After Instruction:
PORTC =
0110 0101 [65h]
DS30000684B-page 404
If No Jump:
Example:
HERE
Before Instruction
PC
=
After Instruction
If OVERFLOW =
PC
=
If OVERFLOW =
PC
=
BOV
Jump
address (HERE)
1;
address (Jump)
0;
address (HERE + 2)
PIC18(L)F2X/45K50
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
BZ
address (HERE)
=
=
=
=
1;
address (Jump)
0;
address (HERE + 2)
kkkk0
kkkk8
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
Jump
k7kkk
kkkk
110s
k19kkk
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 =
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
DS30000684B-page 405
PIC18(L)F2X/45K50
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:
Syntax:
CLRWDT
Operands:
None
Operation:
000h WDT,
000h WDT postscaler,
1 TO,
1 PD
Status Affected:
TO, PD
Encoding:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write
register f
CLRF
Before Instruction
FLAG_REG
After Instruction
FLAG_REG
DS30000684B-page 406
FLAG_REG, 1
5Ah
00h
0000
0000
0000
0100
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
No
operation
Process
Data
No
operation
Example:
Q Cycle Activity:
Example:
CLRWDT
CLRWDT
Before Instruction
WDT Counter
After Instruction
WDT Counter
WDT Postscaler
TO
PD
=
=
=
=
00h
0
1
1
PIC18(L)F2X/45K50
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: Three cycles if skip and
followed by a 2-word instruction.
Q Cycle Activity:
Example:
COMF
Before Instruction
REG
=
After Instruction
REG
=
W
=
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
No
operation
REG, 0, 0
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:
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)
DS30000684B-page 407
PIC18(L)F2X/45K50
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: Three 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
CPFSGT REG, 0
:
:
Before Instruction
PC
W
After Instruction
=
=
Address (HERE)
?
If REG
PC
If REG
PC
W;
Address (GREATER)
W;
Address (NGREATER)
DS30000684B-page 408
ffff
ffff
Words:
Cycles:
1(2)
Note: Three cycles if skip and
followed by a 2-word instruction.
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:
If skip:
Q4
No
operation
No
operation
000a
Q Cycle Activity:
Q1
Decode
0110
Description:
Cycles:
f {,a}
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Example:
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)
PIC18(L)F2X/45K50
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
0000
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register W
Process
Data
Write
W
ffff
Words:
Cycles:
0111
Description:
ffff
Encoding:
01da
Description:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
Example1:
DAW
Example:
Before Instruction
W
=
C
=
DC
=
After Instruction
W
C
DC
Example 2:
=
=
=
A5h
0
0
05h
1
0
DECF
Before Instruction
CNT
=
Z
=
After Instruction
CNT
=
Z
=
CNT,
1, 0
01h
0
00h
1
Before Instruction
W
=
C
=
DC
=
After Instruction
W
C
DC
=
=
=
CEh
0
0
34h
1
0
DS30000684B-page 409
PIC18(L)F2X/45K50
DECFSZ
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
Encoding:
0010
Description:
11da
ffff
ffff
Words:
Cycles:
1(2)
Note: Three cycles if skip and
followed by a 2-word instruction.
Encoding:
0100
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
HERE
DECFSZ
GOTO
Example:
CNT, 1, 1
LOOP
CONTINUE
Before Instruction
PC
=
After Instruction
CNT
=
If CNT
=
PC =
If CNT
PC =
DS30000684B-page 410
Address (HERE)
CNT - 1
0;
Address (CONTINUE)
0;
Address (HERE + 2)
ffff
ffff
Words:
Cycles:
1(2)
Note: Three cycles if skip and
followed by a 2-word instruction.
Q Cycle Activity:
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:
11da
Description:
Q Cycle Activity:
Q1
f {,d {,a}}
If skip:
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Example:
HERE
ZERO
NZERO
Before Instruction
TEMP
After Instruction
TEMP
If TEMP
PC
If TEMP
PC
DCFSNZ
:
:
TEMP, 1, 0
=
=
=
TEMP 1,
0;
Address (ZERO)
0;
Address (NZERO)
PIC18(L)F2X/45K50
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>)
Description:
1110
1111
1111
k19kkk
k7kkk
kkkk
kkkk0
kkkk8
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:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
GOTO THERE
After Instruction
PC =
Address (THERE)
Example:
INCF
Before Instruction
CNT
=
Z
=
C
=
DC
=
After Instruction
CNT
=
Z
=
C
=
DC
=
CNT, 1, 0
FFh
0
?
?
00h
1
1
1
DS30000684B-page 411
PIC18(L)F2X/45K50
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
=
DS30000684B-page 412
INCFSZ
:
:
Address (HERE)
CNT + 1
0;
Address (ZERO)
0;
Address (NZERO)
CNT, 1, 0
Example:
HERE
ZERO
NZERO
Before Instruction
PC
=
After Instruction
REG
=
If REG
PC
=
If REG
=
PC
=
INFSNZ
REG, 1, 0
Address (HERE)
REG + 1
0;
Address (NZERO)
0;
Address (ZERO)
PIC18(L)F2X/45K50
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
BFh
ffff
Words:
Cycles:
35h
9Ah
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
=
RESULT, 0, 1
13h
91h
13h
93h
DS30000684B-page 413
PIC18(L)F2X/45K50
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:
=
=
03h
ABh
ffff
ffff
Words:
Cycles:
LFSR 2, 3ABh
After Instruction
FSR2H
FSR2L
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
DS30000684B-page 414
REG, 0, 0
=
=
22h
FFh
=
=
22h
22h
PIC18(L)F2X/45K50
MOVFF
Move f to f
MOVLB
Syntax:
MOVFF fs,fd
Syntax:
MOVLB 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.)
Description:
1100
1111
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
REG1, REG2
=
=
33h
11h
=
=
33h
33h
DS30000684B-page 415
PIC18(L)F2X/45K50
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
DS30000684B-page 416
=
=
4Fh
FFh
4Fh
4Fh
PIC18(L)F2X/45K50
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
=
=
=
=
C4h
B5h
?
?
=
=
=
=
C4h
B5h
8Ah
94h
DS30000684B-page 417
PIC18(L)F2X/45K50
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
=
DS30000684B-page 418
REG, 1
PIC18(L)F2X/45K50
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
0000
0101
Words:
Cycles:
Q Cycle Activity:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
No
operation
POP TOS
value
No
operation
POP
GOTO
NEW
Example:
0000
Description:
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
PUSH
Before Instruction
TOS
PC
=
=
345Ah
0124h
After Instruction
PC
TOS
Stack (1 level down)
=
=
=
0126h
0126h
345Ah
DS30000684B-page 419
PIC18(L)F2X/45K50
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
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
1111
1111
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Start
Reset
No
operation
No
operation
Example:
Q Cycle Activity:
0000
RESET
After Instruction
Registers =
Flags*
=
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)
DS30000684B-page 420
PIC18(L)F2X/45K50
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:
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
Q2
Q3
Q4
Decode
No
operation
No
operation
POP PC
from stack
Set GIEH or
GIEL
Example:
1100
000s
Words:
No
operation
0000
Description:
GIE/GIEH, PEIE/GIEL.
Encoding:
Description:
Encoding:
No
operation
RETFIE
After Interrupt
PC
W
BSR
Status
GIE/GIEH, PEIE/GIEL
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
=
W contains table
offset value
W now has
table value
W = offset
Begin table
End of table
07h
value of kn
DS30000684B-page 421
PIC18(L)F2X/45K50
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:
RLCF
Before Instruction
REG
=
C
=
After Instruction
REG
=
W
=
C
=
DS30000684B-page 422
REG, 0, 0
1110 0110
0
1110 0110
1100 1100
1
PIC18(L)F2X/45K50
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
=
00da
RLNCF
Words:
Cycles:
0101 0111
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
=
1110 0110
0
1110 0110
0111 0011
0
DS30000684B-page 423
PIC18(L)F2X/45K50
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
Words:
Cycles:
1
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write to
destination
RRNCF
Before Instruction
REG
=
After Instruction
REG
=
Example 2:
f {,a}
0110
100a
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
Write
register f
Example:
Q Cycle Activity:
Example 1:
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
DS30000684B-page 424
PIC18(L)F2X/45K50
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 =
?
After Instruction
1
TO =
0
PD =
If WDT causes wake-up, this bit is cleared.
f {,d {,a}}
01da
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Example:
Q Cycle Activity:
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
DS30000684B-page 425
PIC18(L)F2X/45K50
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:
SUBLW
Before Instruction
W
=
C
=
After Instruction
W
=
C
=
Z
=
N
=
Example 2:
Cycles:
Q Cycle Activity:
Before Instruction
W
=
C
=
After Instruction
W
=
C
=
Z
=
N
=
Example 3:
02h
ffff
Words:
01h
?
SUBLW
ffff
02h
01h
1
; result is positive
0
0
11da
Description:
Q Cycle Activity:
Q1
f {,d {,a}}
02h
?
00h
1
; result is zero
1
0
SUBLW
Before Instruction
W
=
C
=
After Instruction
W
=
C
=
Z
=
N
=
02h
03h
?
FFh ; (2s complement)
0
; result is negative
0
1
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
=
Example 2:
Before Instruction
REG
=
W
=
C
=
After Instruction
REG
=
W
=
C
=
Z
=
N
=
Example 3:
1
2
1
0
0
; result is positive
SUBWF
REG, 0, 0
2
2
?
2
0
1
1
0
SUBWF
Before Instruction
REG
=
W
=
C
=
After Instruction
REG
=
W
=
C
=
Z
=
N
=
DS30000684B-page 426
3
2
?
; result is zero
REG, 1, 0
1
2
?
FFh ;(2s complement)
2
0
; result is negative
0
1
PIC18(L)F2X/45K50
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:
=
=
=
=
; 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
DS30000684B-page 427
PIC18(L)F2X/45K50
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
TBLRD
=
=
=
55h
00A356h
34h
=
=
34h
00A357h
+* ;
Before Instruction
TABLAT
TBLPTR
MEMORY (01A357h)
MEMORY (01A358h)
After Instruction
TABLAT
TBLPTR
*+ ;
Before Instruction
TABLAT
TBLPTR
MEMORY (00A356h)
After Instruction
TABLAT
TBLPTR
=
=
=
=
AAh
01A357h
12h
34h
=
=
34h
01A358h
10nn
nn=0 *
=1 *+
=2 *=3 +*
Description:
Words:
Cycles:
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)
DS30000684B-page 428
PIC18(L)F2X/45K50
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 )
DS30000684B-page 429
PIC18(L)F2X/45K50
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: Three 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
DS30000684B-page 430
TSTFSZ
:
:
CNT, 1
Address (HERE)
=
=
00h,
Address (ZERO)
00h,
Address (NZERO)
PIC18(L)F2X/45K50
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
=
REG, 1, 0
AFh
B5h
1Ah
B5h
DS30000684B-page 431
PIC18(L)F2X/45K50
27.2
A summary of the instructions in the extended instruction set is provided in Table 27-3. Detailed descriptions
are provided in Section 27.2.2 Extended Instruction
Set. The opcode field descriptions in Table 27-1 apply
to both the standard and extended PIC18 instruction
sets.
Note:
27.2.1
TABLE 27-3:
Note:
Mnemonic,
Operands
ADDFSR
ADDULNK
CALLW
MOVSF
f, k
k
MOVSS
zs, zd
PUSHL
SUBFSR
SUBULNK
f, k
k
zs, fd
Description
Cycles
MSb
DS30000684B-page 432
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
None
None
PIC18(L)F2X/45K50
27.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).
DS30000684B-page 433
PIC18(L)F2X/45K50
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
=
DS30000684B-page 434
zzzzs
ffffd
Words:
Cycles:
Q Cycle Activity:
Q1
CALLW
Decode
address (HERE)
10h
00h
06h
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
Q4
Read
source reg
Write
register f
(dest)
[05h], REG2
80h
=
=
33h
11h
80h
=
=
33h
33h
PIC18(L)F2X/45K50
MOVSS
PUSHL
Syntax:
Syntax:
PUSHL k
Operands:
Operands:
0k 255
Operation:
Operation:
k (FSR2),
FSR2 1 FSR2
Status Affected:
None
Status Affected:
None
Encoding:
1st word (source)
2nd word (dest.)
Description
1110
1111
1011
xxxx
1zzz
xzzz
zzzzs
zzzzd
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Decode
Example:
Q2
Q3
Determine
Determine
source addr source addr
Determine
dest addr
Determine
dest addr
Encoding:
1111
1010
kkkk
kkkk
Description:
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
80h
33h
11h
80h
33h
33h
DS30000684B-page 435
PIC18(L)F2X/45K50
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:
DS30000684B-page 436
SUBULNK 23h
Before Instruction
FSR2
=
PC
=
03FFh
0100h
After Instruction
FSR2
=
PC
=
03DCh
(TOS)
PIC18(L)F2X/45K50
27.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.
27.2.3.1
27.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.
DS30000684B-page 437
PIC18(L)F2X/45K50
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
[OFST] , 0
Before Instruction
W
OFST
FSR2
Contents
of 0A2Ch
After Instruction
W
Contents
of 0A2Ch
=
=
=
17h
2Ch
0A00h
20h
37h
20h
Example:
BSF
Before Instruction
FLAG_OFST
FSR2
Contents
of 0A0Ah
After Instruction
Contents
of 0A0Ah
[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
DS30000684B-page 438
[OFST]
=
=
2Ch
0A00h
00h
FFh
PIC18(L)F2X/45K50
27.2.5
DS30000684B-page 439
PIC18(L)F2X/45K50
28.0
DEVELOPMENT SUPPORT
28.1
Multiple projects
Multiple tools
Multiple configurations
Simultaneous debugging sessions
DS30000684B-page 440
PIC18(L)F2X/45K50
28.2
MPLAB XC Compilers
28.4
28.5
28.3
MPASM Assembler
DS30000684B-page 441
PIC18(L)F2X/45K50
28.6
28.7
DS30000684B-page 442
28.8
28.9
PIC18(L)F2X/45K50
28.11 Demonstration/Development
Boards, Evaluation Kits, and
Starter Kits
A wide variety of demonstration, development and
evaluation boards for various PIC MCUs and dsPIC
DSCs allows quick application development on fully
functional systems. Most boards include prototyping
areas for adding custom circuitry and provide
application firmware and source code for examination
and modification.
The boards support a variety of features, including LEDs,
temperature sensors, switches, speakers, RS-232
interfaces, LCD displays, potentiometers and additional
EEPROM memory.
DS30000684B-page 443
PIC18(L)F2X/45K50
29.0
ELECTRICAL SPECIFICATIONS
29.1
NOTICE: Stresses above those listed under Absolute Maximum Ratings may cause permanent damage to the
device. This is a stress rating only and functional operation of the device at those or any other conditions above those
indicated in the operation listings of this specification is not implied. Exposure to maximum rating conditions for
extended periods may affect device reliability.
DS30000684B-page 444
PIC18(L)F2X/45K50
29.2
The standard operating conditions for any device are defined as:
Operating Voltage:
Operating Temperature:
DS30000684B-page 445
PIC18(L)F2X/45K50
FIGURE 29-1:
5.5V
Voltage
5.0V
4.0V
3.6V
3.0V
2.7V
2.3V
1.8V
4
16
20
48
Frequency (MHz)
Note 1: Maximum Frequency 4 MHz, 1.8V to 2.7V, -40C to +85C
2: Maximum Frequency 48 MHz, 2.7V to 3.6V, -40C to +85C
FIGURE 29-2:
5.5V
Voltage
5.0V
4.0V
3.6V
3.0V
2.7V
2.3V
1.8V
20
30
40
48
Frequency (MHz)
Note 1: Maximum Frequency 20 MHz, 2.3V to 2.7V, -40C to +85C
2: Maximum Frequency 48 MHz, 2.7V to 5.5V, -40C to +85C
DS30000684B-page 446
PIC18(L)F2X/45K50
FIGURE 29-3:
5.5V
Voltage
5.0V
4.0V
3.6V
3.0V
2.7V
2.3V
1.8V
10
16 20
30
40
48
60 64
Frequency (MHz)
Note 1: Maximum Frequency 16 MHz, 2.3V to 2.7V, +85C to +125C
2: Maximum Frequency 48 MHz, 2.7V to 5.5V, +85C to +125C
DS30000684B-page 447
PIC18(L)F2X/45K50
29.3
DC Characteristics
TABLE 29-1:
PIC18(L)F2X/45K50
Param.
Symbol
No.
D001
VDD
Characteristic
Supply Voltage
Conditions
PIC18LF2X/45K50
1.8
3.6
Regulator disabled
PIC18F2X/45K50
2.3
5.5
Regulator enabled
3.0
3.3
3.6
Charging current
200
mA Note 4, 5
0.0
mA Note 4
D002
VDR
1.5
D003
VPOR
0.7
D004
SVDD
0.05
D005
VBOR
1.75
1.9
2.05
BORV<1:0> = 10
2.05
2.2
2.35
BORV<1:0> = 01
2.35
2.5
2.65
1.8V
BORV<1:0> = 00
D006
VLPBOR
Note 1:
2:
3:
4:
5:
(3)
2.1
This is the limit to which VDD can be lowered in Sleep mode, or during a device Reset, without losing RAM
data.
On LF devices with BOR enabled, operation is supported until a BOR occurs. This is valid although VDD
may be below the minimum rated supply voltage.
With BOR enabled, full-speed operation (FOSC = 48 MHz) is supported until a BOR occurs. This is valid
although VDD may be below the minimum voltage for this frequency.
This is the inrush current associated with initial charging of the VUSB3V3 capacitor during a fast VDD ramp.
The microcontroller can still start-up from VDD power sources that are limited to significantly less than this
value.
The VUSB3V3 regulator is only designed to supply the current requirements of the microcontroller and USB
transceiver. It is not intended to supply external loads.
DS30000684B-page 448
PIC18(L)F2X/45K50
TABLE 29-2:
PIC18LF2X/45K50
PIC18F2X/45K50
Param.
No.
Typ.
Typ.
Max.
Max.
Units
+25C +60C +85C +125C
Device Characteristics
Conditions
VDD
Notes
WDT, BOR, FVR and SOSC
disabled, all Peripherals
inactive
(IPD)(1)
Sleep mode
0.01
0.04
10
1.8V
0.01
0.06
40
3.0V
12
13
25
35
2.3V
13
14
30
40
3.0V
13
14
35
50
5.0V
2.5
2.5
1.8V
Watchdog Timer
Brown-out Reset(2)
D008
D010
D011
Secondary Oscillator
Note 1:
2:
3:
0.3
0.3
0.5
0.5
2.5
3.0V
0.35
0.35
5.0
5.0
2.3V
0.5
0.5
5.0
5.0
3.0V
0.5
0.5
5.0
5.0
5.0V
8.5
15
16
2.0V
9.5
15
16
3.0V
3.4
3.4
15
16
2.3V
3.8
3.8
15
16
3.0V
5.2
5.2
15
16
5.0V
6.5
6.7
15
15
2.0V
7.5
15
15
3.0V
2.1
2.1
15
15
2.3V
2.4
2.4
15
15
3.0V
3.2
3.2
15
15
5.0V
0.5
10
1.8V
0.6
1.1
10
3.0V
0.5
10
2.3V
0.6
1.1
10
3.0V
0.6
1.1
10
5.0V
32 kHz on SOSC
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.).
On LF devices, the BOR, HLVD and FVR enable internal band gap reference. With more than one of
these modules enabled, the current consumption will be less than the sum of the specifications. On F
devices, the internal band gap reference is always enabled and its current consumption is included in the
Power-down Base Current (IPD).
A/D converter differential currents apply only in Run mode. In Sleep or Idle mode both the ADC and the
FRC turn off as soon as conversion (if any) is complete.
DS30000684B-page 449
PIC18(L)F2X/45K50
TABLE 29-2:
PIC18LF2X/45K50
PIC18F2X/45K50
Param.
No.
Typ.
Typ.
Max.
Max.
Units
+25C +60C +85C +125C
D015
Device Characteristics
Comparators
D16
Comparators
D017
DAC
FVR(2)
D018
D013
A/D
Note 1:
2:
3:
Converter(3)
18
18
Conditions
VDD
1.8V
18
18
3.0V
18
18
2.3V
18
18
3.0V
20
20
5.0V
38
38
95
95
1.8V
40
40
105
105
3.0V
39
39
95
95
2.3V
40
40
105
105
3.0V
40
40
105
105
5.0V
12
12
22
25
1.8V
20
20
35
35
3.0V
15
15
30
30
2.3V
20
20
35
35
3.0V
32
32
60
60
5.0V
15
16
25
25
1.8V
15
16
25
25
3.0V
28
28
45
45
2.3V
31
31
55
55
3.0V
66
66
100
100
5.0V
185
185
370
370
1.8V
210
210
400
400
3.0V
200
200
380
380
2.3V
210
210
400
400
3.0V
250
250
450
450
5.0V
Notes
LP mode
HP mode
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.).
On LF devices, the BOR, HLVD and FVR enable internal band gap reference. With more than one of
these modules enabled, the current consumption will be less than the sum of the specifications. On F
devices, the internal band gap reference is always enabled and its current consumption is included in the
Power-down Base Current (IPD).
A/D converter differential currents apply only in Run mode. In Sleep or Idle mode both the ADC and the
FRC turn off as soon as conversion (if any) is complete.
DS30000684B-page 450
PIC18(L)F2X/45K50
TABLE 29-3:
PIC18LF2X/45K50
PIC18F2X/45K50
Param.
Device Characteristics
No.
D020
D021
D022
D023
D024
Note 1:
2:
Conditions
3.6
23
-40C
3.9
25
+25C
3.9
+60C
3.9
28
+85C
4.0
30
+125C
8.1
26
-40C
8.4
30
+25C
8.6
+60C
8.7
35
+85C
10.7
40
+125C
16
35
-40C
17
35
+25C
18
35
+85C
19
50
+125C
18
50
-40C
20
50
+25C
21
50
+85C
22
60
+125C
19
55
-40C
21
55
+25C
22
55
+85C
23
70
+125C
VDD = 1.8V
FOSC = 31 kHz
(RC_RUN mode,
INTRC source)
VDD = 3.0V
VDD = 2.3V
FOSC = 31 kHz
(RC_RUN mode,
INTRC source)
VDD = 3.0V
VDD = 5.0V
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.
Test condition: All Peripheral Module Control bits in PMD0 and PMD1 set to 1.
The test conditions for all IDD measurements in active operation mode are:
All I/O pins set as outputs driven to Vss;
MCLR = VDD;
OSC1 = external square wave, from rail-to-rail (PRI_RUN and PRI_IDLE only).
DS30000684B-page 451
PIC18(L)F2X/45K50
TABLE 29-3:
PIC18LF2X/45K50
PIC18F2X/45K50
Param.
Device Characteristics
No.
D030
0.35
0.50
mA
-40C to +125C
VDD = 1.8V
D031
0.45
0.65
mA
-40C to +125C
VDD = 3.0V
D032
0.40
0.60
mA
-40C to +125C
VDD = 2.3V
D033
0.50
0.65
mA
-40C to +125C
VDD = 3.0V
D034
0.55
0.75
mA
-40C to +125C
VDD = 5.0V
Conditions
FOSC = 1 MHz
(RC_RUN mode,
HFINTOSC source)
FOSC = 1 MHz
(RC_RUN mode,
HFINTOSC source)
D035
1.3
2.0
mA
-40C to +125C
VDD = 1.8V
D036
2.2
3.0
mA
-40C to +125C
VDD = 3.0V
D037
1.7
2.0
mA
-40C to +125C
VDD = 2.3V
D038
2.2
3.0
mA
-40C to +125C
VDD = 3.0V
D039
2.5
3.5
mA
-40C to +125C
VDD = 5.0V
D041
6.2
8.5
mA
-40C to +125C
VDD = 3.0V
FOSC = 48 MHz
(RC_RUN mode,
HFINTOSC + PLL
source)
D043
6.2
8.5
mA
-40C to +125C
VDD = 3.0V
D044
6.8
9.5
mA
-40C to +125C
VDD = 5.0V
FOSC = 48 MHz
(RC_RUN mode,
HFINTOSC + PLL
source)
Note 1:
2:
FOSC = 16 MHz
(RC_RUN mode,
HFINTOSC source)
FOSC = 16 MHz
(RC_RUN mode,
HFINTOSC 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.
Test condition: All Peripheral Module Control bits in PMD0 and PMD1 set to 1.
The test conditions for all IDD measurements in active operation mode are:
All I/O pins set as outputs driven to Vss;
MCLR = VDD;
OSC1 = external square wave, from rail-to-rail (PRI_RUN and PRI_IDLE only).
DS30000684B-page 452
PIC18(L)F2X/45K50
TABLE 29-4:
PIC18LF2X/45K50
PIC18F2X/45K50
Param.
No.
Device Characteristics
Typ.
0.5
18
-40C
0.6
18
+25C
0.7
+60C
0.75
20
+85C
2.3
22
+125C
1.1
20
-40C
1.2
20
+25C
1.3
+60C
1.4
22
+85C
3.2
25
+125C
17
30
-40C
13
30
+25C
14
30
+85C
15
45
+125C
19
35
-40C
15
35
+25C
16
35
+85C
17
50
+125C
21
40
-40C
15
40
+25C
16
40
+85C
18
60
+125C
D045
D046
D047
D048
D049
Note 1:
2:
Max. Units
Conditions
VDD = 1.8V
FOSC = 31 kHz
(RC_IDLE mode,
INTRC source)
VDD = 3.0V
VDD = 2.3V
FOSC = 31 kHz
(RC_IDLE mode,
INTRC source)
VDD = 3.0V
VDD = 5.0V
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.
Test condition: All Peripheral Module Control bits in PMD0 and PMD1 set to 1.
The test conditions for all IDD measurements in active operation mode are:
All I/O pins set as outputs driven to Vss;
MCLR = VDD;
OSC1 = external square wave, from rail-to-rail (PRI_RUN and PRI_IDLE only).
DS30000684B-page 453
PIC18(L)F2X/45K50
TABLE 29-4:
PIC18LF2X/45K50
PIC18F2X/45K50
Param.
No.
Typ.
Max. Units
D055
0.25
0.40
mA
-40C to +125C
VDD = 1.8V
D056
0.35
0.50
mA
-40C to +125C
VDD = 3.0V
D057
0.30
0.45
mA
-40C to +125C
VDD = 2.3V
D058
0.40
0.50
mA
-40C to +125C
VDD = 3.0V
D059
0.45
0.60
mA
-40C to +125C
VDD = 5.0V
D060
0.50
0.7
mA
-40C to +125C
VDD = 1.8V
D061
0.80
1.1
mA
-40C to +125C
VDD = 3.0V
D062
0.65
1.0
mA
-40C to +125C
VDD = 2.3V
D063
0.80
1.1
mA
-40C to +125C
VDD = 3.0V
D064
0.95
1.2
mA
-40C to +125C
VDD = 5.0V
D066
2.5
3.5
mA
-40C to +125C
VDD = 3.0V
FOSC = 48 MHz
(RC_IDLE mode,
HFINTOSC + PLL
source)
D068
2.5
3.5
mA
-40C to +125C
VDD = 3.0V
D069
3.0
4.5
mA
-40C to +125C
VDD = 5.0V
FOSC = 48 MHz
(RC_IDLE mode,
HFINTOSC + PLL
source)
Note 1:
2:
Device Characteristics
Conditions
FOSC = 1 MHz
(RC_IDLE mode,
HFINTOSC source)
FOSC = 1 MHz
(RC_IDLE mode,
HFINTOSC source)
FOSC = 16 MHz
(RC_IDLE mode,
HFINTOSC source)
FOSC = 16 MHz
(RC_IDLE mode,
HFINTOSC 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.
Test condition: All Peripheral Module Control bits in PMD0 and PMD1 set to 1.
The test conditions for all IDD measurements in active operation mode are:
All I/O pins set as outputs driven to Vss;
MCLR = VDD;
OSC1 = external square wave, from rail-to-rail (PRI_RUN and PRI_IDLE only).
DS30000684B-page 454
PIC18(L)F2X/45K50
TABLE 29-5:
PIC18LF2X/45K50
PIC18F2X/45K50
Param.
No.
Device Characteristics
Typ.
Max. Units
0.11
0.20
mA
-40C to +125C
VDD = 1.8V
D071
0.17
0.25
mA
-40C to +125C
VDD = 3.0V
D072
0.15
0.25
mA
-40C to +125C
VDD = 2.3V
D073
0.20
0.30
mA
-40C to +125C
VDD = 3.0V
D074
0.25
0.35
mA
-40C to +125C
VDD = 5.0V
D075
1.45
2.0
mA
-40C to +125C
VDD = 1.8V
D076
2.60
3.5
mA
-40C to +125C
VDD = 3.0V
D077
1.95
2.5
mA
-40C to +125C
VDD = 2.3V
D078
2.65
3.5
mA
-40C to +125C
VDD = 3.0V
D079
2.95
4.5
mA
-40C to +125C
VDD = 5.0V
D080
7.5
10
mA
-40C to +125C
VDD = 3.0V
FOSC = 48 MHz
(PRI_RUN,
ECH oscillator)
D081
7.5
10
mA
-40C to +125C
VDD = 3.0V
D082
8.5
11.5
mA
-40C to +125C
VDD = 5.0V
FOSC = 48 MHz
(PRI_RUN mode,
ECH source)
D083
1.0
1.5
mA
-40C to +125C
VDD = 1.8V
D084
1.8
3.0
mA
-40C to +125C
VDD = 3.0V
D085
1.4
2.0
mA
-40C to +125C
VDD = 2.3V
D086
1.85
2.5
mA
-40C to +125C
VDD = 3.0V
D087
2.1
3.0
mA
-40C to +125C
VDD = 5.0V
D088
6.35
9.0
mA
-40C to +125C
VDD = 3.0V
FOSC = 16 MHz
48 MHz Internal
(PRI_RUN mode,
ECH + PLL source)
D089
6.35
9.0
mA
-40C to +125C
VDD = 3.0V
D090
7.0
10
mA
-40C to +125C
VDD = 5.0V
FOSC = 16 MHz
48 MHz Internal
(PRI_RUN mode,
ECH + PLL source)
D070
Note 1:
2:
Conditions
FOSC = 1 MHz
(PRI_RUN mode,
ECM source)
FOSC = 1 MHz
(PRI_RUN mode,
ECM source)
FOSC = 20 MHz
(PRI_RUN mode,
ECH source)
FOSC = 20 MHz
(PRI_RUN mode,
ECH source)
FOSC = 4 MHz
16 MHz Internal
(PRI_RUN mode,
ECM + PLL source)
FOSC = 4 MHz
16 MHz Internal
(PRI_RUN mode,
ECM + PLL 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.
Test condition: All Peripheral Module Control bits in PMD0 and PMD1 set to 1.
The test conditions for all IDD measurements in active operation mode are:
All I/O pins set as outputs driven to Vss;
MCLR = VDD;
OSC1 = external square wave, from rail-to-rail (PRI_RUN and PRI_IDLE only).
DS30000684B-page 455
PIC18(L)F2X/45K50
TABLE 29-6:
PIC18LF2X/45K50
PIC18F2X/45K50
Param.
No.
Typ.
Device Characteristics
Supply Current (IDD)(1),(2)
D100
Max. Units
Conditions
0.030 0.050
mA
-40C to +125C
VDD = 1.8V
D101
0.045 0.065
mA
-40C to +125C
VDD = 3.0V
D102
0.06
0.12
mA
-40C to +125C
VDD = 2.3V
D103
0.08
0.15
mA
-40C to +125C
VDD = 3.0V
D104
0.13
0.20
mA
-40C to +125C
VDD = 5.0V
D105
0.45
0.8
mA
-40C to +125C
VDD = 1.8V
D106
0.70
1.0
mA
-40C to +125C
VDD = 3.0V
D107
0.55
0.8
mA
-40C to +125C
VDD = 2.3V
D108
0.75
1.0
mA
-40C to +125C
VDD = 3.0V
D109
0.90
1.2
mA
-40C to +125C
VDD = 5.0V
D110
2.25
3.0
mA
-40C to +125C
VDD = 3.0V
Fosc = 48 MHz
(PRI_IDLE mode,
ECH source)
D111
2.25
3.0
mA
-40C to +125C
VDD = 3.0V
D112
2.60
3.5
mA
-40C to +125C
VDD = 5.0V
Fosc = 48 MHz
(PRI_IDLE mode,
ECH source)
D113
0.35
0.6
mA
-40C to +125C
VDD = 1.8V
D114
0.55
0.8
mA
-40C to +125C
VDD = 3.0V
D115
0.45
0.6
mA
-40C to +125C
VDD = 2.3V
D116
0.60
0.9
mA
-40C to +125C
VDD = 3.0V
D117
0.70
1.0
mA
-40C to +125C
VDD = 5.0V
D118
2.2
3.0
mA
-40C to +125C
VDD = 3.0V
Fosc = 16 MHz
48 MHz Internal
(PRI_IDLE mode,
ECH + PLL source)
D119
2.2
3.0
mA
-40C to +125C
VDD = 3.0V
D120
2.5
3.5
mA
-40C to +125C
VDD = 5.0V
Fosc = 16 MHz
48 MHz Internal
(PRI_IDLE mode,
ECH + PLL source)
Note 1:
2:
Fosc = 1 MHz
(PRI_IDLE mode,
ECM source)
Fosc = 1 MHz
(PRI_IDLE mode,
ECM source)
Fosc = 20 MHz
(PRI_IDLE mode,
ECH source)
Fosc = 20 MHz
(PRI_IDLE mode,
ECH source)
Fosc = 4 MHz
16 MHz Internal
(PRI_IDLE mode,
ECM + PLL source)
Fosc = 4 MHz
16 MHz Internal
(PRI_IDLE mode,
ECM + PLL 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.
Test condition: All Peripheral Module Control bits in PMD0 and PMD1 set to 1.
The test conditions for all IDD measurements in active operation mode are:
All I/O pins set as outputs driven to Vss;
MCLR = VDD;
OSC1 = external square wave, from rail-to-rail (PRI_RUN and PRI_IDLE only).
DS30000684B-page 456
PIC18(L)F2X/45K50
TABLE 29-7:
PIC18LF2X/45K50
PIC18F2X/45K50
Param.
No.
Device Characteristics
Typ.
3.5
23
-40C
3.7
25
+25C
3.8
+60C
4.0
28
+85C
5.1
30
+125C
6.2
26
-40C
6.4
30
+25C
6.5
+60C
6.8
35
+85C
7.8
40
+125C
15
35
-40C
16
35
+25C
17
35
+85C
19
50
+125C
18
50
-40C
19
50
+25C
21
50
+85C
22
60
+125C
19
55
-40C
20
55
+25C
22
55
+85C
23
70
+125C
D130
D131
D132
D133
D134
Note 1:
2:
Max. Units
Conditions
VDD = 1.8V
Fosc = 32 kHz
(SEC_RUN mode,
SOSC source)
VDD = 3.0V
VDD = 2.3V
Fosc = 32 kHz
(SEC_RUN mode,
SOSC source)
VDD = 3.0V
VDD = 5.0V
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.
Test condition: All Peripheral Module Control bits in PMD0 and PMD1 set to 1.
The test conditions for all IDD measurements in active operation mode are:
All I/O pins set as outputs driven to Vss;
MCLR = VDD;
SOSCI / SOSCO = complementary external square wave, from rail-to-rail.
DS30000684B-page 457
PIC18(L)F2X/45K50
TABLE 29-7:
PIC18LF2X/45K50
PIC18F2X/45K50
Param.
No.
Typ.
Device Characteristics
D135
D136
D137
D138
D139
Note 1:
2:
Max. Units
Conditions
0.9
18
-40C
1.0
18
+25C
1.1
+60C
1.3
20
+85C
2.3
22
+125C
1.3
20
-40C
1.4
20
+25C
1.5
+60C
1.8
22
+85C
2.9
25
+125C
12
30
-40C
13
30
+25C
14
30
+85C
16
45
+125C
13
35
-40C
14
35
+25C
16
35
+85C
18
50
+125C
14
40
-40C
15
40
+25C
16
40
+85C
18
60
+125C
VDD = 1.8V
Fosc = 32 kHz
(SEC_IDLE mode,
SOSC source)
VDD = 3.0V
VDD = 2.3V
Fosc = 32 kHz
(SEC_IDLE mode,
SOSC source)
VDD = 3.0V
VDD = 5.0V
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.
Test condition: All Peripheral Module Control bits in PMD0 and PMD1 set to 1.
The test conditions for all IDD measurements in active operation mode are:
All I/O pins set as outputs driven to Vss;
MCLR = VDD;
SOSCI / SOSCO = complementary external square wave, from rail-to-rail.
DS30000684B-page 458
PIC18(L)F2X/45K50
TABLE 29-8:
DC CHARACTERISTICS
Param.
Symbol
No.
VIL
Min.
Typ.
Max.
Units
Conditions
0.8
0.15 VDD
D140
D140A
D141
D142
0.2 VDD
0.3 VDD
0.8
0.2 VDD
0.3 VDD
D142A
mode)(1)
D147
D147A
with Schmitt Trigger buffer
D148
with
I2C
levels
2.0
0.8 VDD
0.7 VDD
2.1
D149
MCLR
0.8 VDD
D150A
0.7 VDD
D150B
0.9 VDD
IIL
D155
D158
Note 1:
2:
3:
4:
IPU
IPURB
0.1
0.7
4
50
100
200
nA
nA
nA
+25C(4)
+60C
+85C
25
85
200
25
130
300
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.
DS30000684B-page 459
PIC18(L)F2X/45K50
TABLE 29-8:
DC CHARACTERISTICS
Param.
Symbol
No.
VOL
D159
D161
2:
3:
4:
Max.
Units
Conditions
0.6
25
85
200
25
130
300
VDD - 0.7
(3)
Note 1:
Typ.
D160
Min.
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.
DS30000684B-page 460
PIC18(L)F2X/45K50
TABLE 29-9:
Sym.
Characteristic
Min.
Typ.
Max.
Units
Conditions
VPP
D171
IDDP
10
mA
100K
E/W
VDDMIN
VDDMAX
ED
Byte Endurance
D173
VDRW
D175
TDEW
ms
D176
40
Year
Provided no other
specifications are violated
D177
TREF
1M
10M
E/W
-40C to +85C
-40C to +85C
Using EECON to read/
write
EP
Cell Endurance
D179
VPR
D181
VIW
D182
VIW
D183
TIW
D184
10K
E/W
VDDMIN
VDDMAX
2.2
VDDMAX
PIC18LF2X/45K50
VDDMIN
VDDMAX
PIC18F2X/45K50
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 8.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.
5: Self-write and Block Erase.
DS30000684B-page 461
PIC18(L)F2X/45K50
TABLE 29-10: USB MODULE SPECIFICATIONS
Standard Operating Conditions (unless otherwise stated)
Param.
No.
D313
Sym.
Characteristic
VUSB
USB Voltage
3.0
3.6
Conditions
Voltage on VUSB3V3 pin must be in this
range for proper USB operation
D314
IIL
D315
0.8
D316
2.0
D318
VDIFS
0.2
D319
VCM
0.8
2.5
D320
ZOUT
28
44
D321
VOL
0.0
0.3
D322
VOH
2.8
3.6
D323
CUSB
0.33 0.47
Note 1: The D+ and D- signal lines have been built-in impedance matching resistors. No external resistors,
capacitors or magnetic components are necessary on the D+/D- signal paths between the PIC18(L)F2X/
45K50 family device and USB cable.
DS30000684B-page 462
PIC18(L)F2X/45K50
29.4
Analog Characteristics
Sym.
CM01
VICM
CM04*
TRESP
TMC2OV
CM05*
*
Note 1:
VIOFF
CM02
Characteristics
Response Time
(1)
Min.
Typ.
Max.
Units
Comments
30
mV
High-Power mode
VREF = VDD/2
40
mV
Low-Power mode
VREF = VDD/2
VSS
VDD
200
400
ns
High-Power mode
600
3500
ns
Low-Power mode
10
Sym.
Characteristics
Min.
Typ.
Max.
Units
CV01*
CLSB
Step Size(2)
VDD/32
CV02*
CACC
Absolute Accuracy
1/2
LSb
CV03*
CR
5k
CV04*
CST
Time(1)
10
CV05*
CV06*
VSRC-
CV07*
*
Note 1:
2:
Settling
VSRC- + 2
VDD
VSS
VSRC+ 2
VDD
Comments
VSRC 2.0V
DS30000684B-page 463
PIC18(L)F2X/45K50
TABLE 29-13:
Sym.
VROUT
VR02
VROUT
VR04*
TSTABLE
*
Characteristics
VR voltage output to ADC
Settling Time
Min.
Typ.
Max.
Units
Comments
0.973
1.024
1.085
1.946
2.048
2.171
3.891
4.096
4.342
0.942
1.024
1.096
1.884
2.048
2.191
3.768
4.096
4.383
25
100
0 to 85C
Sym.
Characteristics
Min.
Typ.(1)
Max.
Units
Comments
CT01
IOUT1
0.55
IRNG<1:0> = 01
CT02
IOUT2
5.5
IRNG<1:0> = 10
CT03
IOUT3
55
IRNG<1:0> = 11
VDD 3.0V
Note 1:
FIGURE 29-4:
VHLVD
(HLVDIF set by hardware)
(HLVDIF can be
cleared by software)
HLVDIF
DS30000684B-page 464
PIC18(L)F2X/45K50
TABLE 29-15: HIGH/LOW-VOLTAGE DETECT CHARACTERISTICS
Standard Operating Conditions (unless otherwise stated)
Param.
Symbol
No.
D420
Characteristic
HLVDL<3:0>
Min.
Typ.
Max.
Units
0000
1.69
1.84
1.99
0001
1.92
2.07
2.22
0010
2.08
2.28
2.48
0011
2.24
2.44
2.64
0100
2.34
2.54
2.74
0101
2.54
2.74
2.94
0110
2.62
2.87
3.12
0111
2.76
3.01
3.26
1000
3.00
3.30
3.60
1001
3.18
3.48
3.78
1010
3.44
3.69
3.94
1011
3.66
3.91
4.16
1100
3.90
4.15
4.40
1101
4.11
4.41
4.71
1110
4.39
4.74
5.09
1111
V(HLVDIN pin)
Conditions
Production tested at TAMB = +25C. Specifications over temperature limits ensured by characterization.
DS30000684B-page 465
PIC18(L)F2X/45K50
29.5
AC (Timing) Characteristics
29.5.1
3. TCC:ST
2. TppS
4. Ts
T
F
Frequency
Time
osc
rd
rw
sc
ss
t0
t1
wr
OSC1
RD
RD or WR
SCK
SS
T0CKI
T13CKI
WR
Fall
High
Invalid (High-impedance)
Low
P
R
V
Z
Period
Rise
Valid
High-impedance
output access
Bus free
High
Low
High
Low
Hold
SU
Setup
DAT
STA
STO
Stop condition
ST
DS30000684B-page 466
PIC18(L)F2X/45K50
29.5.2
TIMING CONDITIONS
FIGURE 29-5:
Load Condition 2
VDD/2
RL
CL
Pin
VSS
CL
Pin
VSS
Legend:
RL = 464
CL = 50 pF
DS30000684B-page 467
PIC18(L)F2X/45K50
29.5.3
FIGURE 29-6:
Q1
Q2
Q3
Q4
Q1
OSC1
1
CLKO
Symbol
1A
FOSC
TOSC
Characteristic
Min.
Max.
Units
Conditions
External CLKIN
Frequency(1)
DC
DC
DC
4
16
48
MHz
MHz
MHz
Oscillator Frequency(1)
DC
MHz
RC Oscillator mode
200
kHz
LP Oscillator mode
0.1
MHz
XT Oscillator mode
MHz
16
MHz
20
MHz
0.25
62.5
20.8
s
ns
ns
Oscillator Period(1)
250
ns
RC Oscillator mode
200
LP Oscillator mode
0.25
250
10
250
s
ns
XT Oscillator mode
HS Oscillator mode, VDD < 2.7V
62.5
250
ns
50
250
ns
TCY
83.3
ns
TCY = 4/FOSC
TOSL,
TOSH
2.5
LP Oscillator mode
Note 1:
TOSR,
TOSF
30
ns
XT Oscillator mode
10
ns
HS Oscillator mode
50
ns
LP Oscillator mode
20
ns
XT 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.
DS30000684B-page 468
PIC18(L)F2X/45K50
TABLE 29-18: PLL CLOCK TIMING SPECIFICATIONS
Param.
Sym.
No.
F10
Characteristic
Min.
Max.
Units
MHz
12
MHz
2.7V VDD,
-40C to +85C
Conditions
F10B
MHz
2.7V VDD,
-40C to +85C
F11
FSYS
16
20
MHz
16
48
MHz
2.7V VDD,
-40C to +85C
ms
F12
trc
OA1B
Characteristic
Min.
Typ.
Units
-2
-3
-5
Conditions
+2
+0C to +70C
+2
+70C to +85C
+5
-40C to +125C
-40C to +85C(2), Active Clock Tune
is enabled and locked.
HF-INTOSC Accuracy(1)
0.05
+0.20
0.1
26.5625
35.9375
kHz
-40C to +85C
25
37.2
kHz
+85C to +125C
OA1C
OA2
Note 1:
2:
Max.
Frequency calibrated at 25C. OSCTUNE register can be used to compensate for temperature drift.
Accuracy measured with respect to reference source.
DS30000684B-page 469
PIC18(L)F2X/45K50
FIGURE 29-7:
Q4
Q2
Q3
OSC1
11
10
CLKO
13
14
19
12
18
16
I/O pin
(Input)
15
17
I/O pin
(Output)
Note:
New Value
Old Value
20, 21
Refer to Figure 29-5 for Load conditions.
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
14
TCKL2IOV
15
16
TCKH2IOI
17
0.5 TCY + 20
ns
Note 1
0.25 TCY + 25
ns
Note 1
ns
Note 1
TOSH2IOV
50
150
ns
18
TOSH2IOI
100
ns
19
ns
20
TIOR
40
15
72
32
ns
ns
VDD = 1.8V
VDD = 3.3V 5.0V
21
TIOF
28
15
55
30
ns
ns
VDD = 1.8V
VDD = 3.3V 5.0V
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 CLKO output is 4 x TOSC.
DS30000684B-page 470
PIC18(L)F2X/45K50
FIGURE 29-8:
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 29-9:
VDD
BVDD
35
VBGAP = 1.2V
VIVRST
Enable Internal
Reference Voltage
Internal Reference
Voltage Stable
36
DS30000684B-page 471
PIC18(L)F2X/45K50
TABLE 29-21: RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER, POWER-UP TIMER
AND BROWN-OUT RESET REQUIREMENTS
Param.
Symbol
No.
Characteristic
Min.
Typ.
Max.
Units
4.1
4.7
ms
1:1 prescaler
TOSC = OSC1 period
30
TMCL
31
TWDT
3.5
32
TOST
1024 TOSC
1024 TOSC
33
TPWRT
54.8
64.4
74.1
ms
34
TIOZ
35
TBOR
36
TIVRST
37
THLVD
38
TCSD
39
TIOBST
Note 1:
200(1)
25
35
200(1)
10
0.25
ms
Conditions
Minimum pulse width that will consistently trigger a Reset or interrupt. Shorter pulses may intermittently
trigger a response.
FIGURE 29-10:
T0CKI
41
40
42
T1CKI/T3CKI
46
45
47
48
TMR0 or
TMR1
Note:
DS30000684B-page 472
PIC18(L)F2X/45K50
TABLE 29-22: TIMER0 AND TIMER1/3 EXTERNAL CLOCK REQUIREMENTS
Param.
No.
Symbol
Characteristic
40
TT0H
No prescaler
41
TT0L
No prescaler
Min.
Max.
0.5 TCY + 20
With prescaler
TT0P
10
ns
ns
10
ns
TCY + 10
ns
Greater of:
20 ns or
(TCY + 40)/N
ns
0.5 TCY + 20
ns
10
ns
Asynchronous
30
ns
0.5 TCY + 5
ns
10
ns
Asynchronous
30
ns
Synchronous
Greater of:
20 ns or
(TCY + 40)/N
ns
Asynchronous
60
ns
DC
50
kHz
2 TOSC
7 TOSC
T0CKI Period
No prescaler
With prescaler
45
46
47
TT1H
TT1L
TT1P
FT 1
48
TxCKI
Input
Period
FIGURE 29-11:
ns
0.5 TCY + 20
With prescaler
42
Units Conditions
N = prescale value
(1, 2, 4,..., 256)
N = prescale value
(1, 2, 4, 8)
50
51
52
CCPx
(Compare or PWM Mode)
53
Note:
54
DS30000684B-page 473
PIC18(L)F2X/45K50
TABLE 29-23: CAPTURE/COMPARE/PWM REQUIREMENTS (ALL CCP MODULES)
Param.
Symbol
No.
Characteristic
50
TCCL
51
TCCH
No prescaler
Min.
Max.
Units
0.5 TCY + 20
ns
With prescaler
10
ns
0.5 TCY + 20
ns
10
ns
3 TCY + 40
N
ns
With prescaler
52
TCCP
53
TCCR
25
ns
54
TCCF
25
ns
FIGURE 29-12:
Conditions
N = prescale value
(1, 4 or 16)
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:
DS30000684B-page 474
PIC18(L)F2X/45K50
TABLE 29-24: EXAMPLE SPI MODE REQUIREMENTS (MASTER MODE, CKE = 0 OR 1)
Param.
No.
Symbol
Characteristic
Min.
Max. Units
Conditions
73
TDIV2SCH,
TDIV2SCL
25
ns
74
TSCH2DIL,
TSCL2DIL
25
ns
75
TDOR
30
ns
Note 1
76
TDOF
20
ns
Note 1
78
TSCR
30
ns
Note 1
79
TSCF
20
ns
Note 1
80
20
ns
81
TCY
ns
Note 1:
When the slew rate control limiting I/O port feature is disabled.
FIGURE 29-13:
SS
81
SCK
(CKP = 0)
71
72
79
73
SCK
(CKP = 1)
80
78
SDO
MSb
bit 6 - - - - - -1
LSb
bit 6 - - - -1
LSb In
75, 76
SDI
MSb In
74
Note:
DS30000684B-page 475
PIC18(L)F2X/45K50
FIGURE 29-14:
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 29-25: EXAMPLE SPI MODE REQUIREMENTS (SLAVE MODE TIMING, CKE = 0 OR 1)
Param.
No.
Symbol
Characteristic
70
71
TSCH
72
TSCL
73
Min.
TCY
ns
Continuous
25
ns
Continuous
30
ns
25
ns
74
TSCH2DIL,
TSCL2DIL
25
ns
75
TDOR
30
ns
Note 1
76
TDOF
20
ns
Note 1
77
TSSH2DOZ
10
50
ns
80
60
ns
Note 1
82
TSSL2DOV
60
ns
Note 1
83
1.5 TCY + 40
ns
Note 1:
When the slew rate control limiting I/O port feature is disabled.
DS30000684B-page 476
PIC18(L)F2X/45K50
FIGURE 29-15:
SS
70
SCK
(CKP = 0)
83
71
72
SCK
(CKP = 1)
80
MSb
SDO
bit 6 - - - - - -1
LSb
75, 76
SDI
Note:
MSb In
77
bit 6 - - - -1
LSb In
74
Refer to Figure 29-5 for Load conditions.
FIGURE 29-16:
SCL
91
90
93
92
SDA
Start
Condition
Note:
Stop
Condition
DS30000684B-page 477
PIC18(L)F2X/45K50
TABLE 29-26: I2C BUS START/STOP BITS REQUIREMENTS (SLAVE MODE)
Param.
Symbol
No.
90
TSU:STA
91
THD:STA
Characteristic
Start Condition
Min.
Max.
Units
Conditions
4700
ns
ns
Setup Time
600
Start Condition
4000
Hold Time
600
Stop Condition
4700
92
TSU:STO
93
Setup Time
Hold Time
FIGURE 29-17:
600
4000
600
ns
ns
102
100
101
SCL
90
106
107
91
92
SDA
In
110
109
109
SDA
Out
Note:
DS30000684B-page 478
PIC18(L)F2X/45K50
TABLE 29-27: I2C BUS DATA REQUIREMENTS (SLAVE MODE)
Param.
Symbol
No.
100
THIGH
Characteristic
Clock High Time
TLOW
TR
103
TF
0.6
1.5 TCY
4.7
1.3
1.5 TCY
1000
ns
ns
300
ns
ns
CB is specified to be from
10 to 400 pF
4.7
0.6
91
4.0
0.6
106
ns
0.9
107
250
ns
100
ns
92
4.7
0.6
109
TAA
3500
ns
ns
4.7
1.3
400
pF
110
TBUF
D102
CB
Note 1:
2:
CB is specified to be from
10 to 400 pF
Conditions
4.0
SSP Module
102
Max. Units
SSP Module
101
Min.
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.
DS30000684B-page 479
PIC18(L)F2X/45K50
MASTER SSP I2C BUS START/STOP BITS TIMING WAVEFORMS
FIGURE 29-18:
SCL
93
91
90
92
SDA
Stop
Condition
Start
Condition
Note:
TSU:STA
Characteristic
ns
ns
2(TOSC)(BRG + 1)
Setup Time
2(TOSC)(BRG + 1)
(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)
93
Units
Hold Time
92
Max.
Start Condition
1 MHz mode
91
Min.
2(TOSC)(BRG + 1)
1 MHz mode(1)
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
(1)
2(TOSC)(BRG + 1)
1 MHz mode
Conditions
ns
ns
FIGURE 29-19:
103
102
100
101
SCL
90
106
91
107
92
SDA
In
109
109
110
SDA
Out
Note:
DS30000684B-page 480
PIC18(L)F2X/45K50
TABLE 29-29: MASTER SSP I2C BUS DATA REQUIREMENTS
Param.
Symbol
No.
100
101
THIGH
TLOW
Characteristic
Min.
Max.
Units
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)
2(TOSC)(BRG + 1)
ms
1000
ns
20 + 0.1 CB
300
ns
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)
1 MHz mode
102
TR
(1)
1 MHz mode
103
90
91
TF
TSU:STA
Start Condition
Setup Time
2(TOSC)(BRG + 1)
ms
ns
0.9
ms
107
TSU:DAT
250
ns
92
1 MHz mode
106
Data Input
Setup Time
100
ns
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG + 1)
ms
(1)
2(TOSC)(BRG + 1)
ms
3500
ns
1000
ns
(1)
1 MHz mode
ns
4.7
ms
1.3
ms
400
pF
1 MHz mode
109
110
D102
Note 1:
2:
TAA
TBUF
CB
Output Valid
from Clock
Conditions
CB is specified to be
from 10 to 400 pF
CB is specified to be
from 10 to 400 pF
Note 2
I2C
DS30000684B-page 481
PIC18(L)F2X/45K50
FIGURE 29-20:
TX/CK
RX/DT
pin
121
121
pin
120
122
Note:
Symbol
120
Characteristic
Min.
Max.
Units
40
ns
Conditions
121
TCKRF
20
ns
Note 1
122
TDTRF
20
ns
Note 1
Note 1:
When the slew rate control limiting I/O port feature is disabled.
FIGURE 29-21:
TX/CK
RX/DT
pin
125
pin
126
Note:
Symbol
Characteristic
125
126
TCKL2DTL
DS30000684B-page 482
Min.
Max.
Units
10
ns
15
ns
Conditions
PIC18(L)F2X/45K50
TABLE 29-32: A/D CONVERTER CHARACTERISTICS (PIC18(L)F2X/45K50)(1)
Standard Operating Conditions (unless otherwise stated)
Operating temperature: Tested at +25C
PIC18(L)F2X/45K50
Param.
Symbol
No.
Characteristic
Min.
Typ.
Max.
Units
Conditions
A01
NR
Resolution
10
bits
VREF 3.0V
A03
EIL
0.5
LSb
VREF = 3.0V
A04
EDL
0.5
LSb
VREF 3.0V
A06
EOFF
Offset Error
0.7
LSb
VREF 3.0V
A07
EGN
Gain Error
0.7
LSb
VREF 3.0V
A08
ETOTL
Total Error
0.8
LSb
VREF 3.0V
A20
VREF
VDD
A21
VREFH
VDD/2
VDD + 0.3
A22
VREFL
VSS 0.3V
VDD/2
A25
VAIN
VREFL
VREFH
A30
ZAIN
Recommended Impedance of
Analog Voltage Source
10
Note 1:
The A/D conversion result never decreases with an increase in the input voltage and has no missing
codes.
FIGURE 29-22:
BSF ADCON0, GO
(Note 2)
131
Q4
A/D CLK
130
132
A/D DATA
.. .
...
OLD_DATA
ADRES
NEW_DATA
TCY
ADIF
GO
DONE
SAMPLING STOPPED
SAMPLE
Note 1:
2:
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.
This is a minimal RC delay (typically 100 ns), which also disconnects the holding capacitor from the analog input.
DS30000684B-page 483
PIC18(L)F2X/45K50
TABLE 29-33: A/D CONVERSION REQUIREMENTS (PIC18(L)F2X/45K50)
Standard Operating Conditions (unless otherwise stated)
Operating temperature: Tested at +25C
Param.
Symbol
No.
Characteristic
Min.
Typ.
Max.
Units
130
TAD
25
131
TCNV
Conversion Time
(not including acquisition time)(1)
12
12
TAD
132
TACQ
Acquisition Time(2)
1.4
135
TSWC
(Note 3)
136
TDIS
Discharge Time
TAD
Note 1:
2:
3:
Conditions
-40C to +85C
VDD = 3V, Rs = 50
DS30000684B-page 484
PIC18(L)F2X/45K50
30.0
DC AND AC
CHARACTERISTICS GRAPHS
AND CHARTS
DS30000684B-page 485
PIC18(L)F2X/45K50
31.0
PACKAGING INFORMATION
31.1
Example
PIC18F25K50
-E/SP e3
1407017
XXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX
YYWWNNN
Example
PIC18F25K50
-E/SO e3
1407017
Example
PIC18F25K50
-E/SS e3
1407017
Legend: XX...X
Y
YY
WW
NNN
e3
Note:
DS30000684B-page 486
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.
PIC18(L)F2X/45K50
Package Marking Information (Continued)
28-Lead QFN (6x6 mm)
PIN 1
XXXXXXXX
XXXXXXXX
YYWWNNN
Example
PIN 1
18F25K50
-E/ML e3
1407017
XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX
YYWWNNN
Example
PIC18F45K50
-E/P e3
1401017
PIN 1
Example
PIN 1
PIC18F
45K50
-E/MV e
1407017
3
Legend: XX...X
Y
YY
WW
NNN
e3
Note:
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.
DS30000684B-page 487
PIC18(L)F2X/45K50
Package Marking Information (Continued)
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
YYWWNNN
Legend: XX...X
Y
YY
WW
NNN
e3
Note:
DS30000684B-page 488
Example
18F45K50
-E/PT e3
1407017
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.
PIC18(L)F2X/45K50
31.2
Package Details
!"
3
&'
!&" &4# *!(!!&
4%&
&#&
&&255***'
'54
N
NOTE 1
E1
2 3
D
E
A2
b1
A1
eB
6&!
'!
9'&!
7"')
%!
7,8.
7
7:
;
<
&
&
&
##4
4!!
-
1!&
&
"# &
"# >#&
-
--
##4>#&
.
<
: 9&
-
-?
&
&
-
9# 4!!
<
)
<
1
6 9#>#&
9
* 9#>#&
:
*+
1,
-
!"
!"#$%&" ' ()"&'"!&)
&#*&&&#
+%&, & !&
- '!
!#.#
&"#'
#%!
& "!
!
#%!
& "!
!!
&$#/ !#
'!
#&
.0
1,2 1!'!
&$& "!
**&
"&&
!
* ,1
DS30000684B-page 489
PIC18(L)F2X/45K50
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
DS30000684B-page 490
PIC18(L)F2X/45K50
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
DS30000684B-page 491
PIC18(L)F2X/45K50
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
DS30000684B-page 492
PIC18(L)F2X/45K50
#$
%
&'
%
!"
3
&'
!&" &4# *!(!!&
4%&
&#&
&&255***'
'54
D
N
E
E1
1 2
NOTE 1
b
e
c
A2
A1
L1
6&!
'!
9'&!
7"')
%!
99.
.
7
7:
;
<
&
: 8&
?1,
=
##4
4!!
?
<
&#
%%
: >#&
<
<
##4>#&
.
-
?
: 9&
&9&
& &
9
.3
9# 4!!
&
@
@
<@
9#>#&
-<
!"
!"#$%&" ' ()"&'"!&)
&#*&&&#
'!
!#.#
&"#'
#%!
& "!
!
#%!
& "!
!!
&$#'' !#
- '!
#&
.0
1,2 1!'!
&$& "!
**&
"&&
!
.32 % '!
("!"*&
"&&
(%
%
'&
"
!!
* ,-1
DS30000684B-page 493
PIC18(L)F2X/45K50
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
DS30000684B-page 494
PIC18(L)F2X/45K50
DS30000684B-page 495
PIC18(L)F2X/45K50
3
&'
!&" &4# *!(!!&
4%&
&#&
&&255***'
'54
DS30000684B-page 496
PIC18(L)F2X/45K50
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
DS30000684B-page 497
PIC18(L)F2X/45K50
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
DS30000684B-page 498
PIC18(L)F2X/45K50
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
DS30000684B-page 499
PIC18(L)F2X/45K50
(( *#
+ ,- * ././. 0 ' *+,
!"
3
&'
!&" &4# *!(!!&
4%&
&#&
&&255***'
'54
D
D1
E
e
E1
N
b
NOTE 1
1 2 3
NOTE 2
A2
A1
L
L1
6&!
'!
9'&!
7"')
%9#!
99.
.
7
7:
;
9#&
: 8&
<1,
=
##4
4!!
&#
%%
&9&
?
& &
9
.3
&
: >#&
1,
: 9&
1,
##4>#&
.
1,
##49&
1,
@
-@
@
9# 4!!
9#>#&
-
-
# %&
@
@
-@
# %&1
&&
'
@
@
-@
!"
!"#$%&" ' ()"&'"!&)
&#*&&&#
,'% !&
!
&
V!W'
- '!
!#.#
&"#'
#%!
& "!
!
#%!
& "!
!!
&$#'' !#
'!
#&
.0
1,2 1!'!
&$& "!
**&
"&&
!
.32 % '!
("!"*&
"&&
(%
%
'&
"
!!
* ,?1
DS30000684B-page 500
PIC18(L)F2X/45K50
Note:
For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
DS30000684B-page 501
PIC18(L)F2X/45K50
NOTES:
DS30000684B-page 502
PIC18(L)F2X/45K50
APPENDIX A:
REVISION HISTORY
Revision A (08/2012)
Initial release.
Revision B (07/2014)
Updated Figures 2, 4 and 3-1; Updated Section 1.2
(Other Special Features), Section 2.4 (Voltage
Regulator Pins (VUSB3V3)) and Section 26.9.1
(Dedicated ICD/ICSP Port); Added note to
Section 24.4.1.1 (Buffer Ownership), Updated Tables
3-6 and 3-7; Updated Chapter 29.0 (Electrical
Specifications), Chapter 31 (Packaging Information)
and the Product Identification System page; Other
minor corrections.
DS30000684B-page 503
PIC18(L)F2X/45K50
APPENDIX B:
DEVICE
DIFFERENCES
TABLE B-1:
DEVICE DIFFERENCES
Features
PIC18F24K50
PIC18LF24K50
PIC18F25K50
PIC18LF25K50
PIC18F45K50
PIC18LF45K50
16384
16384
32768
32768
32768
32768
VDD Range
2.3V to 5.5V
1.8V to 3.6V
2.3V to 5.5V
1.8V to 3.6V
2.3V to 5.5V
1.8V to 3.6V
I/O Ports
Ports A, B, C,
(E)
10-Bit Analog-to-Digital
Module
Packages
DS30000684B-page 504
14 input
channels
14 input
channels
14 input
channels
14 input
channels
25 input
channels
25 input
channels
28-pin SPDIP
28-pin SOIC
28-pin SSOP
28-pin QFN
28-pin SPDIP
28-pin SOIC
28-pin SSOP
28-pin QFN
28-pin SPDIP
28-pin SOIC
28-pin SSOP
28-pin QFN
28-pin SPDIP
28-pin SOIC
28-pin SSOP
28-pin QFN
40-pin PDIP
40-pin UQFN
44-pin TQFP
40-pin PDIP
40-pin UQFN
44-pin TQFP
PIC18(L)F2X/45K50
THE MICROCHIP WEB SITE
CUSTOMER SUPPORT
Distributor or Representative
Local Sales Office
Field Application Engineer (FAE)
Technical Support
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://microchip.com/support
DS30000684B-page 505
PIC18(L)F2X/45K50
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.
Device
Device:
[X](2)
/XX
XXX
Temperature
Range
Package
Pattern
Temperature
Range:
I
E
Package:
ML
MV
P
PT
SO
SP
SS
Pattern:
b)
d)
=
=
=
=
=
=
=
a)
c)
PIC18F45K50, PIC18LF45K50
PIC18F25K50, PIC18LF25K50
PIC18F24K50, PIC18LF24K50
= -40C to +85C
= -40C to +125C
Examples:
PIC18F45K50-E/P 301 = Extended temp.,
PDIP package, QTP pattern #301.
PIC18LF25K50-E/SO = Extended temp., SOIC
package.
PIC18F45K50-E/P = Extended temp., PDIP
package.
PIC18F24K50T-E/ML = Tape and reel,
Extended temp., QFN package.
(Industrial)
(Extended)
QFN
UQFN
PDIP
TQFP (Thin Quad Flatpack)
SOIC
Skinny Plastic DIP
SSOP
Note 1:
2:
DS30000684B-page 506
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, dsPIC,
FlashFlex, flexPWR, JukeBlox, KEELOQ, KEELOQ logo, Kleer,
LANCheck, MediaLB, MOST, MOST logo, MPLAB,
OptoLyzer, PIC, PICSTART, PIC32 logo, RightTouch, SpyNIC,
SST, SST Logo, SuperFlash and UNI/O are registered
trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
The Embedded Control Solutions Company and mTouch are
registered trademarks of Microchip Technology Incorporated
in the U.S.A.
Analog-for-the-Digital Age, BodyCom, chipKIT, chipKIT logo,
CodeGuard, dsPICDEM, dsPICDEM.net, ECAN, In-Circuit
Serial Programming, ICSP, Inter-Chip Connectivity, KleerNet,
KleerNet logo, MiWi, MPASM, MPF, MPLAB Certified logo,
MPLIB, MPLINK, MultiTRAK, NetDetach, Omniscient Code
Generation, PICDEM, PICDEM.net, PICkit, PICtail,
RightTouch logo, REAL ICE, SQI, Serial Quad I/O, Total
Endurance, TSHARC, USBCheck, VariSense, ViewSpan,
WiperLock, Wireless DNA, 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.
Silicon Storage Technology is a registered trademark of
Microchip Technology Inc. in other countries.
GestIC is a registered trademarks of Microchip Technology
Germany II GmbH & Co. KG, a subsidiary of Microchip
Technology Inc., in other countries.
All other trademarks mentioned herein are property of their
respective companies.
2012-2014, Microchip Technology Incorporated, Printed in
the U.S.A., All Rights Reserved.
ISBN: 978-1-63276-360-0
== ISO/TS 16949 ==
2012-2014 Microchip Technology Inc.
DS30000684B-page 507
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://www.microchip.com/
support
Web Address:
www.microchip.com
India - Bangalore
Tel: 91-80-3090-4444
Fax: 91-80-3090-4123
Austria - Wels
Tel: 43-7242-2244-39
Fax: 43-7242-2244-393
Denmark - Copenhagen
Tel: 45-4450-2828
Fax: 45-4485-2829
Australia - Sydney
Tel: 61-2-9868-6733
Fax: 61-2-9868-6755
Atlanta
Duluth, GA
Tel: 678-957-9614
Fax: 678-957-1455
China - Beijing
Tel: 86-10-8569-7000
Fax: 86-10-8528-2104
Austin, TX
Tel: 512-257-3370
China - Chengdu
Tel: 86-28-8665-5511
Fax: 86-28-8665-7889
Boston
Westborough, MA
Tel: 774-760-0087
Fax: 774-760-0088
Chicago
Itasca, IL
Tel: 630-285-0071
Fax: 630-285-0075
Cleveland
Independence, OH
Tel: 216-447-0464
Fax: 216-447-0643
Dallas
Addison, TX
Tel: 972-818-7423
Fax: 972-818-2924
Detroit
Novi, MI
Tel: 248-848-4000
Houston, TX
Tel: 281-894-5983
Indianapolis
Noblesville, IN
Tel: 317-773-8323
Fax: 317-773-5453
Los Angeles
Mission Viejo, CA
Tel: 949-462-9523
Fax: 949-462-9608
New York, NY
Tel: 631-435-6000
San Jose, CA
Tel: 408-735-9110
Canada - Toronto
Tel: 905-673-0699
Fax: 905-673-6509
DS30000684B-page 508
China - Chongqing
Tel: 86-23-8980-9588
Fax: 86-23-8980-9500
China - Hangzhou
Tel: 86-571-8792-8115
Fax: 86-571-8792-8116
China - Hong Kong SAR
Tel: 852-2943-5100
Fax: 852-2401-3431
China - Nanjing
Tel: 86-25-8473-2460
Fax: 86-25-8473-2470
China - Qingdao
Tel: 86-532-8502-7355
Fax: 86-532-8502-7205
China - Shanghai
Tel: 86-21-5407-5533
Fax: 86-21-5407-5066
China - Shenyang
Tel: 86-24-2334-2829
Fax: 86-24-2334-2393
China - Shenzhen
Tel: 86-755-8864-2200
Fax: 86-755-8203-1760
China - Wuhan
Tel: 86-27-5980-5300
Fax: 86-27-5980-5118
China - Xian
Tel: 86-29-8833-7252
Fax: 86-29-8833-7256
France - Paris
Tel: 33-1-69-53-63-20
Fax: 33-1-69-30-90-79
India - Pune
Tel: 91-20-3019-1500
Japan - Osaka
Tel: 81-6-6152-7160
Fax: 81-6-6152-9310
Germany - Dusseldorf
Tel: 49-2129-3766400
Germany - Munich
Tel: 49-89-627-144-0
Fax: 49-89-627-144-44
Japan - Tokyo
Tel: 81-3-6880- 3770
Fax: 81-3-6880-3771
Germany - Pforzheim
Tel: 49-7231-424750
Korea - Daegu
Tel: 82-53-744-4301
Fax: 82-53-744-4302
Italy - Milan
Tel: 39-0331-742611
Fax: 39-0331-466781
Korea - Seoul
Tel: 82-2-554-7200
Fax: 82-2-558-5932 or
82-2-558-5934
Italy - Venice
Tel: 39-049-7625286
Netherlands - Drunen
Tel: 31-416-690399
Fax: 31-416-690340
Malaysia - Penang
Tel: 60-4-227-8870
Fax: 60-4-227-4068
Poland - Warsaw
Tel: 48-22-3325737
Philippines - Manila
Tel: 63-2-634-9065
Fax: 63-2-634-9069
Singapore
Tel: 65-6334-8870
Fax: 65-6334-8850
Taiwan - Hsin Chu
Tel: 886-3-5778-366
Fax: 886-3-5770-955
Spain - Madrid
Tel: 34-91-708-08-90
Fax: 34-91-708-08-91
Sweden - Stockholm
Tel: 46-8-5090-4654
UK - Wokingham
Tel: 44-118-921-5800
Fax: 44-118-921-5820
Taiwan - Kaohsiung
Tel: 886-7-213-7830
Taiwan - Taipei
Tel: 886-2-2508-8600
Fax: 886-2-2508-0102
Thailand - Bangkok
Tel: 66-2-694-1351
Fax: 66-2-694-1350
China - Xiamen
Tel: 86-592-2388138
Fax: 86-592-2388130
China - Zhuhai
Tel: 86-756-3210040
Fax: 86-756-3210049
03/25/14