PIC18F2x20 4x20
PIC18F2x20 4x20
PIC18F2x20 4x20
Data Sheet
28/40/44-Pin High-Performance,
Enhanced Flash Microcontrollers
with 10-Bit A/D and nanoWatt Technology
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip's Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break microchip’s code protection feature may be a violation of the 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.
PDIP
MCLR/VPP/RE3 1 40 RB7/KBI3/PGD
RA0/AN0 2 39 RB6/KBI2/PGC
RA1/AN1 3 38 RB5/KBI1/PGM
RA2/AN2/VREF-/CVREF 4 37 RB4/AN11/KBI0
RA3/AN3/VREF+ 5 36 RB3/AN9/CCP2*
RA4/T0CKI/C1OUT 6 35 RB2/AN8/INT2
RA5/AN4/SS/LVDIN/C2OUT 7 34 RB1/AN10/INT1
PIC18F4220
PIC18F4320
RE0/AN5/RD 8 33 RB0/AN12/INT0
RE1/AN6/WR 9 32 VDD
RE2/AN7/CS 10 31 VSS
VDD 11 30 RD7/PSP7/P1D
VSS 12 29 RD6/PSP6/P1C
OSC1/CLKI/RA7 13 28 RD5/PSP5/P1B
OSC2/CLKO/RA6 14 27 RD4/PSP4
RC0/T1OSO/T1CKI 15 26 RC7/RX/DT
RC1/T1OSI/CCP2* 16 25 RC6/TX/CK
RC2/CCP1/P1A 17 24 RC5/SDO
RC3/SCK/SCL 18 23 RC4/SDI/SDA
RD0/PSP0 19 22 RD3/PSP3
RD1/PSP1 20 21 RD2/PSP2
SPDIP, SOIC
MCLR/VPP/RE3 1 28 RB7/KBI3/PGD
RA0/AN0 2 27 RB6//KBI2/PGC
RA1/AN1 3 26 RB5/KBI1/PGM
RA2/AN2/VREF-/CVREF 4 25 RB4/AN11/KBI0
RB3/AN9/CCP2*
PIC18F2220
PIC18F2320
RA3/AN3/VREF+ 5 24
RA4/T0CKI/C1OUT 6 23 RB2/AN8/INT2
RA5/AN4/SS/LVDIN/C2OUT 7 22 RB1/AN10/INT1
VSS 8 21 RB0/AN12/INT0
OSC1/CLKI/RA7 9 20 VDD
OSC2/CLKO/RA6 10 19 VSS
RC0/T1OSO/T1CKI 11 18 RC7/RX/DT
RC1/T1OSI/CCP2* 12 17 RC6/TX/CK
RC2/CCP1/P1A 13 16 RC5/SDO
RC3/SCK/SCL 14 15 RC4/SDI/SDA
RC1/T1OSI/CCP2*
TQFP
RC2/CCP1/P1A
RC3/SCK/SCL
RC4/SDI/SDA
RC6/TX/CK
RD3/PSP3
RD2/PSP2
RD1/PSP1
RD0/PSP0
RC5/SDO
NC
44
43
42
41
40
39
38
37
36
35
34
RC7/RX/DT 1 33 NC
RD4/PSP4 2 32 RC0/T1OSO/T1CKI
RD5/PSP5/P1B 3 31 OSC2/CLKO/RA6
RD6/PSP6/P1C 4 30 OSC1/CLKI/RA7
RD7/PSP7/P1D 5 PIC18F4220 29 VSS
VSS 6 28 VDD
VDD 7
PIC18F4320 27 RE2/AN7/CS
RB0/AN12/INT0 8 26 RE1/AN6/WR
RB1/AN10/INT1 9 25 RE0/AN5/RD
RB2/AN8/INT2 10 24 RA5/AN4/SS/LVDIN/C2OUT
RB3/AN9/CCP2* 11 12 23 RA4/T0CKI/C1OUT
13
14
15
16
17
18
19
20
21
22
NC
NC
RB6/KBI2/PGC
RB7/KBI3/PGD
RA3/AN3/VREF+
RB4/AN11/KBI0
RB5/KBI1/PGM
MCLR/VPP/RE3
RA0/AN0
RA1/AN1
RA2/AN2/VREF-/CVREF
QFN
RC2/CCP1/P1A
RC3/SCK/SCL
RC4/SDI/SDA
RC6/TX/CK
RD3/PSP3
RD2/PSP2
RD1/PSP1
RD0/PSP0
RC5/SDO
44
43
42
41
40
39
38
37
36
35
34
RC7/RX/DT 1 33 OSC2/CLKO/RA6
RD4/PSP4 2 32 OSC1/CLKI/RA7
RD5/PSP5/P1B 3 31 VSS
RD6/PSP6/P1C 4 30 VSS
RD7/PSP7/P1D 5 PIC18F4220 29 VDD
VSS 6 28 NC
VDD 7
PIC18F4320 27 RE2/AN7/CS
VDD 8 26 RE1/AN6/WR
RB0/AN12/INT0 9 25 RE0/AN5/RD
RB1/AN10/INT1 10 24 RA5/AN4/SS/LVDIN/C2OUT
RB2/AN8/INT2 11 23 RA4/T0CKI/C1OUT
12
13
14
15
16
17
18
19
20
21
22
NC
RB6/KBI2/PGC
RB7/KBI3/PGD
RA3/AN3/VREF+
RB3/AN9/CCP2*
RB4/AN11/KBI0
RB5/KBI1/PGM
MCLR/VPP/RE3
RA0/AN0
RA1/AN1
RA2/AN2/VREF-/CVREF
Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for current
devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revision
of silicon and revision of document to which it applies.
To determine if an errata sheet exists for a particular device, please check with one of the following:
• Microchip’s Worldwide Web site; http://www.microchip.com
• Your local Microchip sales office (see last page)
• The Microchip Corporate Literature Center; U.S. FAX: (480) 792-7277
When contacting a sales office or the literature center, please specify which device, revision of silicon and data sheet (include
literature number) you are using.
PORTA
21 Table Pointer <2> Data Latch
8 8 8 8 RA0/AN0
Data RAM RA1/AN1
21 inc/dec logic (512 Bytes) RA2/AN2/VREF-/CVREF
RA3/AN3/VREF+
21 Address Latch RA4/T0CKI/C1OUT
20 PCLATU PCLATH RA5/AN4/SS/LVDIN/C2OUT
Address Latch 12(2)
OSC2/CLKO/RA6(3)
Program Memory Address<12> OSC1/CLKI/RA7(3)
(4 Kbytes) PCU PCH PCL
Program Counter 4 12 4
Data Latch PORTB
BSR FSR0 Bank0, F
RB0/AN12/INT0
31 Level Stack FSR1
RB1/AN10/INT1
FSR2
12 RB2/AN8/INT2
RB3/AN9/CCP2(1)
16 inc/dec RB4/AN11/KBI0
Decode logic RB5/KBI1/PGM
Table Latch
RB6/KBI2/PGC
RB7/KBI3/PGD
8
ROM Latch PORTC
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2(1)
Instruction RC2/CCP1/P1A
Register
RC3/SCK/SCL
8 RC4/SDI/SDA
Instruction RC5/SDO
Decode &
Control RC6/TX/CK
PRODH PRODL RC7/RX/DT
3
8 x 8 Multiply
8
BIT OP WREG
OSC1(3) Internal Power-up 8
8 8
Oscillator Timer
OSC2(3) Block Oscillator
Start-up Timer 8
T1OSI INT RC Power-on ALU<8>
Oscillator Reset
T1OSO PORTE
Watchdog 8
Timer
Precision RE3(2)
Low-Voltage Brown-out
Voltage
Programming Reset Reference
MCLR(2)
In-Circuit Fail-Safe
Debugger Clock Monitor
VDD, VSS
Note 1: Optional multiplexing of CCP2 input/output with RB3 is enabled by selection of the CCPMX2 configuration bit.
2: RE3 is available only when the MCLR Resets are disabled.
3: OSC1, OSC2, CLKI and CLKO are only available in select oscillator modes and when these pins are not being used as digital I/O.
Refer to Section 2.0 “Oscillator Configurations” for additional information.
PORTA
21 Table Pointer <2> Data Latch RA0/AN0
8 8 8 8 RA1/AN1
Data RAM RA2/AN2/VREF-/CVREF
21 inc/dec logic (512 Bytes) RA3/AN3/VREF+
21 RA4/T0CKI/C1OUT
Address Latch
RA5/AN4/SS/LVDIN/C2OUT
20 PCLATU PCLATH OSC2/CLKO/RA6(3)
Address Latch 12(2)
OSC1/CLKI/RA7(3)
Program Memory Address<12>
(8 Kbytes) PCU PCH PCL
Program Counter 4 12 4
Data Latch PORTB
BSR FSR0 Bank0, F
RB0/AN12/INT0
31 Level Stack FSR1
RB1/AN10/INT1
FSR2 RB2/AN8/INT2
12
RB3/AN9/CCP2(1)
16 inc/dec RB4/AN11/KBI0
Decode logic RB5/KBI1/PGM
Table Latch RB6/KBI2/PGC
RB7/KBI3/PGD
8
ROM Latch
PORTC
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2(1)
Instruction
Register RC2/CCP1/P1A
RC3/SCK/SCL
8 RC4/SDI/SDA
Instruction RC5/SDO
Decode &
Control RC6/TX/CK
PRODH PRODL RC7/RX/DT
3
8 x 8 Multiply
8 PORTD
RD0/PSP0
BIT OP WREG RD1/PSP1
OSC1(3) Internal Power-up 8
Oscillator 8 8 RD2/PSP2
Timer RD3/PSP3
Block
OSC2(3) Oscillator RD4/PSP4
8
Start-up Timer RD5/PSP5/P1B
T1OSI INT RC RD6/PSP6/P1C
Oscillator Power-on ALU<8>
Reset RD7/PSP7/P1D
T1OSO
Watchdog 8
Timer PORTE
Precision RE0/AN5/RD
Low-Voltage Brown-out
Voltage
Programming Reset Reference RE1/AN6/WR
MCLR(2)
In-Circuit Fail-Safe RE2/AN7/CS
Clock Monitor
VDD, VSS
Debugger RE3(2)
Master Addressable
Enhanced Data EEPROM
CCP2 Synchronous USART
CCP (256 Bytes)
Serial Port
Note 1: Optional multiplexing of CCP2 input/output with RB3 is enabled by selection of the CCP2MX configuration bit.
2: RE3 is available only when the MCLR Resets are disabled.
3: OSC1, OSC2, CLKI and CLKO are only available in select oscillator modes and when these pins are not being used as digital I/O.
Refer to Section 2.0 “Oscillator Configurations” for additional information.
REXT
Internal
OSC1
Clock
CEXT
PIC18FXXXX
VSS
RA6 I/O (OSC2)
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Primary Oscillator
PIC18F2X20/4X20 CONFIG1H <3:0>
Clock
OSCCON<1:0>
Control
OSC2
HSPLL
4 x PLL
Sleep
LP, XT, HS, RC, EC
OSC1
Secondary Oscillator Peripherals
T1OSC
MUX
T1OSO
Clock Source Option
T1OSCEN
Enable for Other Modules
T1OSI Oscillator OSCCON<6:4> Internal Oscillator
Postscaler
1 MHz
MUX
100
500 kHz
8 MHz 011
INTRC (INTOSC) 250 kHz
Source 010
125 kHz
001
31 kHz
000
WDT, FSCM
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
3.2 Sleep Mode There is one exception to how the IDLEN bit functions.
When all the low-power OSCCON bits are cleared
The power managed Sleep mode in the PIC18F2X20/ (IDLEN:SCS1:SCS0 = 000), the device enters Sleep
4X20 devices is identical to that offered in all other mode upon the execution of the SLEEP instruction. This
PICmicro controllers. It is entered by clearing the is both the Reset state of the OSCCON register and the
IDLEN and SCS1:SCS0 bits (this is the Reset state) setting that selects Sleep mode. This maintains com-
and executing the SLEEP instruction. This shuts down patibility with other PICmicro devices that do not offer
the primary oscillator and the OSTS bit is cleared (see power managed modes.
Figure 3-1).
If the Idle Enable bit, IDLEN (OSCCON<7>), is set to a
When a wake event occurs in Sleep mode (by interrupt, ‘1’ when a SLEEP instruction is executed, the
Reset or WDT time-out), the system will not be clocked peripherals will be clocked from the clock source
until the primary clock source becomes ready (see selected using the SCS1:SCS0 bits; however, the CPU
Figure 3-2), or it will be clocked from the internal will not be clocked. Since the CPU is not executing
oscillator block if either the Two-Speed Start-up or the instructions, the only exits from any of the Idle modes
Fail-Safe Clock Monitor are enabled (see Section 23.0 are by interrupt, WDT time-out or a Reset.
“Special Features of the CPU”). In either case, the
OSTS bit is set when the primary clock is providing the When a wake-up event occurs, CPU execution is
system clocks. The IDLEN and SCS bits are not delayed approximately 10 µs while it becomes ready to
affected by the wake-up. execute code. When the CPU begins executing code,
it is clocked by the same clock source as was selected
in the power managed mode (i.e., when waking from
3.3 Idle Modes RC_IDLE mode, the internal oscillator block will clock
The IDLEN bit allows the controller’s CPU to be the CPU and peripherals until the primary clock source
selectively shut down while the peripherals continue to becomes ready – this is essentially RC_RUN mode).
operate. Clearing IDLEN allows the CPU to be clocked. This continues until the primary clock source becomes
Setting IDLEN disables clocks to the CPU, effectively ready. When the primary clock becomes ready, the
stopping program execution (see Register 2-2). The OSTS bit is set and the system clock source is
peripherals continue to be clocked regardless of the switched to the primary clock (see Figure 3-4). The
setting of the IDLEN bit. IDLEN and SCS bits are not affected by the wake-up.
While in any Idle mode or the Sleep mode, a WDT time-out
will result in a WDT wake-up to full power operation.
Q1 Q2 Q3 Q4 Q1
OSC1
CPU
Clock
Peripheral
Clock
Sleep
Program
Counter PC PC + 2
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
OSC1
TOST(1) TPLL(1)
PLL Clock
Output
CPU Clock
Peripheral
Clock
Program
PC PC + 2 PC + 4 PC + 6 PC + 8
Counter
Note 1: TOST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
Q1 Q2 Q3 Q4 Q1
OSC1
CPU Clock
Peripheral
Clock
Program
PC PC + 2
Counter
Q1 Q2 Q3 Q4
OSC1
Peripheral
Clock
Program
PC PC + 2
Counter
Wake-up Event
Q1 Q2 Q3 Q4 Q1
T1OSI 1 2 3 4 5 6 7 8
Clock Transition
OSC1
CPU
Clock
Peripheral
Clock
Program
Counter PC PC + 2
FIGURE 3-6: TIMING TRANSITION FOR WAKE FROM SEC_RUN MODE (HSPLL)
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3
T1OSI
OSC1
TOST(1) TPLL(1)
PLL Clock
Output 1 2 3 4 5 6 7 8
Clock Transition
CPU Clock
Peripheral
Clock
Program
PC PC + 2 PC + 4 PC + 6
Counter
Note 1: TOST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
INTRC 1 2 3 4 5 6 7 8
Clock Transition
OSC1
CPU
Clock
Peripheral
Clock
Program
Counter PC PC + 2
FIGURE 3-8: TIMING TRANSITION FOR WAKE FROM RC_RUN MODE (RC_RUN TO PRI_RUN)
Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3
INTOSC
Multiplexer
OSC1
TOST(1) TPLL(1)
PLL Clock
Output 1 2 3 4 5 6 7 8
Clock Transition
CPU Clock
Peripheral
Clock
Program
PC PC + 2 PC + 4 PC + 6
Counter
Note 1: TOST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3
T1OSI 1 2 3 4 5 6 7 8
Clock Transition
OSC1
CPU
Clock
Peripheral
Clock
Program
Counter PC PC + 2 PC + 2
INTRC 1 2 3 4 5 6 7 8
Clock Transition
OSC1
CPU
Clock
Peripheral
Clock
Program
Counter PC PC + 2 PC + 4
External Reset
MCLRE
MCLR
( )_IDLE
Sleep
WDT
Time-out
OST/PWRT
OST 1024 Cycles
Chip_Reset
10-bit Ripple Counter R Q
OSC1
32 µs PWRT 65.5 ms
INTRC(1) 11-bit Ripple Counter
Enable PWRT
Enable OST(2)
Note 1: This is the INTRC source from the internal oscillator block and is separate from the RC oscillator of the CLKI pin.
2: See Table 4-1 for time-out situations.
TABLE 4-2: STATUS BITS, THEIR SIGNIFICANCE AND THE INITIALIZATION CONDITION FOR
RCON REGISTER
Program RCON
Condition RI TO PD POR BOR STKFUL STKUNF
Counter Register
Power-on Reset 0000h 0--1 1100 1 1 1 0 0 0 0
RESET Instruction 0000h 0--0 uuuu 0 u u u u u u
Brown-out 0000h 0--1 11u- 1 1 1 u 0 u u
MCLR during power managed
0000h 0--u 1uuu u 1 u u u u u
Run modes
MCLR during power managed
0000h 0--u 10uu u 1 0 u u u u
Idle modes and Sleep mode
WDT Time-out during full power
0000h 0--u 0uuu u 0 u u u u u
or power managed Run mode
MCLR during full power
u u
execution
Stack Full Reset (STVREN = 1) 0000h 0--u uuuu u u u u u 1 u
Stack Underflow Reset
u 1
(STVREN = 1)
Stack Underflow Error (not an
0000h u--u uuuu u u u u u u 1
actual Reset, STVREN = 0)
WDT Time-out during power
PC + 2 u--u 00uu u 0 0 u u u u
managed Idle or Sleep modes
Interrupt exit from power
PC + 2 u--u u0uu u u 0 u u u u
managed modes
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’
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 (0x000008h or 0x000018h).
TOSU 2220 2320 4220 4320 ---0 0000 ---0 0000 ---0 uuuu(3)
TOSH 2220 2320 4220 4320 0000 0000 0000 0000 uuuu uuuu(3)
TOSL 2220 2320 4220 4320 0000 0000 0000 0000 uuuu uuuu(3)
STKPTR 2220 2320 4220 4320 uu-0 0000 00-0 0000 uu-u uuuu(3)
PCLATU 2220 2320 4220 4320 ---0 0000 ---0 0000 ---u uuuu
PCLATH 2220 2320 4220 4320 0000 0000 0000 0000 uuuu uuuu
PCL 2220 2320 4220 4320 0000 0000 0000 0000 PC + 2(2)
TBLPTRU 2220 2320 4220 4320 --00 0000 --00 0000 --uu uuuu
TBLPTRH 2220 2320 4220 4320 0000 0000 0000 0000 uuuu uuuu
TBLPTRL 2220 2320 4220 4320 0000 0000 0000 0000 uuuu uuuu
TABLAT 2220 2320 4220 4320 0000 0000 0000 0000 uuuu uuuu
PRODH 2220 2320 4220 4320 xxxx xxxx uuuu uuuu uuuu uuuu
PRODL 2220 2320 4220 4320 xxxx xxxx uuuu uuuu uuuu uuuu
INTCON 2220 2320 4220 4320 0000 000x 0000 000u uuuu uuuu(1)
INTCON2 2220 2320 4220 4320 1111 -1-1 1111 -1-1 uuuu -u-u(1)
INTCON3 2220 2320 4220 4320 11-0 0-00 11-0 0-00 uu-u u-uu(1)
INDF0 2220 2320 4220 4320 N/A N/A N/A
POSTINC0 2220 2320 4220 4320 N/A N/A N/A
POSTDEC0 2220 2320 4220 4320 N/A N/A N/A
PREINC0 2220 2320 4220 4320 N/A N/A N/A
PLUSW0 2220 2320 4220 4320 N/A N/A N/A
FSR0H 2220 2320 4220 4320 ---- xxxx ---- uuuu ---- uuuu
FSR0L 2220 2320 4220 4320 xxxx xxxx uuuu uuuu uuuu uuuu
WREG 2220 2320 4220 4320 xxxx xxxx uuuu uuuu uuuu uuuu
INDF1 2220 2320 4220 4320 N/A N/A N/A
POSTINC1 2220 2320 4220 4320 N/A N/A N/A
POSTDEC1 2220 2320 4220 4320 N/A N/A N/A
PREINC1 2220 2320 4220 4320 N/A N/A N/A
PLUSW1 2220 2320 4220 4320 N/A N/A N/A
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition.
Shaded cells indicate conditions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the
interrupt vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 4-2 for Reset value for specific condition.
5: Bits 6 and 7 of PORTA, LATA and TRISA are enabled, depending on the oscillator mode selected. When
not enabled as PORTA pins, they are disabled and read ‘0’.
VDD
MCLR
Internal POR
TPWRT
OST Time-out
Internal Reset
FIGURE 4-4: TIME-OUT SEQUENCE ON POWER-UP (MCLR NOT TIED TO VDD): CASE 1
VDD
MCLR
Internal POR
TPWRT
OST Time-out
Internal Reset
FIGURE 4-5: TIME-OUT SEQUENCE ON POWER-UP (MCLR NOT TIED TO VDD): CASE 2
VDD
MCLR
Internal POR
TPWRT
OST Time-out
Internal Reset
MCLR
Internal POR
TPWRT
PWRT Time-out
TOST
OST Time-out
Internal Reset
FIGURE 4-7: TIME-OUT SEQUENCE ON POR W/ PLL ENABLED (MCLR TIED TO VDD)
VDD
MCLR
Internal POR
TPWRT
PLL Time-out
Internal Reset
FIGURE 5-1: PROGRAM MEMORY MAP FIGURE 5-2: PROGRAM MEMORY MAP
AND STACK FOR AND STACK FOR
PIC18F2220/4220 PIC18F2320/4320
PC<20:0> PC<20:0>
CALL,RCALL,RETURN 21 CALL,RCALL,RETURN 21
RETFIE,RETLW RETFIE,RETLW
Stack Level 1 Stack Level 1
• •
• •
• •
High Priority Interrupt Vector 0008h High Priority Interrupt Vector 0008h
Low Priority Interrupt Vector 0018h Low Priority Interrupt Vector 0018h
On-Chip
Program Memory On-Chip
0FFFh
1000h Program Memory
1FFFh
User Memory Space
2000h
1FFFFFh 1FFFFFh
200000h 200000h
5.2.1 TOP-OF-STACK ACCESS When the stack has been popped enough times to
unload the stack, the next pop will return a value of zero
The top of the stack is readable and writable. Three to the PC and sets the STKUNF bit, while the stack
register locations, TOSU, TOSH and TOSL, hold the pointer remains at zero. The STKUNF bit will remain
contents of the stack location pointed to by the set until cleared by software or a POR occurs.
STKPTR register (Figure 5-3). This allows users to
implement a software stack if necessary. After a CALL, Note: Returning a value of zero to the PC on an
RCALL or interrupt, the software can read the pushed underflow has the effect of vectoring the
value by reading the TOSU, TOSH and TOSL registers. program to the Reset vector, where the
These values can be placed on a user defined software stack conditions can be verified and
stack. At return time, the software can replace the appropriate actions can be taken. This is
TOSU, TOSH and TOSL and do a return. not the same as a Reset, as the contents
of the SFRs are not affected.
The user must disable the global interrupt enable bits
while accessing the stack to prevent inadvertent stack
corruption.
Legend:
R = Readable bit W = Writable bit U = Unimplemented C = Clearable only bit
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
SUB1 •
•
RETURN FAST ;RESTORE VALUES SAVED
;IN FAST REGISTER STACK
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
OSC1
Q1
Q2 Internal
Phase
Q3 Clock
Q4
PC PC PC+2 PC+4
OSC2/CLKO
(RC mode)
Execute INST (PC-2)
Fetch INST (PC) Execute INST (PC)
Fetch INST (PC+2) Execute INST (PC+2)
Fetch INST (PC+4)
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.
5.7.1 TWO-WORD INSTRUCTIONS second word of the instruction is executed by itself (first
word was skipped), it will execute as a NOP. This action
PIC18F2X20/4X20 devices have four two-word instruc-
is necessary when the two-word instruction is preceded
tions: MOVFF, CALL, GOTO and LFSR. The second
by a conditional instruction that results in a skip opera-
word of these instructions has the 4 MSBs set to ‘1’s
tion. A program example that demonstrates this con-
and is decoded as a NOP instruction. The lower 12 bits
cept is shown in Example 5-3. Refer to Section 24.0
of the second word contain data to be used by the
“Instruction Set Summary” for further details of the
instruction. If the first word of the instruction is exe-
instruction set.
cuted, the data in the second word is accessed. If the
CASE 2:
Object Code Source Code
0110 0110 0000 0000 TSTFSZ REG1 ; is RAM location 0?
1100 0001 0010 0011 MOVFF REG1, REG2 ; Yes, execute this word
1111 0100 0101 0110 ; 2nd word of instruction
0010 0100 0000 0000 ADDWF REG3 ; continue code
00h 000h
= 0000 Access RAM 07Fh
Bank 0 080h
FFh GPR
0FFh
00h 100h
= 0001 GPR
Bank 1
FFh 1FFh
200h
Access Bank
00h
Access RAM Low
7Fh
= 0010 Access RAM High 80h
Bank 2 Unused
to (SFRs)
= 1110 Read ‘00h’ FFh
Bank 14
When a = 0:
The BSR is ignored and the
Access Bank is used.
The first 128 bytes are
general purpose RAM
EFFh
F00h (from Bank 0).
00h Unused
= 1111 F7Fh
Bank 15 The second 128 bytes are
SFR F80h
FFh FFFh Special Function Registers
(from Bank 15).
When a = 1:
The BSR specifies the bank
used by the instruction.
OSCCON IDLEN IRCF2 IRCF1 IRCF0 OSTS IOFS SCS1 SCS0 0000 q000 26, 47
LVDCON — — IRVST LVDEN LVDL3 LVDL2 LVDL1 LVDL0 --00 0101 47, 233
WDTCON — — — — — — — SWDTEN --- ---0 47, 246
RCON IPEN — — RI TO PD POR BOR 0--1 11q0 45, 69, 98
TMR1H Timer1 Register High Byte xxxx xxxx 47, 125
TMR1L Timer1 Register Low Byte xxxx xxxx 47, 125
T1CON RD16 T1RUN T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON 0000 0000 47, 121
TMR2 Timer2 Register 0000 0000 47, 127
PR2 Timer2 Period Register 1111 1111 47, 127
T2CON — TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 TMR2ON T2CKPS1 T2CKPS0 -000 0000 47, 127
SSPBUF SSP Receive Buffer/Transmit Register xxxx xxxx 47, 156,
164
SSPADD SSP Address Register in I2C Slave mode. SSP Baud Rate Reload Register in I2C Master mode. 0000 0000 47, 164
SSPSTAT SMP CKE D/A P S R/W UA BF 0000 0000 47, 156,
165
SSPCON1 WCOL SSPOV SSPEN CKP SSPM3 SSPM2 SSPM1 SSPM0 0000 0000 47, 157,
166
SSPCON2 GCEN ACKSTAT ACKDT ACKEN RCEN PEN RSEN SEN 0000 0000 47, 167
ADRESH A/D Result Register High Byte xxxx xxxx 48, 220
ADRESL A/D Result Register Low Byte xxxx xxxx 48, 220
ADCON0 — — CHS3 CHS2 CHS1 CHS0 GO/DONE ADON --00 0000 48, 211
ADCON1 — — VCFG1 VCFG0 PCFG3 PCFG2 PCFG1 PCFG0 --00 0000 48, 212
ADCON2 ADFM — ACQT2 ACQT1 ACQT0 ADCS2 ADCS1 ADCS0 0-00 0000 48, 213
CCPR1H Capture/Compare/PWM Register 1 High Byte xxxx xxxx 48, 134
CCPR1L Capture/Compare/PWM Register 1 Low Byte xxxx xxxx 48, 134
CCP1CON P1M1(5) P1M0(5) DC1B1 DC1B0 CCP1M3 CCP1M2 CCP1M1 CCP1M0 0000 0000 48, 133,
141
CCPR2H Capture/Compare/PWM Register 2 High Byte xxxx xxxx 48, 134
CCPR2L Capture/Compare/PWM Register 2 Low Byte xxxx xxxx 48, 134
CCP2CON — — DC2B1 DC2B0 CCP2M3 CCP2M2 CCP2M1 CCP2M0 --00 0000 48, 133
PWM1CON(5) PRSEN PDC6 PDC5 PDC4 PDC3 PDC2 PDC1 PDC0 0000 0000 48, 149
ECCPAS(5) ECCPASE ECCPAS2 ECCPAS1 ECCPAS0 PSSAC1 PSSAC0 PSSBD1 PSSBD0 0000 0000 48, 150
CVRCON CVREN CVROE CVRR — CVR3 CVR2 CVR1 CVR0 000- 0000 48, 227
CMCON C2OUT C1OUT C2INV C1INV CIS CM2 CM1 CM0 0000 0111 48, 221
TMR3H Timer3 Register High Byte xxxx xxxx 48, 131
TMR3L Timer3 Register Low Byte xxxx xxxx 48, 131
T3CON RD16 T3CCP2 T3CKPS1 T3CKPS0 T3CCP1 T3SYNC TMR3CS TMR3ON 0000 0000 48, 129
SPBRG USART Baud Rate Generator 0000 0000 48, 198
RCREG USART Receive Register 0000 0000 48, 204,
203
TXREG USART Transmit Register 0000 0000 48, 202,
203
TXSTA CSRC TX9 TXEN SYNC — BRGH TRMT TX9D 0000 -010 48, 196
RCSTA SPEN RX9 SREN CREN ADDEN FERR OERR RX9D 0000 000x 48, 197
Legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: RA6 and associated bits are configured as port pins in RCIO, ECIO and INTIO2 (with port function on RA6) Oscillator mode only and read
‘0’ in all other oscillator modes.
2: RA7 and associated bits are configured as port pins in INTIO2 Oscillator mode only and read ‘0’ in all other modes.
3: Bit 21 of the PC is only available in Test mode and Serial Programming modes.
4: If PBADEN = 0, PORTB<4:0> are configured as digital input and read unknown and if PBADEN = 1, PORTB<4:0> are configured as
analog input and read ‘0’ following a Reset.
5: These registers and/or bits are not implemented on the PIC18F2X20 devices and read as ‘0’.
6: The RE3 port bit is only available when MCLRE fuse (CONFIG3H<7>) is programmed to ‘0’. Otherwise, RE3 reads ‘0’. This bit is
read-only.
• Intermediate computational values BSR<3:0> holds the upper 4 bits of the 12-bit RAM
address. The BSR<7:4> bits will always read ‘0’s and
• Local variables of subroutines
writes will have no effect (see Figure 5-7).
• Faster context saving/switching of variables
A MOVLB instruction has been provided in the
• Common variables
instruction set to assist in selecting banks.
• Faster evaluation/control of SFRs (no banking)
If the currently selected bank is not implemented, any
The Access Bank is comprised of the last 128 bytes in read will return all ‘0’s and all writes are ignored. The
Bank 15 (SFRs) and the first 128 bytes in Bank 0. Status register bits will be set/cleared as appropriate for
These two sections will be referred to as Access RAM the instruction performed.
High and Access RAM Low, respectively. Figure 5-6
indicates the Access RAM areas. Each Bank extends up to FFh (256 bytes). All data
memory is implemented as static RAM.
A bit in the instruction word specifies if the operation is
to occur in the bank specified by the BSR register or in A MOVFF instruction ignores the BSR since the 12-bit
the Access Bank. This bit is denoted as the ‘a’ bit (for addresses are embedded into the instruction word.
access bit). Section 5.12 “Indirect Addressing, INDF and FSR
When forced in the Access Bank (a = 0), the last Registers” provides a description of indirect address-
address in Access RAM Low is followed by the first ing which allows linear addressing of the entire RAM
address in Access RAM High. Access RAM High maps space.
the Special Function Registers, so these registers can
be accessed without any software overhead. This is
useful for testing status flags and modifying control bits.
Direct Addressing
BSR<7:4> BSR<3:0> 7 From Opcode(3) 0
0 0 0 0
Data
Memory(1)
0h
RAM
Instruction
Executed
Opcode Address
FFFh
12
BSR<3:0> 12 12
Instruction
4 8
Fetched
Opcode File FSR
11 0
Location Select
0000h
Data
Memory(1)
0FFFh
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Instruction: TBLRD*
Program Memory
Table Pointer(1)
Table Latch (8-bit)
TBLPTRU TBLPTRH TBLPTRL
TABLAT
Program Memory
(TBLPTR)
Program Memory
Holding Registers
Table Pointer(1) Table Latch (8-bit)
TBLPTRU TBLPTRH TBLPTRL TABLAT
Program Memory
(TBLPTR)
Note 1: Table Pointer actually points to one of eight holding registers, the address of which is determined by
TBLPTRL<2:0>. The process for physically writing data to the program memory array is discussed in
Section 6.5 “Writing to Flash Program Memory”.
6.2 Control Registers The WREN bit enables and disables erase and write
operations. When set, erase and write operations are
Several control registers are used in conjunction with allowed. When clear, erase and write operations are
the TBLRD and TBLWT instructions. These include the: disabled – the WR bit cannot be set while the WREN bit
• EECON1 register is clear. This process helps to prevent accidental writes
• EECON2 register to memory due to errant (unexpected) code execution.
• TABLAT register Firmware should keep the WREN bit clear at all times
• TBLPTR registers except when starting erase or write operations. Once
firmware has set the WR bit, the WREN bit may be
6.2.1 EECON1 AND EECON2 REGISTERS cleared. Clearing the WREN bit will not affect the
operation in progress.
EECON1 is the control register for memory accesses.
The WRERR bit is set when a write operation is inter-
EECON2 is not a physical register. Reading EECON2
rupted by a Reset. In these situations, the user can
will read all ‘0’s. The EECON2 register is used
check the WRERR bit and rewrite the location. It will be
exclusively in the memory write and erase sequences.
necessary to reload the data and address registers
Control bit, EEPGD, determines if the access will be to (EEDATA and EEADR) as these registers have cleared
program or data EEPROM memory. When clear, as a result of the Reset.
operations will access the data EEPROM memory.
Control bits, RD and WR, start read and erase/write
When set, program memory is accessed.
operations, respectively. These bits are set by firmware
Control bit, CFGS, determines if the access will be to and cleared by hardware at the completion of the
the configuration registers or to program memory/data operation.
EEPROM memory. When set, subsequent operations
The RD bit cannot be set when accessing program
access configuration registers. When CFGS is clear,
memory (EEPGD = 1). Program memory is read using
the EEPGD bit selects either program Flash or data
table read instructions. See Section 6.3 “Reading the
EEPROM memory.
Flash Program Memory” regarding table reads.
The FREE bit controls program memory erase opera-
tions. When the FREE bit is set, the erase operation is Note: Interrupt flag bit, EEIF in the PIR2 register,
initiated on the next WR command. When FREE is is set when the write is complete. It must
clear, only writes are enabled. be cleared in software.
Legend:
R = Readable bit S = Settable only U = Unimplemented bit, read as ‘0’ W = Writable bit
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
TABLE 6-1: TABLE POINTER OPERATIONS WITH TBLRD AND TBLWT INSTRUCTIONS
Example Operation on Table Pointer
TBLRD*
TBLPTR is not modified
TBLWT*
TBLRD*+
TBLPTR is incremented after the read/write
TBLWT*+
TBLRD*-
TBLPTR is decremented after the read/write
TBLWT*-
TBLRD+*
TBLPTR is incremented before the read/write
TBLWT+*
ERASE – TBLPTR<21:6>
Program Memory
TBLPTR TBLPTR
LSB = 1 LSB = 0
TABLAT
Write Register
8 8 8 8
Program Memory
Legend:
R = Readable bit S = Settable only U = Unimplemented bit, read as ‘0’ W = Writable bit
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Wake-up if in
Power Managed Mode
TMR0IF
TMR0IE
TMR0IP
RBIF
RBIE
RBIP
INT0IF
INT0IE
Interrupt to CPU
INT1IF Vector to Location
INT1IE
INT1IP 0008h
PSPIF
PSPIE INT2IF
PSPIP INT2IE
INT2IP
GIEH/GIE
ADIF
ADIE
ADIP IPE
RCIF IPEN
RCIE GIEL/PEIE
RCIP
IPEN
Additional Peripheral Interrupts
High Priority Interrupt Generation
PSPIF
PSPIE
PSPIP
Interrupt to CPU
TMR0IF Vector to Location
TMR0IE 0018h
ADIF TMR0IP
ADIE RBIF
ADIP RBIE
RBIP
RCIF GIEL\PEIE
RCIE INT0IF
RCIP
INT0IE
INT1IF
Additional Peripheral Interrupts INT1IE
INT1IP
INT2IF
INT2IE
INT2IP
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Note: Interrupt flag bits are set when an interrupt condition occurs regardless of the state
of its corresponding enable bit or the global enable bit. User software should ensure
the appropriate interrupt flag bits are clear prior to enabling an interrupt. This feature
allows for software polling.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Note: Interrupt flag bits are set when an interrupt condition occurs regardless of the state
of its corresponding enable bit or the global enable bit. User software should ensure
the appropriate interrupt flag bits are clear prior to enabling an interrupt. This feature
allows for software polling.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
• TRIS register (Data Direction register) Reading the PORTA register reads the status of the
pins, whereas writing to it, will write to the port latch.
• PORT register (reads the levels on the pins of the
device) The Data Latch register (LATA) is also memory mapped.
• LAT register (Data Latch) Read-modify-write operations on the LATA register read
and write the latched output value for PORTA.
The Data Latch (LAT register) is useful for read-modify-
write operations on the value that the I/O pins are The RA4 pin is multiplexed with the Timer0 module
driving. clock input and one of the comparator outputs to
become the RA4/T0CKI/C1OUT pin. Pins RA6 and
A simplified model of a generic I/O port without the RA7 are multiplexed with the main oscillator pins; they
interfaces to other peripherals is shown in Figure 10-1. are enabled as oscillator or I/O pins by the selection of
the main oscillator in Configuration Register 1H (see
FIGURE 10-1: GENERIC I/O PORT Section 23.1 “Configuration Bits” for details). When
OPERATION they are not used as port pins, RA6 and RA7 and their
associated TRIS and LAT bits are read as ‘0’.
RD LAT The other PORTA pins are multiplexed with analog
inputs, the analog VREF+ and VREF- inputs and the com-
Data
Bus
parator voltage reference output. The operation of pins,
D Q
RA3:RA0 and RA5, as A/D converter inputs is selected
WR LAT I/O pin(1) by clearing/setting the control bits in the ADCON1 reg-
or Port
CK ister (A/D Control Register 1). Pins RA0 through RA5
Data Latch may also be used as comparator inputs or outputs by
setting the appropriate bits in the CMCON register.
D Q
Note: On a Power-on Reset, RA5 and RA3:RA0
WR TRIS are configured as analog inputs and read
CK
TRIS Latch Input
as ‘0’. RA4 is configured as a digital input.
Buffer
The RA4/T0CKI/C1OUT pin is a Schmitt Trigger input
RD TRIS and an open-drain output. All other PORTA pins have
TTL input levels and full CMOS output drivers.
Q D The TRISA register controls the direction of the RA pins
even when they are being used as analog inputs. The
ENEN user must ensure the bits in the TRISA register are
maintained set when using them as analog inputs.
RD Port
RD LATA RD LATA
Data Data
Bus
D Q Bus D Q
WR LATA VDD
or WR LATA
PORTA or
CK Q PORTA CK Q I/O pin(1)
P
N
Data Latch Data Latch
N I/O pin(1)
D Q D Q VSS
RD TRISA
RD TRISA
TTL
Input Q D
Q D Buffer
ENEN
EN
RD PORTA RD PORTA
RD LATA RD LATA
D Q D Q
WR LATA VDD WR LATA VDD
or or
PORTA PORTA
CK Q P CK Q P
Data Latch Data Latch
RD RD
TRISA TTL TRISA TTL
Input Input
ECIO or Buffer Buffer
RCIO RA7
Enable Enable
Q D Q D
EN EN
RD PORTA RD PORTA
Note 1: I/O pins have protection diodes to VDD and VSS. Note 1: I/O pins have protection diodes to VDD and VSS.
PORTA RA7(1) RA6(1) RA5 RA4 RA3 RA2 RA1 RA0 xx0x 0000 uu0u 0000
LATA LATA7(1) LATA6(1) LATA Data Latch Register xxxx xxxx uuuu uuuu
TRISA TRISA7(1) TRISA6(1) PORTA Data Direction Register 1111 1111 1111 1111
ADCON1 — — VCFG1 VCFG0 PCFG3 PCFG2 PCFG1 PCFG0 --00 0000 --00 0000
CMCON C2OUT C1OUT C2INV C1INV CIS CM2 CM1 CM0 0000 0111 0000 0111
CVRCON CVREN CVROE CVRR — CVR3 CVR2 CVR1 CVR0 000- 0000 000- 0000
Legend: x = unknown, u = unchanged, - = unimplemented locations read as ‘0’. Shaded cells are not used by PORTA.
Note 1: RA7:RA6 and their associated latch and data direction bits are enabled as I/O pins based on oscillator configuration;
otherwise, they are read as ‘0’.
RD TRISB
RD LATB
Latch
RD LATB
Q D
Q D RD PORTB
EN Q1
Set RBIF
ENEN
RD PORTB
Q D
Schmitt Trigger
Buffer RD PORTB
INTx
From RB7:RB5 EN
Q3
To A/D Converter To A/D Converter
Note 1: I/O pins have diode protection to VDD and VSS. Note 1: I/O pins have diode protection to VDD and VSS.
2: To enable weak pull-ups, set the appropriate TRIS 2: To enable weak pull-ups, set the appropriate TRIS bit(s)
bit(s) and clear the RBPU bit (INTCON2<7>). and clear the RBPU bit (INTCON2<7>).
RD LATC 0 VDD
Data Bus P
D Q
1
WR LATB
or PORTB CK
Data Latch RB3 pin(1)
TTL Input
D Q Buffer
N
WR TRISB
CK VSS
TRIS Latch
RD TRISC
Q D
ENEN
RD PORTB Schmitt
Trigger
CCP2 Input
Analog Input Mode
To A/D Converter
Port/Peripheral Select(2)
VDD
Peripheral Data Out
RD LATC
0
Data Bus
D Q
WR LATC or P
WR PORTC Q 1
CK
I/O pin(1)
Data Latch
D Q
WR TRISC CK Q N
TRIS Latch
Schmitt
VSS Trigger
RD TRISC
Peripheral Output
Enable(3)
Q D
EN
RD PORTC
Peripheral Data In
PSPMODE
RD LATD
D Q
I/O pin(1)
WR TRISD
CK Q 0 N
TRIS Latch
PSP Read
1 VSS
TTL Buffer
RD TRISD
1
Q D
0
RD PORTD ENEN Schmitt Trigger
0
Input Buffer
PSP Write 1
RD LATD
D Q
I/O pin(1)
WR TRISD
CK Q 0 N
TRIS Latch
PSP Read VSS
1
TTL Buffer
RD TRISD
1
Q D
0
RD PORTD ENEN Schmitt Trigger
0
Input Buffer
PSP Write
1
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
RE0/AN5/RD bit 0 ST/TTL(1) Input/output port pin, analog input or read control input in Parallel Slave
Port mode.
For RD (PSP Control mode):
1 = PSP is Idle
0 = Read operation. Reads PORTD register (if chip selected).
RE1/AN6/WR bit 1 ST/TTL(1) Input/output port pin, analog input or write control input in Parallel
Slave Port mode.
For WR (PSP Control mode):
1 = PSP is Idle
0 = Write operation. Writes PORTD register (if chip selected).
RE2/AN7/CS bit 2 ST/TTL(1) Input/output port pin, analog input or chip select control input in Parallel
Slave Port mode.
For CS (PSP Control mode):
1 = PSP is Idle
0 = External device is selected
MCLR/VPP/RE3 bit 3 ST Input only port pin or programming voltage input (if MCLR is disabled);
Master Clear input or programming voltage input (if MCLR is enabled).
Legend: ST = Schmitt Trigger input, TTL = TTL input
Note 1: Input buffers are Schmitt Triggers when in I/O mode and TTL buffers when in Parallel Slave Port mode.
CS
WR
RD
PORTD<7:0>
IBF
OBF
PSPIF
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
CS
WR
RD
PORTD<7:0>
IBF
OBF
PSPIF
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Data Bus
RA4/T0CKI/C1OUT FOSC/4 0
pin 8
0
Sync with
1 Internal TMR0
Clocks
Programmable 1
Prescaler
T0SE (2 TCY delay)
3 PSA
Set Interrupt
T0PS2, T0PS1, T0PS0 Flag bit TMR0IF
T0CS on Overflow
Note: Upon Reset, Timer0 is enabled in 8-bit mode with clock input from T0CKI maximum prescale.
RA4/T0CKI/C1OUT FOSC/4
0
pin
0 Sync with Set Interrupt
1 Internal TMR0L TMR0
High Byte Flag bit TMR0IF
Programmable Clocks on Overflow
1 8
Prescaler (2 TCY delay)
T0SE
3
Read TMR0L
T0PS2, T0PS1, T0PS0
T0CS PSA Write TMR0L
8
8
TMR0H
Data Bus<7:0>
Note: Upon Reset, Timer0 is enabled in 8-bit mode with clock input from T0CKI maximum prescale.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Note 1: When enable bit T1OSCEN is cleared, the inverter and feedback resistor are turned off. This eliminates power drain.
TMR1H
8
8
Write TMR1L
CCP Special Event Trigger
Read TMR1L
Note 1: When enable bit T1OSCEN is cleared, the inverter and feedback resistor are turned off. This eliminates power drain.
RC0
TABLE 12-1: CAPACITOR SELECTION FOR
THE TIMER OSCILLATOR(2,3,4) RC1
Osc Type Freq C1 C2
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Prescaler Reset
FOSC/4 TMR2
1:1, 1:4, 1:16
2 Postscaler
Comparator
EQ 1:1 to 1:16
T2CKPS1:T2CKPS0
PR2 4
TOUTPS3:TOUTPS0
Note 1: TMR2 register output can be software selected by the SSP module as a baud clock.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
T1OSO/ T1OSC
T1CKI 1
Synchronize
Prescaler
T1OSCEN FOSC/4 1, 2, 4, 8 det
Enable Internal 0
T1OSI Oscillator(1) Clock 2
TMR3CS Peripheral Clocks
T3CKPS1:T3CKPS0
Note 1: When enable bit T1OSCEN is cleared, the inverter and feedback resistor are turned off. This eliminates power drain.
TMR3H
8
8
Write TMR3L
Read TMR3L
CCP Special Event Trigger
8 T3CCPx Synchronized
Set TMR3IF Flag bit TMR3 0
on Overflow Timer3 CLR Clock Input
High Byte TMR3L
1
To Timer1 Clock Input TMR3ON
On/Off T3SYNC
T1OSC
T1OSO/
T1CKI 1
Synchronize
Prescaler
T1OSCEN FOSC/4 1, 2, 4, 8 det
Enable Internal 0
T1OSI Oscillator(1) Clock 2 Peripheral Clocks
T3CKPS1:T3CKPS0
TMR3CS
Note 1: When the T1OSCEN bit is cleared, the inverter and feedback resistor are turned off. This eliminates power drain.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
TMR1
and T3CCP2 Enable
Edge Detect
TMR1H TMR1L
CCP1CON<3:0>
Q’s
TMR1
and
Enable
Edge Detect
T3CCP2
T3CCP1 TMR1H TMR1L
CCP2CON<3:0>
Q’s
Q S Output
Logic Comparator
RC2/CCP1/P1A R Match
pin
TRISC<2>
Output Enable CCP1CON<3:0> T3CCP2 0 1
Mode Select
Q S Output Comparator
RC1/T1OSI/CCP2 Logic Match
R
pin
TRISC<1> CCPR2H CCPR2L
Output Enable CCP2CON<3:0>
Mode Select
Duty Cycle
TMR2 = PR2
TMR2 = PR2
REGISTER 16-1: CCP1CON REGISTER FOR ENHANCED CCP OPERATION (PIC18F4X20 ONLY)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
P1M1 P1M0 DC1B1 DC1B0 CCP1M3 CCP1M2 CCP1M1 CCP1M0
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
TRISD<4>
CCPR1H (Slave)
P1B RD5/PSP5/P1B
Output TRISD<5>
Comparator R Q
Controller
RD6/PSP6/P1C
P1C
TMR2 (Note 1)
S TRISD<6>
P1D RD7/PSP7/P1D
Comparator
Clear Timer, TRISD<7>
set CCP1 pin and
latch D.C.
PR2 PWM1CON
Note: The 8-bit timer TMR2 register is concatenated with the 2-bit internal Q clock or 2 bits of the prescaler to create the 10-bit time base.
P1A Active
P1D Modulated
P1A Inactive
P1D Inactive
P1A Modulated
Delay(1) Delay(1)
10 (Half-Bridge) P1B Modulated
P1A Active
P1D Modulated
P1A Inactive
P1D Inactive
Relationships:
• Period = 4 * TOSC * (PR2 + 1) * (TMR2 Prescale Value)
• Duty Cycle = TOSC * (CCPR1L<7:0>:CCP1CON<5:4>) * (TMR2 Prescale Value)
• Delay = 4 * TOSC * (PWM1CON<6:0>)
Note 1: Dead band delay is programmed using the PWM1CON register (see Section 16.4.4 “Programmable Dead Band Delay”).
PIC18F4220/4320 FET
Driver +
P1A V
-
Load
FET
Driver
+
P1B V
-
V-
Half-Bridge Output Driving a Full-Bridge Circuit
V+
PIC18F4220/4320
FET FET
Driver Driver
P1A
Load
FET FET
Driver Driver
P1B
V-
FORWARD MODE
Period
P1A(2)
Duty Cycle
P1B(2)
P1C(2)
P1D(2)
(1) (1)
REVERSE MODE
Period
Duty Cycle
(2)
P1A
P1B(2)
P1C(2)
P1D(2)
(1) (1)
Note 1: At this time, the TMR2 register is equal to the PR2 register.
Note 2: Output signal is shown as active-high.
Load
P1B
FET FET
Driver Driver
P1C
QB QD
V-
P1D
16.4.3.1 Direction Change in Full-Bridge Figure 16-9 shows an example where the PWM direc-
Mode tion changes from forward to reverse at a near 100%
duty cycle. At time t1, the outputs P1A and P1D
In the Full-Bridge Output mode, the P1M1 bit in the
become inactive, while output P1C becomes active. In
CCP1CON register allows users to control the forward/
this example, since the turn-off time of the power
reverse direction. When the application firmware
devices is longer than the turn-on time, a shoot-through
changes this direction control bit, the module will
current may flow through power devices QC and QD
assume the new direction on the next PWM cycle.
(see Figure 16-7) for the duration of ‘t’. The same
Just before the end of the current PWM period, the mod- phenomenon will occur to power devices QA and QB
ulated outputs (P1B and P1D) are placed in their inactive for PWM direction change from reverse to forward.
state, while the unmodulated outputs (P1A and P1C) are
If changing PWM direction at high duty cycle is required
switched to drive in the opposite direction. This occurs in
for an application, one of the following requirements
a time interval of 4 TOSC * (Timer2 Prescale Value)
must be met:
before the next PWM period begins. The Timer2
prescaler will be either 1, 4 or 16, depending on the 1. Reduce PWM for a PWM period before
value of the T2CKPS bit (T2CON<1:0>). During the changing directions.
interval from the switch of the unmodulated outputs to 2. Use switch drivers that can drive the switches off
the beginning of the next period, the modulated outputs faster than they can drive them on.
(P1B and P1D) remain inactive. This relationship is Other options to prevent shoot-through current may
shown in Figure 16-8. exist.
Note that in the Full-Bridge Output mode, the ECCP
module does not provide any dead band delay. In gen-
eral, since only one output is modulated at all times,
dead band delay is not required. However, there is a
situation where a dead band delay might be required.
This situation occurs when both of the following
conditions are true:
1. The direction of the PWM output changes when
the duty cycle of the output is at or near 100%.
2. The turn-off time of the power switch, including
the power device and driver circuit, is greater
than the turn-on time.
(Note 2)
P1D (Active High)
DC
Note 1: The direction bit in the CCP1 Control register (CCP1CON<7>) is written any time during the PWM cycle.
2: When changing directions, the P1A and P1C signals switch before the end of the current PWM cycle at intervals of
4 TOSC, 16 TOSC or 64 TOSC, depending on the Timer2 prescaler value. The modulated P1B and P1D signals are
inactive at this time.
P1A
P1B DC
P1C
P1D DC
ton(2)
External Switch C
toff(3)
External Switch D
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
PWM Activity
Dead Time Dead Time Dead Time
Shutdown Event
ECCPASE bit
PWM Activity
Dead Time Dead Time Dead Time
Shutdown Event
ECCPASE bit
ECCPASE
Cleared by Firmware
2
Clock Select
SSPM3:SSPM0
SMP:CKE 4
2 (
TMR2 Output
2
)
Edge
Select Prescaler TOSC
RC3/SCK/ 4, 16, 64
SCL
Data to TX/RX in SSPSR
TRIS bit
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
SDO SDI
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
4 Clock
SCK Modes
(CKP = 0
CKE = 1)
SCK
(CKP = 1
CKE = 1)
Input
Sample
(SMP = 1)
SSPIF
Next Q4 Cycle
SSPSR to after Q2↓
SSPBUF
SS
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
Write to
SSPBUF
SDI bit 0
(SMP = 0)
bit 7 bit 7
Input
Sample
(SMP = 0)
SSPIF
Interrupt
Flag
Next Q4 Cycle
SSPSR to after Q2↓
SSPBUF
SS
Optional
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
Write to
SSPBUF
SDI
(SMP = 0) bit 7 bit 0
Input
Sample
(SMP = 0)
SSPIF
Interrupt
Flag
Next Q4 Cycle
SSPSR to after Q2↓
SSPBUF
SS
Not Optional
SCK
(CKP = 0
CKE = 1)
SCK
(CKP = 1
CKE = 1)
Write to
SSPBUF
SDI
(SMP = 0) bit 7 bit 0
Input
Sample
(SMP = 0)
SSPIF
Interrupt
Flag
Next Q4 Cycle
after Q2↓
SSPSR to
SSPBUF
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Note: 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 SSPBUF may not be written (or writes
to the SSPBUF are disabled).
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
DS39599C-page 170
Receiving Address R/W = 0 Receiving Data ACK Receiving Data ACK
SDA A7 A6 A5 A4 A3 A2 A1 ACK D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
S P
SSPIF
Bus master
(PIR1<3>) terminates
transfer
BF (SSPSTAT<0>)
Cleared in software
SSPBUF is read
PIC18F2220/2320/4220/4320
SSPOV (SSPCON1<6>)
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
SCL
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
S
Data in SCL held low P
sampled while CPU
responds to SSPIF
SSPIF (PIR1<3>)
BF (SSPSTAT<0>)
Cleared in software Cleared in software
From SSPIF ISR From SSPIF ISR
SSPBUF is written in software SSPBUF is written in software
CKP
I2C SLAVE MODE TIMING (TRANSMISSION, 7-BIT ADDRESS)
DS39599C-page 171
FIGURE 17-10:
DS39599C-page 172
Clock is held low until Clock is held low until
update of SSPADD has update of SSPADD has
taken place taken place
Receive First Byte of Address Receive Second Byte of Address Receive Data Byte Receive Data Byte
R/W = 0 ACK
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
S P
Bus master
terminates
SSPIF transfer
(PIR1<3>)
Cleared in software Cleared in software Cleared in software
Cleared in software
BF (SSPSTAT<0>)
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
PIC18F2220/2320/4220/4320
UA (SSPSTAT<1>)
Bus master
terminates
Clock is held low until Clock is held low until transfer
update of SSPADD has update of SSPADD has Clock is held low until
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
S Sr P
SSPIF
(PIR1<3>)
Cleared in software Cleared in software Cleared in software
BF (SSPSTAT<0>)
DS39599C-page 173
PIC18F2220/2320/4220/4320
17.4.4 CLOCK STRETCHING 17.4.4.3 Clock Stretching for 7-bit Slave
Both 7 and 10-bit Slave modes implement automatic Transmit Mode
clock stretching during a transmit sequence. 7-bit Slave Transmit mode implements clock stretching
The SEN bit (SSPCON2<0>) allows clock stretching to by clearing the CKP bit after the falling edge of the
be enabled during receives. Setting SEN will cause ninth clock if the BF bit is clear. This occurs regardless
the SCL pin to be held low at the end of each data of the state of the SEN bit.
receive sequence. The user’s ISR must set the CKP bit before transmis-
sion is allowed to continue. By holding the SCL line
17.4.4.1 Clock Stretching for 7-bit Slave low, the user has time to service the ISR and load the
Receive Mode (SEN = 1) contents of the SSPBUF before the master device can
In 7-bit Slave Receive mode, on the falling edge of the initiate another transmit sequence (see Figure 17-9).
ninth clock at the end of the ACK sequence if the BF bit Note 1: If the user loads the contents of SSPBUF,
is set, the CKP bit in the SSPCON1 register is automat- setting the BF bit before the falling edge of
ically cleared, forcing the SCL output to be held low. the ninth clock, the CKP bit will not be
The CKP being cleared to ‘0’ will assert the SCL line cleared and clock stretching will not occur.
low. The CKP bit must be set in the user’s ISR before
reception is allowed to continue. By holding the SCL 2: The CKP bit can be set in software
line low, the user has time to service the ISR and read regardless of the state of the BF bit.
the contents of the SSPBUF before the master device
17.4.4.4 Clock Stretching for 10-bit Slave
can initiate another receive sequence. This will prevent
buffer overruns from occurring (see Figure 17-13). Transmit Mode
In 10-bit Slave Transmit mode, clock stretching is con-
Note 1: If the user reads the contents of the
trolled during the first two address sequences by the
SSPBUF before the falling edge of the
state of the UA bit, just as it is in 10-bit Slave Receive
ninth clock, thus clearing the BF bit, the
mode. The first two addresses are followed by a third
CKP bit will not be cleared and clock
address sequence which contains the high order bits
stretching will not occur.
of the 10-bit address and the R/W bit set to ‘1’. After
2: The CKP bit can be set in software the third address sequence is performed, the UA bit is
regardless of the state of the BF bit. The not set, the module is now configured in Transmit
user should be careful to clear the BF bit mode and clock stretching is controlled by the BF flag
in the ISR before the next receive as in 7-bit Slave Transmit mode (see Figure 17-11).
sequence in order to prevent an overflow
condition.
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
SDA DX DX-1
SCL
Master device
CKP asserts clock
Master device
deasserts clock
WR
SSPCON1
DS39599C-page 176
Clock is not held low
because buffer full bit is
clear prior to falling edge Clock is held low until Clock is not held low
of 9th clock CKP is set to ‘1’ because ACK = 1
SDA A7 A6 A5 A4 A3 A2 A1 ACK D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
S P
SSPIF
Bus master
(PIR1<3>) terminates
transfer
BF (SSPSTAT<0>)
Cleared in software
SSPBUF is read
PIC18F2220/2320/4220/4320
SSPOV (SSPCON1<6>)
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
CKP
CKP
If BF is cleared written
prior to the falling to ‘1’ in
edge of the 9th clock, software
CKP will not be reset BF is set after falling
to ‘0’ and no clock edge of the 9th clock,
stretching will occur CKP is reset to ‘0’ and
clock stretching occurs
I2C SLAVE MODE TIMING WITH SEN = 1 (RECEPTION, 7-BIT ADDRESS)
SSPIF
Bus master
(PIR1<3>) terminates
Cleared in software Cleared in software Cleared in software transfer
Cleared in software
BF (SSPSTAT<0>)
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
UA (SSPSTAT<1>)
DS39599C-page 177
PIC18F2220/2320/4220/4320
17.4.5 GENERAL CALL ADDRESS If the general call address matches, the SSPSR is
SUPPORT transferred to the SSPBUF, the BF flag bit is set (eighth
bit) and on the falling edge of the ninth bit (ACK bit), the
The addressing procedure for the I2C bus is such that
SSPIF interrupt flag bit is set.
the first byte after the Start condition usually deter-
mines which device will be the slave addressed by the When the interrupt is serviced, the source for the inter-
master. The exception is the general call address, rupt can be checked by reading the contents of the
which can address all devices. When this address is SSPBUF. The value can be used to determine if the
used, all devices should, in theory, respond with an address was device specific or a general call address.
Acknowledge. In 10-bit mode, the SSPADD is required to be updated
The general call address is one of eight addresses for the second half of the address to match and the UA
reserved for specific purposes by the I2C protocol. It bit is set (SSPSTAT<1>). If the general call address is
consists of all ‘0’s with R/W = 0. sampled when the GCEN bit is set while the slave is
configured in 10-bit Address mode, then the second
The general call address is recognized when the
half of the address is not necessary, the UA bit will not
General Call Enable bit (GCEN) is enabled
be set and the slave will begin receiving data after the
(SSPCON2<7> set). Following a Start bit detect, 8 bits
Acknowledge (Figure 17-15).
are shifted into the SSPSR and the address is com-
pared against the SSPADD. It is also compared to the
general call address and fixed in hardware.
SCL
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
S
SSPIF
BF (SSPSTAT<0>)
Cleared in software
SSPBUF is read
SSPOV (SSPCON1<6>) ‘0’
Internal SSPM3:SSPM0
Data Bus SSPADD<6:0>
Read Write
SSPBUF Baud
Rate
Generator
SDA Shift
Clock Arbitrate/WCOL Detect
SDA In Clock
SSPSR
(hold off clock source)
MSb LSb
Receive Enable
Acknowledge
Generate
SCL
SSPM3:SSPM0 SSPADD<6:0>
SDA DX DX-1
BRG decrements on
Q2 and Q4 cycles
BRG
03h 02h 01h 00h (hold off) 03h 02h
Value
SCL
TBRG
S
Set S (SSPSTAT<3>)
Write to SSPCON2
SDA = 1,
occurs here. At completion of Start bit,
SDA = 1, SCL = 1
hardware clears RSEN bit
SCL (no change). and sets SSPIF
Sr = Repeated Start
DS39599C-page 186
Write SSPCON2<0> SEN = 1, ACKSTAT in
Start condition begins SSPCON2 = 1
From slave, clear ACKSTAT bit SSPCON2<6>
SEN = 0
Transmitting Data or Second Half
Transmit Address to Slave R/W = 0 of 10-bit Address ACK
SDA A7 A6 A5 A4 A3 A2 A1 ACK = 0 D7 D6 D5 D4 D3 D2 D1 D0
BF (SSPSTAT<0>)
SEN
PEN
R/W
I 2C MASTER MODE WAVEFORM (TRANSMISSION, 7 OR 10-BIT ADDRESS)
Write to SSPCON2<4>
to start Acknowledge sequence,
SDA = ACKDT (SSPCON2<5>) = 0
Write to SSPCON2<0> (SEN = 1),
begin Start condition ACK from master, Set ACKEN, start Acknowledge sequence,
Master configured as a receiver SDA = ACKDT = 0 SDA = ACKDT = 1
SEN = 0 by programming SSPCON2<3> (RCEN = 1)
Bus master
ACK is not sent terminates
transfer
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
SCL S P
Data shifted in on falling edge of CLK Set SSPIF at end
of receive Set SSPIF interrupt
Set SSPIF interrupt at end of Acknow-
Set SSPIF interrupt ledge sequence
at end of receive
at end of Acknowledge
SSPIF sequence
Set P bit
Cleared in software Cleared in software Cleared in software Cleared in software (SSPSTAT<4>)
SDA = 0, SCL = 1, Cleared in
while CPU software and SSPIF
responds to SSPIF
BF
(SSPSTAT<0>) Last bit is shifted into SSPSR and
contents are unloaded into SSPBUF
SSPOV
ACKEN
I 2C MASTER MODE WAVEFORM (RECEPTION, 7-BIT ADDRESS)
PIC18F2220/2320/4220/4320
DS39599C-page 187
PIC18F2220/2320/4220/4320
17.4.12 ACKNOWLEDGE SEQUENCE TIMING 17.4.13 STOP CONDITION TIMING
An Acknowledge sequence is enabled by setting the A Stop bit is asserted on the SDA pin at the end of a
Acknowledge Sequence Enable bit, ACKEN receive/transmit by setting the Stop Sequence Enable
(SSPCON2<4>). When this bit is set, the SCL pin is bit, PEN (SSPCON2<2>). At the end of a receive/
pulled low and the contents of the Acknowledge data bit transmit, the SCL line is held low after the falling edge
are presented on the SDA pin. If the user wishes to gen- of the ninth clock. When the PEN bit is set, the master
erate an Acknowledge, then the ACKDT bit should be will assert the SDA line low. When the SDA line is sam-
cleared. If not, the user should set the ACKDT bit before pled low, the Baud Rate Generator is reloaded and
starting an Acknowledge sequence. The Baud Rate counts down to 0. When the Baud Rate Generator
Generator then counts for one rollover period (TBRG) and times out, the SCL pin will be brought high and one
the SCL pin is deasserted (pulled high). When the SCL TBRG (Baud Rate Generator rollover count) later, the
pin is sampled high (clock arbitration), the Baud Rate SDA pin will be deasserted. When the SDA pin is sam-
Generator counts for TBRG. The SCL pin is then pulled pled high while SCL is high, the P bit (SSPSTAT<4>) is
low. Following this, the ACKEN bit is automatically set. A TBRG later, the PEN bit is cleared and the SSPIF
cleared, the Baud Rate Generator is turned off and the bit is set (Figure 17-24).
MSSP module then goes into Idle mode (Figure 17-23).
17.4.13.1 WCOL Status Flag
17.4.12.1 WCOL Status Flag If the user writes the SSPBUF when a Stop sequence
If the user writes the SSPBUF when an Acknowledge is in progress, then the WCOL bit is set and the con-
sequence is in progress, then WCOL is set and the tents of the buffer are unchanged (the write doesn’t
contents of the buffer are unchanged (the write doesn’t occur).
occur).
SCL 8 9
SSPIF
Cleared in software
Set SSPIF at the end Cleared in
of receive software Set SSPIF at the end
of Acknowledge sequence
Note: TBRG = one Baud Rate Generator period.
SDA ACK
P
TBRG TBRG TBRG
SCL brought high after TBRG
SDA asserted low before rising edge of clock
to setup Stop condition
SDA
SCL
Set Bus Collision
Interrupt Flag (BCLIF)
BCLIF
SDA
SCL
Set SEN, enable Start SEN cleared automatically because of bus collision.
condition if SDA = 1, SCL = 1 SSP module reset into Idle state.
SEN
SDA sampled low before
Start condition. Set BCLIF.
S bit and SSPIF set because
BCLIF SDA = 0, SCL = 1.
SSPIF and BCLIF are
cleared in software
SSPIF
TBRG TBRG
SDA
FIGURE 17-28: BRG RESET DUE TO SDA ARBITRATION DURING START CONDITION
SDA = 0, SCL = 1
Set S Set SSPIF
Less than TBRG
TBRG
SCL S
SCL pulled low after BRG
Time-out
SEN
Set SEN, enable Start
sequence if SDA = 1, SCL = 1
BCLIF ‘0’
SSPIF
SDA = 0, SCL = 1, Interrupts cleared
set SSPIF in software
SDA
SCL
RSEN
BCLIF
Cleared in software
S ‘0’
SSPIF ‘0’
TBRG TBRG
SDA
SCL
S ‘0’
SSPIF
PEN
BCLIF
P ‘0’
SSPIF ‘0’
SDA
PEN
BCLIF
P ‘0’
SSPIF ‘0’
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
FOSC = 8.000000 MHz FOSC = 7.159090 MHz FOSC = 5.068800 MHz FOSC = 4.000000 MHz
BAUD
RATE Actual SPBRG Actual SPBRG Actual SPBRG Actual SPBRG
% % % %
(K) Rate value Rate value Rate value Rate value
Error Error Error Error
(K) (decimal) (K) (decimal) (K) (decimal) (K) (decimal)
0.3 0.49 62.76 255 0.44 45.65 255 0.31 3.13 255 0.30 0.16 207
1.2 1.20 0.16 103 1.20 0.23 92 1.20 0.00 65 1.20 0.16 51
2.4 2.40 0.16 51 2.38 -0.83 46 2.40 0.00 32 2.40 0.16 25
9.6 9.62 0.16 12 9.32 -2.90 11 9.90 3.13 7 8.93 -6.99 6
19.2 17.86 -6.99 6 18.64 -2.90 5 19.80 3.13 3 20.83 8.51 2
38.4 41.67 8.51 2 37.29 -2.90 2 39.60 3.13 1 31.25 -18.62 1
57.6 62.50 8.51 1 55.93 -2.90 1 — — — 62.50 8.51 0
— — — — — — — 79.20 3.13 0 — — —
115.2 125.00 8.51 0 111.86 -2.90 0 — — — — — —
FOSC = 3.579545 MHz FOSC = 2.000000 MHz FOSC = 1.000000 MHz FOSC = 0.032768 MHz
BAUD
RATE Actual SPBRG Actual SPBRG Actual SPBRG Actual SPBRG
% % % %
(K) Rate value Rate value Rate value Rate value
Error Error Error Error
(K) (decimal) (K) (decimal) (K) (decimal) (K) (decimal)
0.3 0.30 0.23 185 0.30 0.16 103 0.30 0.16 51 0.26 -14.67 1
1.2 1.19 -0.83 46 1.20 0.16 25 1.20 0.16 12 — — —
2.4 2.43 1.32 22 2.40 0.16 12 2.23 -6.99 6 — — —
9.6 9.32 -2.90 5 10.42 8.51 2 7.81 -18.62 1 — — —
19.2 18.64 -2.90 2 15.63 -18.62 1 15.63 -18.62 0 — — —
38.4 — — — 31.25 -18.62 0 — — — — — —
57.6 55.93 -2.90 0 — — — — — — — — —
2.4 — — — 4.88 103.45 255 3.91 62.76 255 2.44 1.73 255
9.6 9.77 1.73 255 9.62 0.16 129 9.62 0.16 103 9.63 0.16 64
19.2 19.23 0.16 129 19.23 0.16 64 19.23 0.16 51 18.94 -1.36 32
38.4 38.46 0.16 64 37.88 -1.36 32 38.46 0.16 25 39.06 1.73 15
57.6 58.14 0.94 42 56.82 -1.36 21 58.82 2.12 16 56.82 -1.36 10
76.8 75.76 -1.36 32 78.13 1.73 15 76.92 0.16 12 78.13 1.73 7
96.0 96.15 0.16 25 96.15 0.16 12 100.00 4.17 9 89.29 -6.99 6
115.2 113.64 -1.36 21 113.64 -1.36 10 111.11 -3.55 8 125.00 8.51 4
250.0 250.00 0.00 9 250.00 0.00 4 250.00 0.00 3 208.33 -16.67 2
300.0 312.50 4.17 7 312.50 4.17 3 333.33 11.11 2 312.50 4.17 1
500.0 500.00 0.00 4 416.67 -16.67 2 500.00 0.00 1 — — —
625.0 625.00 0.00 3 625.00 0.00 1 — — — 625.00 0.00 0
1000.0 833.33 -16.67 2 — — — 1000.00 0.00 0 — — —
1250.0 1250.00 0.00 1 1250.00 0.00 0 — — — — — —
FOSC = 8.000000 MHz FOSC = 7.159090 MHz FOSC = 5.068800 MHz FOSC = 4.000 MHz
BAUD
RATE SPBRG SPBRG SPBRG SPBRG
Actual % Actual % Actual % Actual %
(K) value value value value
Rate (K) Error Rate (K) Error Rate (K) Error Rate (K) Error
(decimal) (decimal) (decimal) (decimal)
FOSC = 3.579545 MHz FOSC = 2.000000 MHz FOSC = 1.000000 MHz FOSC = 0.032768 MHz
BAUD
RATE SPBRG SPBRG SPBRG SPBRG
Actual % Actual % Actual % Actual %
(K) value value value value
Rate (K) Error Rate (K) Error Rate (K) Error Rate (K) Error
(decimal) (decimal) (decimal) (decimal)
0.3 0.87 191.30 255 0.49 62.76 255 0.30 0.16 207 0.29 -2.48 6
1.2 1.20 0.23 185 1.20 0.16 103 1.20 0.16 51 1.02 -14.67 1
2.4 2.41 0.23 92 2.40 0.16 51 2.40 0.16 25 2.05 -14.67 0
9.6 9.73 1.32 22 9.62 0.16 12 8.93 -6.99 6 — — —
19.2 18.64 -2.90 11 17.86 -6.99 6 20.83 8.51 2 — — —
38.4 37.29 -2.90 5 41.67 8.51 2 31.25 -18.62 1 — — —
57.6 55.93 -2.90 3 62.50 8.51 1 62.50 8.51 0 — — —
76.8 74.57 -2.90 2 — — — — — — — — —
115.2 111.86 -2.90 1 125.00 8.51 0 — — — — — —
250.0 223.72 -10.51 0 — — — — — — — — —
FOSC = 8.000000 MHz FOSC = 7.159090 MHz FOSC = 5.068800 MHz FOSC = 4.000 MHz
BAUD
RATE SPBRG SPBRG SPBRG SPBRG
Actual % Actual % Actual % Actual %
(K) value value value value
Rate (K) Error Rate (K) Error Rate (K) Error Rate (K) Error
(decimal) (decimal) (decimal) (decimal)
2.4 7.81 225.52 255 6.99 191.30 255 4.95 106.25 255 3.91 62.76 255
9.6 9.62 0.16 207 9.62 0.23 185 9.60 0.00 131 9.62 0.16 103
19.2 19.23 0.16 103 19.24 0.23 92 19.20 0.00 65 19.23 0.16 51
38.4 38.46 0.16 51 38.08 -0.83 46 38.40 0.00 32 38.46 0.16 25
57.6 57.14 -0.79 34 57.73 0.23 30 57.60 0.00 21 58.82 2.12 16
76.8 76.92 0.16 25 77.82 1.32 22 74.54 -2.94 16 76.92 0.16 12
96.0 95.24 -0.79 20 94.20 -1.88 18 97.48 1.54 12 100.00 4.17 9
250.0 250.00 0.00 7 255.68 2.27 6 253.44 1.38 4 250.00 0.00 3
300.0 285.71 -4.76 6 298.30 -0.57 5 316.80 5.60 3 333.33 11.11 2
500.0 500.00 0.00 3 447.44 -10.51 3 422.40 -15.52 2 500.00 0.00 1
625.0 666.67 6.67 2 596.59 -4.55 2 633.60 1.38 1 — — —
1000.0 1000.00 0.00 1 894.89 -10.51 1 — — — 1000.00 0.00 0
1250.0 — — — 1789.77 43.18 0 1267.20 1.38 0 — — —
FOSC = 3.579545 MHz FOSC = 2.000000 MHz FOSC = 1.000000 MHz FOSC = 0.032768 MHz
BAUD
RATE SPBRG SPBRG SPBRG SPBRG
Actual % Actual % Actual % Actual %
(K) value value value value
Rate (K) Error Rate (K) Error Rate (K) Error Rate (K) Error
(decimal) (decimal) (decimal) (decimal)
0.3 — — — — — — 0.98 225.52 255 0.30 1.14 26
1.2 — — — 1.95 62.76 255 1.20 0.16 207 1.17 -2.48 6
2.4 3.50 45.65 255 2.40 0.16 207 2.40 0.16 103 2.73 13.78 2
9.6 9.62 0.23 92 9.62 0.16 51 9.62 0.16 25 8.19 -14.67 0
19.2 19.04 -0.83 46 19.23 0.16 25 19,.23 0.16 12 — — —
38.4 38.91 1.32 22 38.46 0.16 12 35.71 -6.99 6 — — —
57.6 55.93 -2.90 15 55.56 -3.55 8 62.50 8.51 3 — — —
76.8 74.57 -2.90 11 71.43 -6.99 6 83.33 8.51 2 — — —
96.0 99.43 3.57 8 100.00 4.17 4 — — — — — —
250.0 223.72 -10.51 3 250.00 0.00 1 250.00 0.00 0 — — —
500.0 447.44 -10.51 1 500.00 0.00 0 — — — — — —
Data Bus
SPBRG
TX9
Baud Rate Generator
TX9D
Write to TXREG
Word 1
BRG Output
(Shift Clock)
RC6/TX/CK (pin)
Start bit bit 0 bit 1 bit 7/8 Stop bit
Word 1
TXIF bit
(Transmit Buffer 1 TCY
Reg. Empty Flag)
Word 1
TRMT bit Transmit Shift Reg
(Transmit Shift
Reg. Empty Flag)
Write to TXREG
Word 1 Word 2
BRG Output
(Shift Clock)
RC6/TX/CK (pin)
Start bit bit 0 bit 1 bit 7/8 Stop bit Start bit bit 0
TXIF bit
(Interrupt Reg. Flag) 1 TCY Word 1 Word 2
1 TCY
TRMT bit Word 1 Word 2
(Transmit Shift Transmit Shift Reg.
Reg. Empty Flag) Transmit Shift Reg.
RX9
SPEN
8
RCIF
(Interrupt Flag)
OERR bit
CREN
Note: This timing diagram shows three words appearing on the RX input. The RCREG (Receive Buffer) is read after the third word,
causing the OERR (Overrun) bit to be set.
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 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
‘1’ ‘1’
TXEN bit
Note: Sync Master mode, SPBRG = 0; continuous transmission of two 8-bit words.
RC6/TX/CK pin
Write to
TXREG reg
TXIF bit
TRMT bit
TXEN bit
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 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
RC7/RX/DT pin bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7
RC6/TX/CK pin
Write to
bit SREN
SREN bit
RCIF bit
(Interrupt)
Read
RXREG
Note: Timing diagram demonstrates Sync Master mode with bit SREN = 1 and bit BRGH = 0.
Synchronous Slave mode differs from the Master mode 1. Enable the synchronous slave serial port by
in the fact that the shift clock is supplied externally at setting bits SYNC and SPEN and clearing bit
the RC6/TX/CK pin (instead of being supplied internally CSRC.
in Master mode). This allows the device to transfer or 2. Clear bits CREN and SREN.
receive data while in any power managed mode. Slave 3. If interrupts are desired, set enable bit TXIE.
mode is entered by clearing bit, CSRC (TXSTA<7>). 4. If 9-bit transmission is desired, set bit TX9.
5. Enable the transmission by setting enable bit
18.5.1 USART SYNCHRONOUS SLAVE
TXEN.
TRANSMIT
6. If 9-bit transmission is selected, the ninth bit
The operation of the Synchronous Master and Slave should be loaded in bit TX9D.
modes are identical, except in the case of the Sleep 7. Start transmission by loading data to the TXREG
mode. register.
If two words are written to the TXREG and then the 8. If using interrupts, ensure that the GIE and PEIE
SLEEP instruction is executed, the following will occur: bits in the INTCON register (INTCON<7:6>) are
a) The first word will immediately transfer to the set.
TSR register and transmit.
b) The second word will remain in TXREG register.
c) Flag bit TXIF will not be set.
d) When the first word has been shifted out of TSR,
the TXREG register will transfer the second
word to the TSR and flag bit TXIF will now be
set.
e) If enable bit TXIE is set, the interrupt will wake
the chip from Sleep. If the global interrupt is
enabled, the program will branch to the interrupt
vector.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
AN7(2)
AN6(2)
AN5(2)
AN12
AN10
AN11
PCFG3:
AN9
AN8
AN4
AN3
AN2
AN1
AN0
PCFG0
0000(1) A A A A A A A A A A A A A
0001 A A A A A A A A A A A A A
0010 A A A A A A A A A A A A A
0011 D A A A A A A A A A A A A
0100 D D A A A A A A A A A A A
0101 D D D A A A A A A A A A A
0110 D D D D A A A A A A A A A
0111(1) D D D D D A A A A A A A A
1000 D D D D D D A A A A A A A
1001 D D D D D D D A A A A A A
1010 D D D D D D D D A A A A A
1011 D D D D D D D D D A A A A
1100 D D D D D D D D D D A A A
1101 D D D D D D D D D D D A A
1110 D D D D D D D D D D D D A
1111 D D D D D D D D D D D D D
A = Analog input D = Digital I/O
Note 1: The POR value of the PCFG bits depends on the value of the PBAD bit in
Configuration Register 3H. When PBAD = 1, PCFG<3:0> = 0000; when PBAD = 0,
PCFG<3:0> = 0111.
2: AN5 through AN7 are available only in PIC18F4X20 devices.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Note 1: If the A/D FRC clock source is selected, a delay of one TCY (instruction cycle) is
added before the A/D clock starts. This allows the SLEEP instruction to be executed
before starting a conversion.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
CHS3:CHS0
1100
AN12(2)
1011
AN11
1010
AN10
1001
AN9
1000
AN8
0111
AN7(1)
0110
AN6(1)
0101
AN5(1)
0100
AN4
VAIN
10-bit (Input Voltage) 0011
AN3/VREF+
Converter
A/D 0010
AN2/VREF-
0001
VCFG1:VCFG0 AN1
AVDD 0000
AN0
X0
VREFH X1
Reference 1X
Voltage VREFL 0X
AVSS
Note 1: Channels AN5 through AN7 are not available on PIC18F2X20 devices.
2: I/O pins have diode protection to VDD and VSS.
VSS
Conversion starts
Holding capacitor is disconnected from analog input (typically 100 ns)
Set GO bit
FIGURE 19-4: A/D CONVERSION TAD CYCLES (ACQT<2:0> = 010, TACQ = 4 TAD)
1 2 3 4 1 2 3 4 5 6 7 8 9 10 11
b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
Automatic
Acquisition Conversion starts
Time (Holding capacitor is disconnected)
Set GO bit
(Holding capacitor continues
acquiring input) Next Q4: ADRESH:ADRESL are loaded, GO bit is cleared,
ADIF bit is set, holding capacitor is reconnected to analog input.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
RA5/AN4/SS/LVDIN/C2OUT(1)
Two Common Reference Comparators Two Common Reference Comparators with Outputs
CM<2:0> = 100 CM<2:0> = 101
RA0/AN0
A VIN- A VIN-
RA0/AN0
A VIN+ C1 C1OUT A VIN+ C1 C1OUT
RA3/AN3/ RA3/AN3/
VREF+ VREF+
RA4/T0CKI/C1OUT(1)
RA1/AN1
A VIN-
C2 C2OUT A VIN-
RA2/AN2/ D VIN+ RA1/AN1
VREF-/CVREF D VIN+ C2 C2OUT
RA2/AN2/
VREF-/CVREF
RA5/AN4/SS/LVDIN/C2OUT(1)
One Independent Comparator with Output Four Inputs Multiplexed to Two Comparators
CM<2:0> = 001 CM<2:0> = 110
A VIN- A
RA0/AN0 RA0/AN0 CIS = 0 VIN-
VIN+ C1 C1OUT A CIS = 1
RA3/AN3/ A RA3/AN3/ VIN+ C1 C1OUT
VREF+ VREF+
A
RA4/T0CKI/C1OUT(1) RA1/AN1 CIS = 0 VIN-
A CIS = 1
RA2/AN2/ VIN+ C2 C2OUT
D VIN-
RA1/AN1 VREF-/CVREF
C2 Off (Read as ‘0’) CVROE = 0
RA2/AN2/ D VIN+
CVREF
VREF-/CVREF From VREF Module
CVROE = 1
20.3.1 EXTERNAL REFERENCE SIGNAL The polarity of the comparator outputs can be changed
using the C2INV and C1INV bits (CMCON<4:5>).
When external voltage references are used, the
Note 1: When reading the Port register, all pins
comparator module can be configured to have the com-
configured as analog inputs will read as a
parators operate from the same or different reference
‘0’. Pins configured as digital inputs will
sources. However, threshold detector applications may
convert an analog input according to the
require the same reference. The reference signal must
Schmitt Trigger input specification.
be between VSS and VDD and can be applied to either
pin of the comparator(s). 2: Analog levels on any pin defined as a
digital input may cause the input buffer to
consume more current than is specified.
Port Pins
MULTIPLEX
+ -
CxINV
To RA4 or
RA5 Pin
Bus Q D
Data
Read CMCON EN
Set
CMIF Q D
bit From
other EN
Comparator
CL Read CMCON
Reset
VDD
VT = 0.6V RIC
RS < 10k
Comparator
AIN Input
CPIN ILEAKAGE
VA VT = 0.6V ±500 nA
5 pF
VSS
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
VDD
16 Stages
CVREN
8R R R R R
CVRR
RA2/AN2/VREF-/CVREF
8R
CVROE
CVR3
CVREF 16-1 Analog Mux (From CVRCON<3:0>)
CVR0
R(1) RA2
CVREF
Module +
CVREF Output
–
Voltage
Reference
Output
Impedance
Note 1: R is dependent upon the voltage reference configuration bits (CVRCON<3:0> and CVRCON<5>).
VA
VB
Voltage
Legend:
VA = LVD trip point
VB = Minimum valid device
operating voltage
TA TB
Time
VDD LVDIN
LVD Control
Register
16 to 1 MUX
LVDIF
The LVD module has an additional feature that allows pin, LVDIN (Figure 22-3). This gives users flexibility
the user to supply the sense voltage to the module because it allows them to configure the Low-Voltage
from an external source. This mode is enabled when Detect interrupt to occur at any voltage in the valid
bits LVDL3:LVDL0 are set to ‘1111’. In this state, the operating range.
comparator input is multiplexed from the external input
FIGURE 22-3: LOW-VOLTAGE DETECT (LVD) WITH EXTERNAL INPUT BLOCK DIAGRAM
VDD
VDD
LVD Control
Register
16 to 1 MUX
LVDIN LVDEN
Externally Generated
Trip Point
LVD
VxEN
BODEN
EN
BGAP
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
VDD
VLVD
LVDIF
Enable LVD
CASE 2:
VDD
VLVD
LVDIF
Enable LVD
Legend:
R = Readable bit P = Programmable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
Note 1: The Power-up Timer is decoupled from Brown-out Reset, allowing these features to
be independently controlled.
Legend:
R = Readable bit P = Programmable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
Legend:
R = Readable bit P = Programmable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
Legend:
R = Readable bit P = Programmable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
Legend:
R = Readable bit C = Clearable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
Legend:
R = Readable bit C = Clearable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
Legend:
R = Readable bit C = Clearable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
Legend:
R = Readable bit P = Programmable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
Legend:
R = Readable bit P = Programmable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
Legend:
R = Readable bit P = Programmable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
Legend:
R = Readable bit P = Programmable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
Legend:
R = Read-only bit P = Programmable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
Legend:
R = Read-only bit P = Programmable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
Sleep
Legend:
R = Readable bit W = Writable bit
U = Unimplemented bit, read as ‘0’ - n = Value at POR
INTOSC
Multiplexer
OSC1
TOST(1) TPLL(1)
PLL Clock
Output 1 2 3 4 5 6 7 8
Clock Transition
CPU Clock
Peripheral
Clock
Program PC PC + 2 PC + 4 PC + 6
Counter
Note 1: TOST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
Sample Clock
System Oscillator
Clock Failure
Output
CM Output
(Q)
Failure
Detected
OSCFIF
Note: 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.
000000h
Boot Block Boot Block CPB, WRTB, EBTRB
0001FFh
000200h
Block 0 Block 0 CP0, WRT0, EBTR0
0007FFh
000800h
Block 1 Block 1 CP1, WRT1, EBTR1
000FFFh
001000h
Unimplemented
Block 2 CP2, WRT2, EBTR2
Read ‘0’s
0017FFh
001800h
Unimplemented
Block 3 CP3, WRT3, EBTR3
Read ‘0’s
001FFFh
002000h
Unimplemented Unimplemented
Read ‘0’s Read ‘0’s (Unimplemented Memory Space)
1FFFFFh
TBLPTR = 0002FFh
WRT0, EBTR0 = 01
001FFFh
000000h
WRTB, EBTRB = 11
0001FFh
000200h
TBLPTR = 0002FFh
WRT0, EBTR0 = 10
0007FFh
000800h
PC = 000FFEh TBLRD * WRT1, EBTR1 = 11
000FFFh
001000h
WRT2, EBTR2 = 11
0017FFh
001800h
WRT3, EBTR3 = 11
001FFFh
Results: All table reads from external blocks to Blockn are disabled whenever EBTRn = 0.
TABLAT register returns a value of ‘0’.
001FFFh
Literal operations
15 8 7 0
OPCODE k (literal) MOVLW 0x7F
Control operations
CALL, GOTO and Branch operations
15 8 7 0
OPCODE n<7:0> (literal) GOTO Label
15 12 11 0
1111 n<19:8> (literal)
15 8 7 0
OPCODE S n<7:0> (literal) CALL MYFUNC
15 12 11 0
n<19:8> (literal)
S = Fast bit
15 11 10 0
OPCODE n<10:0> (literal) BRA MYFUNC
15 8 7 0
OPCODE n<7:0> (literal) BC MYFUNC
CONTROL OPERATIONS
BC n Branch if Carry 1 (2) 1110 0010 nnnn nnnn None
BN n Branch if Negative 1 (2) 1110 0110 nnnn nnnn None
BNC n Branch if Not Carry 1 (2) 1110 0011 nnnn nnnn None
BNN n Branch if Not Negative 1 (2) 1110 0111 nnnn nnnn None
BNOV n Branch if Not Overflow 1 (2) 1110 0101 nnnn nnnn None
BNZ n Branch if Not Zero 1 (2) 1110 0001 nnnn nnnn None
BOV n Branch if Overflow 1 (2) 1110 0100 nnnn nnnn None
BRA n Branch Unconditionally 2 1101 0nnn nnnn nnnn None
BZ n Branch if Zero 1 (2) 1110 0000 nnnn nnnn None
CALL n, s Call subroutine 1st word 2 1110 110s kkkk kkkk None
2nd word 1111 kkkk kkkk kkkk
CLRWDT — Clear Watchdog Timer 1 0000 0000 0000 0100 TO, PD
DAW — Decimal Adjust WREG 1 0000 0000 0000 0111 C, DC
GOTO n Go to address 1st word 2 1110 1111 kkkk kkkk None
2nd word 1111 kkkk kkkk kkkk
NOP — No Operation 1 0000 0000 0000 0000 None
NOP — No Operation (Note 4) 1 1111 xxxx xxxx xxxx None
POP — Pop top of return stack (TOS) 1 0000 0000 0000 0110 None
PUSH — Push top of return stack (TOS) 1 0000 0000 0000 0101 None
RCALL n Relative Call 2 1101 1nnn nnnn nnnn None
RESET Software device Reset 1 0000 0000 1111 1111 All
RETFIE s Return from interrupt enable 2 0000 0000 0001 000s GIE/GIEH,
PEIE/GIEL
RETLW k Return with literal in WREG 2 0000 1100 kkkk kkkk None
RETURN s Return from Subroutine 2 0000 0000 0001 001s None
SLEEP — Go into Standby mode 1 0000 0000 0000 0011 TO, PD
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’.
2: If this instruction is executed on the TMR0 register (and where applicable, d = 1), the prescaler will be cleared
if assigned.
3: 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.
4: Some instructions are 2-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.
5: If the table write starts the write cycle to internal memory, the write will continue until terminated.
LITERAL OPERATIONS
ADDLW k Add literal and WREG 1 0000 1111 kkkk kkkk C, DC, Z, OV, N
ANDLW k AND literal with WREG 1 0000 1011 kkkk kkkk Z, N
IORLW k Inclusive OR literal with WREG 1 0000 1001 kkkk kkkk Z, N
LFSR f, k Move literal (12-bit) 2nd word 2 1110 1110 00ff kkkk None
to FSRx 1st word 1111 0000 kkkk kkkk
MOVLB k Move literal to BSR<3:0> 1 0000 0001 0000 kkkk None
MOVLW k Move literal to WREG 1 0000 1110 kkkk kkkk None
MULLW k Multiply literal with WREG 1 0000 1101 kkkk kkkk None
RETLW k Return with literal in WREG 2 0000 1100 kkkk kkkk None
SUBLW k Subtract WREG from literal 1 0000 1000 kkkk kkkk C, DC, Z, OV, N
XORLW k Exclusive OR literal with 1 0000 1010 kkkk kkkk Z, N
WREG
DATA MEMORY ↔ PROGRAM MEMORY OPERATIONS
TBLRD* Table Read 2 0000 0000 0000 1000 None
TBLRD*+ Table Read with post-increment 0000 0000 0000 1001 None
TBLRD*- Table Read with post-decrement 0000 0000 0000 1010 None
TBLRD+* Table Read with pre-increment 0000 0000 0000 1011 None
TBLWT* Table Write 2 (5) 0000 0000 0000 1100 None
TBLWT*+ Table Write with post-increment 0000 0000 0000 1101 None
TBLWT*- Table Write with post-decrement 0000 0000 0000 1110 None
TBLWT+* Table Write with pre-increment 0000 0000 0000 1111 None
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’.
2: If this instruction is executed on the TMR0 register (and where applicable, d = 1), the prescaler will be cleared
if assigned.
3: 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.
4: Some instructions are 2-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.
5: If the table write starts the write cycle to internal memory, the write will continue until terminated.
Cycles: 1 Words: 1
Cycles: 2 Words: 1
BTFSC Bit Test File, Skip if Clear BTFSS Bit Test File, Skip if Set
Syntax: [ label ] BTFSC f,b[,a] Syntax: [ label ] BTFSS f,b[,a]
Operands: 0 ≤ f ≤ 255 Operands: 0 ≤ f ≤ 255
0≤b≤7 0≤b<7
a ∈ [0,1] 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: If bit ‘b’ in register ‘f’ is ‘0’, then the Description: If bit ‘b’ in register ‘f’ is ‘1’, then the
next instruction is skipped. next instruction is skipped.
If bit ‘b’ is ‘0’, then the next instruc- If bit ‘b’ is ‘1’, then the next instruc-
tion fetched during the current tion fetched during the current
instruction execution is discarded instruction execution is discarded
and a NOP is executed instead, mak- and a NOP is executed instead, mak-
ing this a two-cycle instruction. If ‘a’ ing this a two-cycle instruction. If ‘a’
is ‘0’, the Access Bank will be is ‘0’, the Access Bank will be
selected, overriding the BSR value. If selected, overriding the BSR value. If
‘a’ = 1, then the bank will be selected ‘a’ = 1, then the bank will be selected
as per the BSR value (default). as per the BSR value (default).
Words: 1 Words: 1
Cycles: 1(2) Cycles: 1(2)
Note: 3 cycles if skip and followed Note: 3 cycles if skip and followed
by a 2-word instruction. by a 2-word instruction.
Q Cycle Activity: Q Cycle Activity:
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
Decode Read Process Data No Decode Read Process Data No
register ‘f’ operation register ‘f’ operation
If skip: If skip:
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
No No No No No No No No
operation operation operation operation operation operation operation operation
If skip and followed by 2-word instruction: If skip and followed by 2-word instruction:
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
No No No No No No No No
operation operation operation operation operation operation operation operation
No No No No No No No No
operation operation operation operation operation operation operation operation
Cycles: 1 Words: 1
Description: Clears the contents of the specified Encoding: 0000 0000 0000 0100
register. If ‘a’ is ‘0’, the Access Description: CLRWDT instruction resets the
Bank will be selected, overriding Watchdog Timer. It also resets the
the BSR value. If ‘a’ = 1, then the postscaler of the WDT. Status bits
bank will be selected as per the TO and PD are set.
BSR value (default). Words: 1
Words: 1 Cycles: 1
Cycles: 1 Q Cycle Activity:
Q Cycle Activity: Q1 Q2 Q3 Q4
Q1 Q2 Q3 Q4 Decode No Process No
Decode Read Process Write operation Data operation
register ‘f’ Data register ‘f’
Example: CLRWDT
Example: CLRF FLAG_REG
Before Instruction
Before Instruction WDT Counter = ?
FLAG_REG = 0x5A After Instruction
After Instruction WDT Counter = 0x00
FLAG_REG = 0x00 WDT Postscaler = 0
TO = 1
PD = 1
Description: The contents of register ‘f’ are Encoding: 0110 001a ffff ffff
complemented. If ‘d’ is ‘0’, the Description: Compares the contents of data
result is stored in W. If ‘d’ is ‘1’, the memory location ‘f’ to the contents
result is stored back in register ‘f’ of W by performing an unsigned
(default). If ‘a’ is ‘0’, the Access subtraction.
Bank will be selected, overriding If ‘f’ = W, then the fetched instruc-
the BSR value. If ‘a’ = 1, then the tion is discarded and a NOP is
bank will be selected as per the executed instead, making this a
BSR value (default). two-cycle instruction. If ‘a’ is ‘0’, the
Words: 1 Access Bank will be selected, over-
riding the BSR value. If ‘a’ = 1, then
Cycles: 1 the bank will be selected as per the
Q Cycle Activity: BSR value (default).
Q1 Q2 Q3 Q4 Words: 1
Decode Read Process Write to Cycles: 1(2)
register ‘f’ Data destination
Note: 3 cycles if skip and followed
Example: COMF REG, W by a 2-word instruction.
Before Instruction Q Cycle Activity:
REG = 0x13
Q1 Q2 Q3 Q4
After Instruction
Decode Read Process No
REG = 0x13
register ‘f’ Data operation
W = 0xEC
If skip:
Q1 Q2 Q3 Q4
No No No No
operation operation operation operation
If skip and followed by 2-word instruction:
Q1 Q2 Q3 Q4
No No No No
operation operation operation operation
No No No No
operation operation operation operation
CPFSGT Compare f with W, skip if f > W CPFSLT Compare f with W, skip if f < W
Syntax: [ label ] CPFSGT f [,a] Syntax: [ label ] CPFSLT f [,a]
Operands: 0 ≤ f ≤ 255 Operands: 0 ≤ f ≤ 255
a ∈ [0,1] a ∈ [0,1]
Operation: (f) − (W), Operation: (f) – (W),
skip if (f) > (W) skip if (f) < (W)
(unsigned comparison) (unsigned comparison)
Status Affected: None Status Affected: None
Encoding: 0110 010a ffff ffff Encoding: 0110 000a ffff ffff
Description: Compares the contents of data Description: Compares the contents of data
memory location 'f' to the contents memory location ‘f’ to the contents
of the W by performing an of W by performing an unsigned
unsigned subtraction. subtraction.
If the contents of ‘f’ are greater than If the contents of ‘f’ are less than
the contents of WREG, then the the contents of W, then the fetched
fetched instruction is discarded and instruction is discarded and a NOP
a NOP is executed instead, making is executed instead, making this a
this a two-cycle instruction. If ‘a’ is two-cycle instruction. If ‘a’ is ‘0’, the
‘0’, the Access Bank will be Access Bank will be selected. If ’a’
selected, overriding the BSR value. is ‘1’, the BSR will not be
If ‘a’ = 1, then the bank will be overridden (default).
selected as per the BSR value Words: 1
(default).
Cycles: 1(2)
Words: 1 Note: 3 cycles if skip and followed
Cycles: 1(2) by a 2-word instruction.
Note: 3 cycles if skip and followed Q Cycle Activity:
by a 2-word instruction.
Q1 Q2 Q3 Q4
Q Cycle Activity: Decode Read Process No
Q1 Q2 Q3 Q4 register ‘f’ Data operation
Decode Read Process No If skip:
register ‘f’ Data operation Q1 Q2 Q3 Q4
If skip: No No No No
Q1 Q2 Q3 Q4 operation operation operation operation
No No No No If skip and followed by 2-word instruction:
operation operation operation operation Q1 Q2 Q3 Q4
If skip and followed by 2-word instruction: No No No No
Q1 Q2 Q3 Q4 operation operation operation operation
No No No No No No No No
operation operation operation operation operation operation operation operation
No No No No
operation operation operation operation Example: HERE CPFSLT REG
NLESS :
Example: HERE CPFSGT REG LESS :
NGREATER : Before Instruction
GREATER : PC = Address (HERE)
Before Instruction W = ?
PC = Address (HERE) After Instruction
W = ? If REG < W;
After Instruction PC = Address (LESS)
If REG ≥ W;
If REG > W; PC = Address (NLESS)
PC = Address (GREATER)
If REG ≤ W;
PC = Address (NGREATER)
Example 2:
Before Instruction
W = 0xCE
C = 0
DC = 0
After Instruction
W = 0x34
C = 1
DC = 0
Words: 2
Cycles: 2 (3)
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read Process No
register ‘f’ Data operation
(src)
Decode No No Write
operation operation register ‘f’
No dummy (dest)
read
Description: The eight-bit literal ‘k’ is loaded into Encoding: 0110 111a ffff ffff
W. Description: Move data from W to register ‘f’.
Words: 1 Location ‘f’ can be anywhere in the
256-byte bank. If ‘a’ is ‘0’, the
Cycles: 1 Access Bank will be selected, over-
Q Cycle Activity: riding the BSR value. If ‘a’ = 1, then
Q1 Q2 Q3 Q4 the bank will be selected as per the
Decode Read Process Write to W
BSR value (default).
literal ‘k’ Data Words: 1
Cycles: 1
Example: MOVLW 0x5A
Q Cycle Activity:
After Instruction Q1 Q2 Q3 Q4
W = 0x5A Decode Read Process Write
register ‘f’ Data register ‘f’
Cycles: 1
Example:
Q Cycle Activity:
Q1 Q2 Q3 Q4
None.
Decode Read Process Write
register ‘f’ Data register ‘f’
POP Pop Top of Return Stack PUSH Push Top of Return Stack
Syntax: [ label ] POP Syntax: [ label ] PUSH
Operands: None Operands: None
Operation: (TOS) → bit bucket Operation: (PC+2) → TOS
Status Affected: None Status Affected: None
Encoding: 0000 0000 0000 0110 Encoding: 0000 0000 0000 0101
Description: The TOS value is pulled off the Description: The PC+2 is pushed onto the top of
return stack and is discarded. The the return stack. The previous TOS
TOS value then becomes the previ- value is pushed down on the stack.
ous value that was pushed onto the This instruction allows to implement
return stack. a software stack by modifying TOS,
This instruction is provided to and then push it onto the return
enable the user to properly manage stack.
the return stack to incorporate a Words: 1
software stack.
Cycles: 1
Words: 1
Q Cycle Activity:
Cycles: 1
Q1 Q2 Q3 Q4
Q Cycle Activity: Decode PUSH PC+2 No No
Q1 Q2 Q3 Q4 onto return operation operation
Decode No POP TOS No stack
operation value operation
Example: PUSH
Example: POP Before Instruction
GOTO NEW
TOS = 0x00345A
Before Instruction PC = 0x000124
TOS = 0x0031A2
Stack (1 level down) = 0x014332 After Instruction
PC = 0x000126
After Instruction TOS = 0x000126
Stack (1 level down) = 0x00345A
TOS = 0x014332
PC = NEW
After Interrupt
PC = TOS Before Instruction
W = WS W = 0x07
BSR = BSRS
STATUS = STATUSS After Instruction
GIE/GIEH, PEIE/GIEL = 1
W = value of kn
RLNCF Rotate Left f (no carry) RRCF Rotate Right f through Carry
Syntax: [ label ] RLNCF f [,d [,a]] Syntax: [ label ] RRCF f [,d [,a]]
Operands: 0 ≤ f ≤ 255 Operands: 0 ≤ f ≤ 255
d ∈ [0,1] d ∈ [0,1]
a ∈ [0,1] a ∈ [0,1]
Operation: (f<n>) → dest<n+1>, Operation: (f<n>) → dest<n-1>,
(f<7>) → dest<0> (f<0>) → C,
Status Affected: N, Z (C) → dest<7>
Description: The contents of register ‘f’ are Encoding: 0011 00da ffff ffff
rotated one bit to the left. If ‘d’ is ‘0’, Description: The contents of register ‘f’ are
the result is placed in W. If ‘d’ is ‘1’, rotated one bit to the right through
the result is stored back in register the Carry Flag. If ‘d’ is ‘0’, the result
‘f’ (default). If ‘a’ is ‘0’, the Access is placed in W. If ‘d’ is ‘1’, the result
Bank will be selected, overriding is placed back in register ‘f’
the BSR value. If ‘a’ is ‘1’, then the (default). If ‘a’ is ‘0’, the Access
bank will be selected as per the Bank will be selected, overriding
BSR value (default). the BSR value. If ‘a’ is ‘1’, then the
register f
bank will be selected as per the
BSR value (default).
Words: 1 C register f
Cycles: 1
Words: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4 Cycles: 1
Decode Read Process Write to Q Cycle Activity:
register ‘f’ Data destination Q1 Q2 Q3 Q4
Decode Read Process Write to
Example: RLNCF REG register ‘f’ Data destination
Before Instruction
REG = 1010 1011 Example: RRCF REG, W
After Instruction Before Instruction
REG = 0101 0111 REG = 1110 0110
C = 0
After Instruction
REG = 1110 0110
W = 0111 0011
C = 0
SWAPF Swap f
Syntax: [ label ] SWAPF f [,d [,a]]
Operands: 0 ≤ f ≤ 255
d ∈ [0,1]
a ∈ [0,1]
Operation: (f<3:0>) → dest<7:4>,
(f<7:4>) → dest<3:0>
Status Affected: None
Encoding: 0011 10da ffff ffff
Description: The upper and lower nibbles of reg-
ister ‘f’ are exchanged. If ‘d’ is ‘0’,
the result is placed in W. If ‘d’ is ‘1’,
the result is placed in register ‘f’
(default). If ‘a’ is ‘0’, the Access
Bank will be selected, overriding
the BSR value. If ‘a’ is ‘1’, then the
bank will be selected as per the
BSR value (default).
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read Process Write to
register ‘f’ Data destination
† 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.
6.0V
5.5V
5.0V PIC18F2X20/4X20
4.5V
Voltage
4.2V
4.0V
3.5V
3.0V
2.5V
2.0V
40 MHz
Frequency
6.0V
5.5V
5.0V PIC18F2X20/4X20
4.5V
Voltage
4.2V
4.0V
3.5V
3.0V
2.5V
2.0V
25 MHz
Frequency
6.0V
5.5V
5.0V
4.5V PIC18LF2X20/4X20
Voltage
4.2V
4.0V
3.5V
3.0V
2.5V
2.0V
4 MHz 40 MHz
Frequency
Param
Symbol Characteristic Min Typ Max Units Conditions
No.
VDD Supply Voltage
D001 PIC18LF2X20/4X20 2.0 — 5.5 V HS, XT, RC and LP Osc mode
PIC18F2X20/4X20 4.2 — 5.5 V
D002 VDR RAM Data Retention 1.5 — — V
Voltage(1)
D003 VPOR VDD Start Voltage — — 0.7 V See section on Power-on Reset for details
to ensure internal
Power-on Reset signal
D004 SVDD VDD Rise Rate 0.05 — — V/ms See section on Power-on Reset for details
to ensure internal
Power-on Reset signal
VBOR Brown-out Reset Voltage
PIC18LF2X20/4X20 Industrial Low Voltage
D005 BORV1:BORV0 = 11 NA — NA V Reserved
BORV1:BORV0 = 10 2.50 2.72 2.94 V
BORV1:BORV0 = 01 3.88 4.22 4.56 V
BORV1:BORV0 = 00 4.18 4.54 4.90 V
D005 PIC18F2X20/4X20 Industrial
BORV1:BORV0 = 1x NA — NA V Not in operating voltage range of device
BORV1:BORV0 = 01 3.88 4.22 4.56 V
BORV1:BORV0 = 00 4.18 4.54 4.90 V
D005E PIC18F2X20/4X20 Extended
BORV1:BORV0 = 1x NA — NA V Not in operating voltage range of device
BORV1:BORV0 = 01 3.71 4.22 4.73 V
BORV1:BORV0 = 00 4.00 4.54 5.08 V
Legend: Shading of rows is to assist in readability of the table.
Note 1: This is the limit to which VDD can be lowered in Sleep mode, or during a device Reset, without losing RAM data.
Param
Device Typ Max Units Conditions
No.
Param
Device Typ Max Units Conditions
No.
Param
Device Typ Max Units Conditions
No.
Param
Device Typ Max Units Conditions
No.
Param
Device Typ Max Units Conditions
No.
Param
Device Typ Max Units Conditions
No.
Param
Device Typ Max Units Conditions
No.
Param
Device Typ Max Units Conditions
No.
Param
Device Typ Max Units Conditions
No.
Param
Symbol Characteristic Min Max Units Conditions
No.
VIL Input Low Voltage
I/O ports:
D030 with TTL buffer VSS 0.15 VDD V VDD < 4.5V
D030A — 0.8 V 4.5V ≤ VDD ≤ 5.5V
D031 with Schmitt Trigger buffer VSS 0.2 VDD V
RC3 and RC4 VSS 0.3 VDD V
D032 MCLR VSS 0.2 VDD V
D032A OSC1 and T1OSI VSS 0.2 VDD V LP, XT, HS, HSPLL
modes(1)
D033 OSC1 VSS 0.2 VDD V EC mode(1)
VIH Input High Voltage
I/O ports:
D040 with TTL buffer 0.25 VDD + 0.8V VDD V VDD < 4.5V
D040A 2.0 VDD V 4.5V ≤ VDD ≤ 5.5V
D041 with Schmitt Trigger buffer 0.8 VDD VDD V
RC3 and RC4 0.7 VDD VDD V
D042 MCLR 0.8 VDD VDD V
D042A OSC1 and T1OSI 1.6 VDD V LP, XT, HS, HSPLL
modes(1)
D043 OSC1 0.8 VDD VDD V EC mode(1)
IIL Input Leakage Current(2,3)
D060 I/O ports — ±0.2 µA VSS ≤ VPIN ≤ VDD,
Pin at high-impedance
D061 MCLR, RA4 — ±1.0 µA Vss ≤ VPIN ≤ VDD
D063 OSC1 — ±1.0 µA Vss ≤ VPIN ≤ VDD
IPU Weak Pull-up Current
D070 IPURB PORTB weak pull-up current 50 400 µA VDD = 5V, VPIN = VSS
Note 1: In RC oscillator configuration, the OSC1/CLKI pin is a Schmitt Trigger input. It is not recommended that the
PICmicro device be driven with an external clock while in RC mode.
2: 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.
3: Negative current is defined as current sourced by the pin.
4: Parameter is characterized but not tested.
Param
Symbol Characteristic Min Max Units Conditions
No.
VOL Output Low Voltage
D080 I/O ports — 0.6 V IOL = 8.5 mA, VDD = 4.5V,
-40°C to +85°C
D080A — 0.6 V IOL = 7.0 mA, VDD = 4.5V,
-40°C to +125°C
D083 OSC2/CLKO — 0.6 V IOL = 1.6 mA, VDD = 4.5V,
(RC mode) -40°C to +85°C
D083A — 0.6 V IOL = 1.2 mA, VDD = 4.5V,
-40°C to +125°C
VOH Output High Voltage(3)
D090 I/O ports VDD – 0.7 — V IOH = -3.0 mA, VDD = 4.5V,
-40°C to +85°C
D090A VDD – 0.7 — V IOH = -2.5 mA, VDD = 4.5V,
-40°C to +125°C
D092 OSC2/CLKO VDD – 0.7 — V IOH = -1.3 mA, VDD = 4.5V,
(RC mode) -40°C to +85°C
D092A VDD – 0.7 — V IOH = -1.0 mA, VDD = 4.5V,
-40°C to +125°C
D150 VOD Open-Drain High Voltage — 8.5 V RA4 pin
Capacitive Loading Specs
on Output Pins
D100(4) COSC2 OSC2 pin — 15 pF In XT, HS and LP modes
when external clock is
used to drive OSC1
D101 CIO All I/O pins and OSC2 — 50 pF To meet the AC Timing
(in RC mode) Specifications
D102 CB SCL, SDA — 400 pF In I2C mode
Note 1: In RC oscillator configuration, the OSC1/CLKI pin is a Schmitt Trigger input. It is not recommended that the
PICmicro device be driven with an external clock while in RC mode.
2: 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.
3: Negative current is defined as current sourced by the pin.
4: Parameter is characterized but not tested.
Param
Sym Characteristics Min Typ Max Units Comments
No.
D300 VIOFF Input Offset Voltage — ± 5.0 ± 10 mV
D301 VICM Input Common Mode Voltage* 0 — VDD – 1.5 V
D302 CMRR Common Mode Rejection Ratio* 55 — — dB
300 TRESP Response Time(1)* — 150 400 ns PIC18FXX20
300A 600 ns PIC18LFXX20
301 TMC2OV Comparator Mode Change to — — 10 µs
Output Valid*
* These parameters are characterized but not tested.
Note 1: Response time measured with one comparator input at (VDD – 1.5)/2, while the other input transitions
from VSS to VDD.
Param
Sym Characteristics Min Typ Max Units Comments
No.
D310 VRES Resolution VDD/24 — VDD/32 LSb
D311 VRAA Absolute Accuracy — — 1/2 LSb Low Range (VRR = 1)
— — 1/2 LSb High Range (VRR = 0)
D312 VRUR Unit Resistor Value (R)* — 2k — Ω
310 TSET Settling Time(1)* — — 10 µs
* These parameters are characterized but not tested.
Note 1: Settling time measured while VRR = 1 and VR<3:0> transitions from ‘0000’ to ‘1111’.
VDD
(LVDIF can be
VLVD cleared in software)
(LVDIF set by hardware)
LVDIF
Param
Symbol Characteristic Min Typ† Max Units Conditions
No.
D420 LVD Voltage on VDD Transition High to Low Industrial
PIC18LF2X20/4X20 LVDL<3:0> = 0000 N/A N/A N/A V Reserved
LVDL<3:0> = 0001 N/A N/A N/A V Reserved
LVDL<3:0> = 0010 2.15 2.26 2.37 V
LVDL<3:0> = 0011 2.33 2.45 2.58 V
LVDL<3:0> = 0100 2.43 2.55 2.68 V
LVDL<3:0> = 0101 2.63 2.77 2.91 V
LVDL<3:0> = 0110 2.73 2.87 3.01 V
LVDL<3:0> = 0111 2.91 3.07 3.22 V
LVDL<3:0> = 1000 3.20 3.36 3.53 V
LVDL<3:0> = 1001 3.39 3.57 3.75 V
LVDL<3:0> = 1010 3.49 3.67 3.85 V
LVDL<3:0> = 1011 3.68 3.87 4.07 V
LVDL<3:0> = 1100 3.87 4.07 4.28 V
LVDL<3:0> = 1101 4.06 4.28 4.49 V
LVDL<3:0> = 1110 4.37 4.60 4.82 V
D420 LVD Voltage on VDD Transition High to Low Industrial
PIC18F2X20/4X20 LVDL<3:0> = 1011 3.68 3.87 4.07 V
LVDL<3:0> = 1100 3.87 4.07 4.28 V
LVDL<3:0> = 1101 4.06 4.28 4.49 V
LVDL<3:0> = 1110 4.37 4.60 4.82 V
D420E LVD Voltage on VDD Transition High to Low Extended
PIC18F2X20/4X20 LVDL<3:0> = 1011 3.48 3.87 4.25 V
LVDL<3:0> = 1100 3.66 4.07 4.48 V
LVDL<3:0> = 1101 3.85 4.28 4.70 V
LVDL<3:0> = 1110 4.14 4.60 5.05 V
Legend: Shading of rows is to assist in readability of the table.
† Production tested at TAMB = 25°C. Specifications over temperature limits ensured by characterization.
VDD/2
RL Pin CL
VSS
CL
Pin
RL = 464Ω
VSS CL = 50 pF for all pins except OSC2/CLKO
and including D and E outputs as ports
Q4 Q1 Q2 Q3 Q4 Q1
OSC1
1 3 3 4 4
2
CLKO
Param
Device Min Typ Max Units Conditions
No.
INTOSC Accuracy @ Freq = 8 MHz, 4 MHz, 2 MHz, 1 MHz, 500 kHz, 250 kHz, 125 kHz(1)
F14 PIC18LF2220/2320/4220/4320 -2 +/-1 2 % +25°C VDD = 2.7-3.3V
F15 -5 — 5 % -10°C to +85°C VDD = 2.7-3.3V
F16 -10 — 10 % -40°C to +85°C VDD = 2.7-3.3V
F17 PIC18F2220/2320/4220/4320 -2 +/-1 2 % +25°C VDD = 4.5-5.5V
F18 -5 — 5 % -10°C to +85°C VDD = 4.5-5.5V
F19 -10 — 10 % -40°C to +85°C VDD = 4.5-5.5V
INTRC Accuracy @ Freq = 31 kHz(2)
F20 PIC18LF2220/2320/4220/4320 26.562 — 35.938 kHz -40°C to +85°C VDD = 2.7-3.3V
F21 PIC18F2220/2320/4220/4320 26.562 — 35.938 kHz -40°C to +85°C VDD = 4.5-5.5V
Legend: Shading of rows is to assist in readability of the table.
Note 1: Frequency calibrated at 25°C. OSCTUNE register can be used to compensate for temperature drift.
2: INTRC frequency after calibration.
3: Change of INTRC frequency as VDD changes.
OSC1
10 11
CLKO
13 12
14 19 18
16
I/O pin
(Input)
17 15
20, 21
Note: Refer to Figure 26-5 for load conditions.
VDD
MCLR
30
Internal
POR
33
PWRT
Time-out
32
OSC
Time-out
Internal
Reset
Watchdog
Timer
Reset
31
34 34
I/O pins
BVDD
VDD
35
VBGAP = 1.2V
VIRVST
Enable Internal
Reference Voltage
Internal Reference
Voltage Stable 36
TABLE 26-10: RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER, POWER-UP TIMER
AND BROWN-OUT RESET REQUIREMENTS
Param.
Symbol Characteristic Min Typ Max Units Conditions
No.
T0CKI
40 41
42
T1OSO/T1CKI
45 46
47 48
TMR0 or
TMR1
CCPx
(Capture Mode)
50 51
52
CCPx
(Compare or PWM Mode)
53 54
RE2/CS
RE0/RD
RE1/WR
65
RD7:RD0
62
64
63
Note: Refer to Figure 26-5 for load conditions.
SS
70
SCK
(CKP = 0)
71 72
78 79
SCK
(CKP = 1)
79 78
80
75, 76
74
73
Note: Refer to Figure 26-5 for load conditions.
SS
81
SCK
(CKP = 0)
71 72
79
73
SCK
(CKP = 1)
80
78
75, 76
74
Note: Refer to Figure 26-5 for load conditions.
SS
70
SCK
(CKP = 0) 83
71 72
78 79
SCK
(CKP = 1)
80 79 78
75, 76 77
TABLE 26-16: EXAMPLE SPI MODE REQUIREMENTS (SLAVE MODE TIMING, CKE = 0)
Param
Symbol Characteristic Min Max Units Conditions
No.
70
SCK 83
(CKP = 0)
71 72
SCK
(CKP = 1)
80
75, 76 77
SDI
MSb In bit 6 - - - -1 LSb In
74
Note: Refer to Figure 26-5 for load conditions.
SCL
91 93
90 92
SDA
Start Stop
Condition Condition
91 92
SDA
In
110
109 109
SDA
Out
91 THD:STA Start Condition Hold 100 kHz mode 4.0 — µs After this period, the first clock pulse is
Time 400 kHz mode 0.6 — µs generated
SCL
91 93
90 92
SDA
Start Stop
Condition Condition
SDA
Out
RC6/TX/CK
pin 121 121
RC7/RX/DT
pin
120
122
Note: Refer to Figure 26-5 for load conditions.
RC6/TX/CK
pin 125
RC7/RX/DT
pin
126
BSF ADCON0, GO
(Note 2)
131
Q4
130
A/D CLK 132
ADIF TCY
GO DONE
SAMPLING STOPPED
SAMPLE
Note 1: If the A/D clock source is selected as RC, a time of TCY is added before the A/D clock starts. This allows the SLEEP instruction to be
executed.
2: This is a minimal RC delay (typically 100 ns), which also disconnects the holding capacitor from the analog input.
130 TAD A/D Clock Period PIC18FXX20 1.6 20(2) µs TOSC based, VREF ≥ 3.0V
(2)
PIC18LFXX20 3.0 20 µs TOSC based, VREF full range
PIC18FXX20 2.0 6.0 µs A/D RC mode
PIC18LFXX20 3.0 9.0 µs A/D RC mode
131 TCNV Conversion Time 11 12 TAD
(not including acquisition time)(1)
Note 1: ADRES register may be read on the following TCY cycle.
2: The time of the A/D clock period is dependent on the device frequency and the TAD clock divider.
FIGURE 27-1: TYPICAL IDD vs. FOSC OVER VDD PRI_RUN, EC MODE, +25°C
0.5
5.0V
0.3
4.5V
IDD (mA)
4.0V
0.2
3.5V
3.0V
0.1 2.5V
2.0V
0.0
0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20
FOSC (MHz)
FIGURE 27-2: MAXIMUM IDD vs. FOSC OVER VDD PRI_RUN, EC MODE, -40°C TO +85°C
0.7
5.0V
0.5
4.5V
0.4
IDD (mA)
4.0V
0.3
3.5V
3.0V
0.2
2.5V
0.1
2.0V
0.0
0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20
FOSC (MHz)
5.0V
0.5
4.5V
0.4
IDD (mA)
4.0V
0.3
3.5V
3.0V
0.2
2.5V
0.1
2.0V
0.0
0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20
FOSC (MHz)
FIGURE 27-4: TYPICAL IDD vs. FOSC OVER VDD PRI_RUN, EC MODE, +25°C
2.0
1.6
5.5V
1.4
5.0V
1.2
4.5V
IDD (mA)
1.0
4.0V
0.8 3.5V
3.0V
0.6
2.5V
0.4 2.0V
0.2
0.0
1.0 1.5 2.0 2.5 3.0 3.5 4.0
FOSC (MHz)
5.5V
5.0V
1.5
IDD (mA)
4.5V
4.0V
1.0
3.5V
3.0V
2.5V
0.5
2.0V
0.0
1.0 1.5 2.0 2.5 3.0 3.5 4.0
FOSC (MHz)
FIGURE 27-6: TYPICAL IDD vs. FOSC OVER VDD PRI_RUN, EC MODE, +25°C
16
5.5V
12
5.0V
10
4.5V
IDD (mA)
8
4.0V
3.5V
3.0V
2
2.5V
2.0V
0
4 8 12 16 20 24 28 32 36 40
FOSC (MHz)
4.0V
10
4.5V
IDD (mA)
3.5V
6
4
3.0V
2
2.5V
2.0V
0
4 8 12 16 20 24 28 32 36 40
FOSC (MHz)
FIGURE 27-8: TYPICAL IDD vs. FOSC OVER VDD PRI_IDLE, EC MODE, +25°C
0.035
5.0V
0.025
4.5V
0.020
4.0V
IDD (mA)
3.5V
0.015
3.0V
2.5V
0.010
2.0V
0.005
0.000
0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20
FOSC (MHz)
0.035
5.0V
0.030
4.5V
0.025
IDD (mA)
4.0V
0.020
3.5V
3.0V
0.015
2.5V
0.010 2.0V
0.005
0.000
0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20
FOSC (MHz)
FIGURE 27-10: MAXIMUM IDD vs. FOSC OVER VDD PRI_IDLE, EC MODE, -40°C TO +125°C
0.100
0.070 5.0V
0.060
4.5V
IDD (mA)
0.050 4.0V
3.5V
0.040
3.0V
0.030
2.5V
0.020 2.0V
0.010
0.000
0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20
FOSC (MHz)
600
5.5V
5.0V
400
4.5V
IDD (µA)
4.0V
300
3.5V
3.0V
200
2.5V
2.0V
100
0
1.0 1.5 2.0 2.5 3.0 3.5 4.0
FOSC (MHz)
FIGURE 27-12: MAXIMUM IDD vs. FOSC OVER VDD PRI_IDLE, EC MODE, -40°C TO +125°C
600
5.0V
400
4.5V
4.0V
IDD (µA)
300
3.5V
3.0V
200
2.5V
2.0V
100
0
1.0 1.5 2.0 2.5 3.0 3.5 4.0
FOSC (MHz)
4.5
5.5V 5.0V
4.0
3.5
IDD (mA)
4.5V
3.0
2.5
4.0V
2.0
3.5V
1.5
1.0
3.0V
0.5
2.5V
2.0V
0.0
4 8 12 16 20 24 28 32 36 40
FOSC (MHz)
FIGURE 27-14: MAXIMUM IDD vs. FOSC OVER VDD PRI_IDLE, EC MODE, -40°C TO +125°C
6.0
5.5
Typical: statistical mean @ 25°C 5.5V
5.0 Maximum: mean + 3σ (-40°C to +125°C)
Minimum: mean – 3σ (-40°C to +125°C) 5.0V
4.5
4.0
4.5V
3.5
IDD (mA)
3.0
4.0V
2.5
2.0
3.5V
1.5
1.0
3.0V
0.5
2.5V
2.0V
0.0
4 8 12 16 20 24 28 32 36 40
FOSC (MHz)
1500
4 MHz
1000
2 MHz
500
1 MHz
125 kHz
0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 27-16: MAXIMUM IPD vs. VDD (-40°C TO +125°C), 125 kHz TO 8 MHz RC_RUN,
ALL PERIPHERALS DISABLED
3500
8 MHz
3000
250 kHz and 500 kHz curves are
bounded by 125 kHz and 1 MHz
curves.
2500
Typical: statistical mean @ 25°C
Maximum: mean + 3σ (-40°C to +125°C)
Minimum: mean – 3σ (-40°C to +125°C)
2000
IPD (µA)
4 MHz
1500
1000
2 MHz
500 1 MHz
125 kHz
0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
Max (+125°C)
Max (+85°C)
Typ (+25°C)
IPD (µA)
10
1
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 27-18: TYPICAL IPD vs. VDD (+25°C), 125 kHz TO 8 MHz RC_IDLE MODE,
ALL PERIPHERALS DISABLED
800
750
500
2 MHz
IPD (µA)
1 MHz
450
125 kHz
400
350
300
250
200
150
100
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
500
IPD (µA)
450
400
350
300
Typical: statistical mean @ 25°C
250
Maximum: mean + 3σ (-40°C to +125°C)
Minimum: mean – 3σ (-40°C to +125°C)
200
150
100
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 27-20: TYPICAL AND MAXIMUM IPD vs. VDD (-40°C TO +125°C), 31.25 kHz RC_IDLE,
ALL PERIPHERALS DISABLED
100
Max (+125°C)
Max (+85°C)
IPD (µA)
10
Typ (+25°C)
1
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
60
Max (+70°C)
50
IPD (µA)
40
Typ (+25°C)
30
20
10
0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
16
14
Max (+70°C)
12
IPD (µA)
10
Typ (+25°C)
0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
100
Max (+125°C)
10
Max (+85°C)
1
IPD (µA)
0.1
Typ (+25°C)
0.01
Typical: statistical mean @ 25°C
Maximum: mean + 3σ (-40°C to +125°C)
Minimum: mean – 3σ (-40°C to +125°C)
0.001
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 27-24: VOH vs. IOH OVER TEMPERATURE (-40°C TO +125°C), VDD = 3.0V
3.0
2.5
2.0
Max (+125°C)
VOH (V)
1.5
Typ (+25°C)
Min (+125°C)
1.0
0.5
0.0
0 5 10 15 20 25
IOH (-mA)
4.5
Max (+125°C)
4.0
Typ (+25°C)
3.5
3.0
VOH (V)
2.5
Min (+125°C)
2.0
1.5
1.0
0.5
0.0
0 5 10 15 20 25
IOH (-mA)
Max (+125°C)
2.5
Max (+85°C)
2.0
VOL (V)
1.5
Typ (+25°C)
1.0
0.5
Min (+125°C)
0.0
0 5 10 15 20 25
IOL (-mA)
0.9
Max (+125°C)
0.8
0.7
0.6
Max (+85°C)
VOL (V)
0.5
0.4
Typ (+25°C)
0.3
0.2
Min (+125°C)
0.1
0.0
0 5 10 15 20 25
IOL (-mA)
5.0
4.5
3.5
3.0
Typ (+25°C)
IPD (µA)
2.5
2.0
1.5
0.5
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
4.0
Max (-40°C)
3.5
3.0
2.5
∆IPD (µA)
Typ (+25°C)
2.0
1.5
0.5
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 27-30: ∆IPD WDT, -40°C TO +125°C SLEEP MODE, ALL PERIPHERALS DISABLED
14
10
Max (+125°C)
8
∆IPD (µA)
Max (+85°C)
4
Typ (+25°C)
0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
45
Typical: statistical mean @ 25°C
Maximum: mean + 3σ (-40°C to +125°C)
40 Minimum: mean – 3σ (-40°C to +125°C)
Max (+125°C)
35
Max (+85°C)
30
IPD (µA)
Typ (+25°C)
25
20
15
10
Low-Voltage Detection Range
5
FIGURE 27-32: ∆IPD BOR vs. VDD, -40°C TO +125°C SLEEP MODE,
BOR ENABLED AT 2.00V-2.16V
40
30
25
Typ (+25°C)
IPD (µA)
20
15
10
5
Device is Operating
0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
10
Max (+125°C)
1
IPD (µA)
Max (+85°C)
0.1
0.01
Typical: statistical mean @ 25°C
Maximum: mean + 3σ (-40°C to +125°C)
Typ (+25°C)
Minimum: mean – 3σ (-40°C to +125°C)
0.001
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 27-34: AVERAGE FOSC vs. VDD FOR VARIOUS R'S EXTERNAL RC MODE,
C = 20 pF, TEMPERATURE = +25°C
5.0
4.0
5.1K
3.5
3.0
Freq (MHz)
2.5
10K
2.0
1.5
1.0
33K
0.5
100K
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
1.8
1.6
5.1K
1.4
1.2
Freq (MHz)
1.0
10K
0.8
0.6
0.4
33K
0.2
100K
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 27-36: AVERAGE FOSC vs. VDD FOR VARIOUS R'S EXTERNAL RC MODE,
C = 300 pF, TEMPERATURE = +25°C
0.8
0.7
0.6
0.5
5.1K
Freq (MHz)
0.4
0.3
10K
0.2
0.1
33K
100K
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
XXXXXXXXXXXXXXXXX PIC18F2220-I/SP
XXXXXXXXXXXXXXXXX 0310017
YYWWNNN
XXXXXXXXXXXXXXXXXXXX PIC18F2320-E/SO
XXXXXXXXXXXXXXXXXXXX 0310017
XXXXXXXXXXXXXXXXXXXX
YYWWNNN
XXXXXXXXXXXXXXXXXX PIC18F4220-I/P
XXXXXXXXXXXXXXXXXX 0310017
XXXXXXXXXXXXXXXXXX
YYWWNNN
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.
* Standard PICmicro device marking consists of Microchip part number, year code, week code, and
traceability code. For PICmicro device marking beyond this, certain price adders apply. Please check
with your Microchip Sales Office. For QTP devices, any special marking adders are included in QTP
price.
XXXXXXXXXX PIC18F4320
XXXXXXXXXX -I/PT
XXXXXXXXXX 0310017
YYWWNNN
XXXXXXXXXX PIC18F4220
XXXXXXXXXX -I/ML
XXXXXXXXXX 0310017
YYWWNNN
2
n 1 α
E A2
L
c
β A1 B1
eB B p
E
E1
p
B
2
n 1
h
α
45°
c
A A2
φ
β L A1
E1
2 α
n 1
A A2
L
c
β B1
A1
eB B p
E
E1
#leads=n1
D1 D
2
1
B
n
CH x 45 °
α
A
φ
β A1 A2
L
(F)
E EXPOSED
METAL
PAD
D D2
2 B
1
n PIN 1
OPTIONAL PIN 1
INDEX ON E2
INDEX ON
EXPOSED PAD L
TOP MARKING
(PROFILE MAY VARY)
TOP VIEW BOTTOM VIEW
A
A1
(A3)
From: Name
Company
Address
City / State / ZIP / Country
Telephone: (_______) _________ - _________ FAX: (______) _________ - _________
Application (optional):
Would you like a reply? Y N
Questions:
2. How does this document meet your hardware and software development needs?
3. Do you find the organization of this document easy to follow? If not, why?
4. What additions to the document do you think would enhance the structure and subject?
5. What deletions from the document could be made without affecting the overall usefulness?
PIC18LF2220/2320/4220/4320(1),
PIC18LF2220/2320/4220/4320T(1,2);
VDD range 2.0V to 5.5V