Professional Documents
Culture Documents
Data Sheet
28/40/44-Pin 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.
PIC18F2420
PIC18F2520
RA4/T0CKI/C1OUT 6 23 RB2/INT2/AN8
RA5/AN4/SS/HLVDIN/C2OUT 7 22 RB1/INT1/AN10
VSS 8 21 RB0/INT0/FLT0/AN12
OSC1/CLKI/RA7 9 20 VDD
OSC2/CLKO/RA6 10 19 VSS
RC0/T1OSO/T13CKI 11 18 RC7/RX/DT
RC1/T1OSI/CCP2(1) 12 17 RC6/TX/CK
RC2/CCP1 13 16 RC5/SDO
RC3/SCK/SCL 14 15 RC4/SDI/SDA
MCLR/VPP/RE3
RB5/KBI1/PGM
RB4KBI0/AN11
RB7/KBI3/PGD
RB6/KBI2/PGC
28-Pin QFN
RA1/AN1
RA0/AN0
28 27 26 25 24 23 22
RA2/AN2/VREF-/CVREF 1 21 RB3/AN9/CCP2(1)
RA3/AN3/VREF+ 2 20 RB2/INT2/AN8
RA4/T0CKI/C1OUT 3 PIC18F2420 19 RB1/INT1/AN10
RA5/AN4/SS/HLVDIN/C2OUT 4 18 RB0/INT0/FLT0/AN12
VSS
PIC18F2520
5 17 VDD
OSC1/CLKI/RA7 6 16 VSS
OSC2/CLKO/RA6 7 15 RC7/RX/DT
8 9 10 11 12 13 14
RC5/SDO
RC0/T1OSO/T13CKI
RC4/SDI/SDA
RC1/T1OSI/CCP2(1)
RC2/CCP1
RC3/SCK/SCL
RC6/TX/CK
40-Pin 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/KBI0/AN11
RA3/AN3/VREF+ 5 36 RB3/AN9/CCP2(1)
RA4/T0CKI/C1OUT 6 35 RB2/INT2/AN8
RA5/AN4/SS/HLVDIN/C2OUT 7 34 RB1/INT1/AN10
RE0/RD/AN5 8 RB0/INT0/FLT0/AN12
PIC18F4420
PIC18F4520
33
RE1/WR/AN6 9 32 VDD
RE2/CS/AN7 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/T13CKI 15 26 RC7/RX/DT
RC1/T1OSI/CCP2(1) 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
RC1/T1OSI/CCP2(1)
44-pin 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/T13CKI
RD5/PSP5/P1B 3 31 OSC2/CLKO/RA6
RD6/PSP6/P1C 4 30 OSC1/CLKI/RA7
RD7/PSP7/P1D 5 PIC18F4420 29 VSS
VSS 6 28 VDD
VDD 7
PIC18F4520 27 RE2/CS/AN7
RB0/INT0/FLT0/AN12 8 26 RE1/WR/AN6
RB1/INT1/AN10 9 25 RE0/RD/AN5
RB2/INT2/AN8 10 24 RA5/AN4/SS/HLVDIN/C2OUT
RB3/AN9/CCP2(1) 11 12 23 RA4/T0CKI/C1OUT
13
14
15
16
17
18
19
20
21
22
RB4/KBI0/AN11
RB5/KBI1/PGM
MCLR/VPP/RE3
RA0/AN0
RA1/AN1
NC
NC
RB6/KBI2/PGC
RB7/KBI3/PGD
RA3/AN3/VREF+
RA2/AN2/VREF-/CVREF
RC1/T1OSI/CCP2(1)
RC0/T1OSO/T13CKI
RC2/CCP1/P1A
RC3/SCK/SCL
RC4/SDI/SDA
RC6/TX/CK
RD3/PSP3
RD2/PSP2
RD1/PSP1
RD0/PSP0
RC5/SDO
44-pin QFN
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 PIC18F4420 29 VDD
VSS 6 28 VDD
VDD 7 PIC18F4520 27 RE2/CS/AN7
VDD 8 26 RE1/WR/AN6
RB0/INT0/FLT0/AN12 9 25 RE0/RD/AN5
RB1/INT1/AN10 10 24 RA5/AN4/SS/HLVDIN/C2OUT
RB2/INT2/AN8 11 23 RA4/T0CKI/C1OUT
12
13
14
15
16
17
18
19
20
21
22
RA2/AN2/VREF-/CVREF
RB3/AN9/CCP2(1)
RB5/KBI1/PGM
RB4/KBI0/AN11
MCLR/VPP/RE3
RA0/AN0
RA1/AN1
NC
RB6/KBI2/PGC
RB7/KBI3/PGD
RA3/AN3/VREF+
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)
When contacting a sales office, please specify which device, revision of silicon and data sheet (include literature number) you are
using.
8
Instruction State Machine
Decode and Control Signals
Control
PRODH PRODL
PORTC
8 x 8 Multiply RC0/T1OSO/T13CKI
3 8 RC1/T1OSI/CCP2(1)
RC2/CCP1
BITOP W RC3/SCK/SCL
8 8 8
RC4/SDI/SDA
Internal RC5/SDO
OSC1(3) Power-up RC6/TX/CK
Oscillator 8 8
Block Timer RC7/RX/DT
(3) Oscillator
OSC2 ALU<8>
INTRC Start-up Timer
T1OSI Oscillator Power-on 8
Reset
8 MHz
T1OSO Oscillator Watchdog
Timer
Precision
Single-Supply Brown-out Band Gap
MCLR(2) PORTE
Programming Reset Reference
In-Circuit Fail-Safe
VDD, VSS Debugger Clock Monitor
MCLR/VPP/RE3(2)
BOR Data
EEPROM Timer0 Timer1 Timer2 Timer3
HLVD
ADC
Comparator CCP1 CCP2 MSSP EUSART 10-Bit
Note 1: CCP2 is multiplexed with RC1 when Configuration bit, CCP2MX, is set, or RB3 when CCP2MX is not set.
2: RE3 is only available when MCLR functionality is disabled.
3: OSC1/CLKI and OSC2/CLKO are only available in select oscillator modes and when these pins are not being used as digital I/O.
Refer to Section 2.0 “Oscillator Configurations” for additional information.
ROM Latch
Address PORTC
Instruction Bus <16> Decode RC0/T1OSO/T13CKI
RC1/T1OSI/CCP2(1)
RC2/CCP1/P1A
IR
RC3/SCK/SCL
RC4/SDI/SDA
8 RC5/SDO
State Machine RC6/TX/CK
Instruction
Decode and Control Signals RC7/RX/DT
Control
PRODH PRODL
8 x 8 Multiply
3 8 PORTD
RD0/PSP0 :RD4/PSP4
BITOP W
8 RD5/PSP5/P1B
8 8
RD6/PSP6/P1C
OSC1(3) Internal RD7/PSP7/P1D
Oscillator Power-up
Timer 8 8
Block
(3) Oscillator
OSC2 ALU<8>
INTRC Start-up Timer
T1OSI Oscillator Power-on 8
Reset
8 MHz
T1OSO Oscillator Watchdog PORTE
Timer
Precision RE0/RD/AN5
Single-Supply Brown-out Band Gap RE1/WR/AN6
MCLR(2)
Programming Reset Reference RE2/CS/AN7
In-Circuit Fail-Safe MCLR/VPP/RE3(2)
VDD, VSS Debugger Clock Monitor
BOR Data
EEPROM Timer0 Timer1 Timer2 Timer3
HLVD
ADC
Comparator ECCP1 CCP2 MSSP EUSART 10-Bit
Note 1: CCP2 is multiplexed with RC1 when Configuration bit, CCP2MX, is set, or RB3 when CCP2MX is not set.
2: RE3 is only available when MCLR functionality is disabled.
3: OSC1/CLKI and OSC2/CLKO are only available in select oscillator modes and when these pins are not being used as digital I/O.
Refer to Section 2.0 “Oscillator Configurations” for additional information.
CEXT Loop
PIC18FXXXX Filter
VSS
OSC2/CLKO
FOSC/4
÷4 VCO
Recommended values: 3 kΩ ≤ REXT ≤ 100 kΩ SYSCLK
MUX
CEXT > 20 pF
CEXT
PIC18FXXXX
VSS
RA6 I/O (OSC2)
These features are discussed in greater detail in Unlike HSPLL mode, the PLL is controlled through
Section 23.0 “Special Features of the CPU”. software. The control bit, PLLEN (OSCTUNE<6>), is
used to enable or disable its operation.
The clock source frequency (INTOSC direct, INTRC
direct or INTOSC postscaler) is selected by configuring The PLL is available when the device is configured to
the IRCF bits of the OSCCON register (page 30). use the internal oscillator block as its primary clock
source (FOSC<3:0> = 1001 or 1000). Additionally, the
2.6.1 INTIO MODES PLL will only function when the selected output fre-
quency is either 4 MHz or 8 MHz (OSCCON<6:4> = 111
Using the internal oscillator as the clock source elimi- or 110). If both of these conditions are not met, the PLL
nates the need for up to two external oscillator pins, is disabled.
which can then be used for digital I/O. Two distinct
configurations are available: The PLLEN control bit is only functional in those inter-
nal oscillator modes where the PLL is available. In all
• In INTIO1 mode, the OSC2 pin outputs FOSC/4, other modes, it is forced to ‘0’ and is effectively
while OSC1 functions as RA7 for digital input and unavailable.
output.
• In INTIO2 mode, OSC1 functions as RA7 and 2.6.5 INTOSC FREQUENCY DRIFT
OSC2 functions as RA6, both for digital input and
The factory calibrates the internal oscillator block
output.
output (INTOSC) for 8 MHz. However, this frequency
may drift as VDD or temperature changes, which can
2.6.2 INTOSC OUTPUT FREQUENCY
affect the controller operation in a variety of ways. It is
The internal oscillator block is calibrated at the factory possible to adjust the INTOSC frequency by modifying
to produce an INTOSC output frequency of 8.0 MHz. the value in the OSCTUNE register. This has no effect
The INTRC oscillator operates independently of the on the INTRC clock source frequency.
INTOSC source. Any changes in INTOSC across Tuning the INTOSC source requires knowing when to
voltage and temperature are not necessarily reflected make the adjustment, in which direction it should be
by changes in INTRC and vice versa. made, and in some cases, how large a change is
needed. Three compensation techniques are discussed
2.6.3 OSCTUNE REGISTER in Section 2.6.5.1 “Compensating with the
The internal oscillator’s output has been calibrated at EUSART”, Section 2.6.5.2 “Compensating with the
the factory but can be adjusted in the user’s applica- Timers” and Section 2.6.5.3 “Compensating with the
tion. This is done by writing to the OSCTUNE register CCP Module in Capture Mode”, but other techniques
(Register 2-1). may be used.
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: Available only in certain oscillator configurations; otherwise, this bit is unavailable and reads as ‘0’. See
Section 2.6.4 “PLL in INTOSC Modes” for details.
2.6.5.1 Compensating with the EUSART 2.6.5.3 Compensating with the CCP Module
An adjustment may be required when the EUSART in Capture Mode
begins to generate framing errors or receives data with A CCP module can use free-running Timer1 (or
errors while in Asynchronous mode. Framing errors Timer3), clocked by the internal oscillator block and an
indicate that the device clock frequency is too high. To external event with a known period (i.e., AC power fre-
adjust for this, decrement the value in OSCTUNE to quency). The time of the first event is captured in the
reduce the clock frequency. On the other hand, errors CCPRxH:CCPRxL registers and is recorded for use
in data may suggest that the clock speed is too low. To later. When the second event causes a capture, the
compensate, increment OSCTUNE to increase the time of the first event is subtracted from the time of the
clock frequency. second event. Since the period of the external event is
known, the time difference between events can be
2.6.5.2 Compensating with the Timers calculated.
This technique compares device clock speed to some If the measured time is much greater than the calcu-
reference clock. Two timers may be used; one timer is lated time, the internal oscillator block is running too
clocked by the peripheral clock, while the other is fast; to compensate, decrement the OSCTUNE register.
clocked by a fixed reference source, such as the If the measured time is much less than the calculated
Timer1 oscillator. time, the internal oscillator block is running too slow; to
Both timers are cleared, but the timer clocked by the compensate, increment the OSCTUNE register.
reference generates interrupts. When an interrupt
occurs, the internally clocked timer is read and both
timers are cleared. If the internally clocked timer value
is greater than expected, then the internal oscillator
block is running too fast. To adjust for this, decrement
the OSCTUNE register.
PIC18F2420/2520/4420/4520
Primary Oscillator LP, XT, HS, RC, EC
OSC2
T1OSO
T1OSCEN
Enable
T1OSI Oscillator OSCCON<6:4> Internal Oscillator
OSCCON<6:4> 8 MHz CPU
111
4 MHz
Internal 110
Oscillator 2 MHz IDLEN
101
Block Clock
Postscaler
1 MHz
8 MHz Control
MUX
100
Source 500 kHz
8 MHz 011
(INTOSC) 250 kHz
INTRC 010 FOSC<3:0> OSCCON<1:0>
Source 125 kHz
001
1 31 kHz Clock Source Option
31 kHz (INTRC) 000 for Other Modules
0
OSCTUNE<7>
WDT, PWRT, FSCM
and Two-Speed Start-up
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
T1OSI 1 2 3 n-1 n
CPU
Clock
Peripheral
Clock
Program
Counter PC PC + 2 PC + 4
FIGURE 3-2: TRANSITION TIMING FROM SEC_RUN MODE TO PRI_RUN MODE (HSPLL)
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3
T1OSI
OSC1
TOST(1) TPLL(1)
1 2 n-1 n
PLL Clock
Output
Clock
Transition(2)
CPU Clock
Peripheral
Clock
Program PC PC + 2 PC + 4
Counter
Note1: TOST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
2: Clock transition typically occurs within 2-4 TOSC.
3.2.3 RC_RUN MODE This mode is entered by setting the SCS1 bit to ‘1’.
Although it is ignored, it is recommended that the SCS0
In RC_RUN mode, the CPU and peripherals are
bit also be cleared; this is to maintain software compat-
clocked from the internal oscillator block using the
ibility with future devices. When the clock source is
INTOSC multiplexer. In this mode, the primary clock is
switched to the INTOSC multiplexer (see Figure 3-3),
shut down. When using the INTRC source, this mode
the primary oscillator is shut down and the OSTS bit is
provides the best power conservation of all the Run
cleared. The IRCF bits may be modified at any time to
modes while still executing code. It works well for user
immediately change the clock speed.
applications which are not highly timing sensitive or do
not require high-speed clocks at all times. Note: Caution should be used when modifying a
If the primary clock source is the internal oscillator single IRCF bit. If VDD is less than 3V, it is
block (either INTRC or INTOSC), there are no distin- possible to select a higher clock speed
guishable differences between PRI_RUN and than is supported by the low VDD.
RC_RUN modes during execution. However, a clock Improper device operation may result if
switch delay will occur during entry to and exit from the VDD/FOSC specifications are violated.
RC_RUN mode. Therefore, if the primary clock source
is the internal oscillator block, the use of RC_RUN
mode is not recommended.
INTRC 1 2 3 n-1 n
(1)
OSC1 Clock Transition
CPU
Clock
Peripheral
Clock
Program
Counter PC PC + 2 PC + 4
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3
INTOSC
Multiplexer
OSC1
TOST(1) TPLL(1)
1 2 n-1 n
PLL Clock
Output
Clock
Transition(2)
CPU Clock
Peripheral
Clock
Program PC PC + 2 PC + 4
Counter
Note1: TOST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
2: Clock transition typically occurs within 2-4 TOSC.
OSC1
CPU
Clock
Peripheral
Clock
Sleep
Program
Counter PC PC + 2
OSC1
TOST(1) TPLL(1)
PLL Clock
Output
CPU Clock
Peripheral
Clock
Program PC PC + 2 PC + 4 PC + 6
Counter
Wake Event OSTS bit Set
Note1: 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
FIGURE 3-8: TRANSITION TIMING FOR WAKE FROM IDLE TO RUN MODE
Q1 Q2 Q3 Q4
OSC1
TCSD
CPU Clock
Peripheral
Clock
Program PC
Counter
Wake Event
TABLE 3-2: EXIT DELAY ON WAKE-UP BY RESET FROM SLEEP MODE OR ANY IDLE MODE
(BY CLOCK SOURCES)
Clock Source Clock Source Clock Ready Status
Exit Delay
Before Wake-up After Wake-up Bit (OSCCON)
LP, XT, HS
Primary Device Clock HSPLL OSTS
TCSD(1)
(PRI_IDLE mode) EC, RC
INTOSC(2) IOFS
LP, XT, HS TOST(3)
HSPLL TOST + trc(3) OSTS
T1OSC or INTRC(1)
EC, RC TCSD(1)
INTOSC(2) TCSD(1) IOFS
LP, XT, HS TOST(3)
HSPLL TOST + trc(3) OSTS
INTOSC(2)
EC, RC TCSD(1)
INTOSC(2) TCSD(1) IOFS
LP, XT, HS TOST(3)
None HSPLL TOST + trc(3) OSTS
(Sleep mode) EC, RC TCSD(1)
INTOSC(2) TCSD(1) IOFS
Note 1: TCSD (parameter 38) is a required delay when waking from Sleep and all Idle modes and runs concurrently
with any other required delays (see Section 3.4 “Idle Modes”). On Reset, INTOSC defaults to 1 MHz.
2: Includes both the INTOSC 8 MHz source and postscaler derived frequencies.
3: TOST is the Oscillator Start-up Timer (parameter 32). trc is the PLL lock-out timer (parameter F12); it is also
designated as TPLL.
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-2 for time-out situations.
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: It is recommended that the POR bit be set after a Power-on Reset has been detected so that subsequent
Power-on Resets may be detected.
2: Brown-out Reset is said to have occurred when BOR is ‘0’ and POR is ‘1’ (assuming that POR was set to
‘1’ by software immediately after a Power-on Reset).
4.5.2 OSCILLATOR START-UP TIMER Since the time-outs occur from the POR pulse, if MCLR
is kept low long enough, all time-outs will expire. Bring-
(OST)
ing MCLR high will begin execution immediately
The Oscillator Start-up Timer (OST) provides a (Figure 4-5). This is useful for testing purposes or to
1024 oscillator cycle (from OSC1 input) delay after the synchronize more than one PIC18FXXXX device
PWRT delay is over (parameter 33). This ensures that operating in parallel.
the crystal oscillator or resonator has started and
stabilized.
The OST time-out is invoked only for XT, LP, HS and
HSPLL modes and only on Power-on Reset, or on exit
from most power-managed modes.
HSPLL 66 ms(1) + 1024 TOSC + 2 ms(2) 1024 TOSC + 2 ms(2) 1024 TOSC + 2 ms(2)
HS, XT, LP 66 ms(1) + 1024 TOSC 1024 TOSC 1024 TOSC
EC, ECIO 66 ms(1) — —
RC, RCIO 66 ms(1) — —
(1)
INTIO1, INTIO2 66 ms — —
Note 1: 66 ms (65.5 ms) is the nominal Power-up Timer (PWRT) delay.
2: 2 ms is the nominal time required for the PLL to lock.
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
TABLE 4-3: STATUS BITS, THEIR SIGNIFICANCE AND THE INITIALIZATION CONDITION
FOR RCON REGISTER
Program RCON Register STKPTR Register
Condition
Counter RI TO PD POR BOR STKFUL STKUNF
Power-on Reset 0000h 1 1 1 0 0 0 0
RESET Instruction 0000h 0 u u u u u u
Brown-out Reset 0000h 1 1 1 u 0 u u
MCLR Reset during Power-Managed 0000h u 1 u u u u u
Run Modes
MCLR Reset during Power-Managed 0000h u 1 0 u u u u
Idle Modes and Sleep Mode
WDT Time-out during Full Power or 0000h u 0 u u u u u
Power-Managed Run Mode
MCLR Reset during Full-Power 0000h u u u u u u u
Execution
Stack Full Reset (STVREN = 1) 0000h u u u u u 1 u
Stack Underflow Reset (STVREN = 1) 0000h u u u u u u 1
Stack Underflow Error (not an actual 0000h u u u u u u 1
Reset, STVREN = 0)
WDT Time-out during PC + 2 u 0 0 u u u u
Power-Managed Idle or Sleep Modes
Interrupt Exit from Power-Managed PC + 2(1) u u 0 u u u u
Modes
Legend: u = unchanged
Note 1: When the wake-up is due to an interrupt and the GIEH or GIEL bits are set, the PC is loaded with the
interrupt vector (008h or 0018h).
TOSU 2420 2520 4420 4520 ---0 0000 ---0 0000 ---0 uuuu(3)
TOSH 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu(3)
TOSL 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu(3)
STKPTR 2420 2520 4420 4520 00-0 0000 uu-0 0000 uu-u uuuu(3)
PCLATU 2420 2520 4420 4520 ---0 0000 ---0 0000 ---u uuuu
PCLATH 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
PCL 2420 2520 4420 4520 0000 0000 0000 0000 PC + 2(2)
TBLPTRU 2420 2520 4420 4520 --00 0000 --00 0000 --uu uuuu
TBLPTRH 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
TBLPTRL 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
TABLAT 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
PRODH 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
PRODL 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
INTCON 2420 2520 4420 4520 0000 000x 0000 000u uuuu uuuu(1)
INTCON2 2420 2520 4420 4520 1111 -1-1 1111 -1-1 uuuu -u-u(1)
INTCON3 2420 2520 4420 4520 11-0 0-00 11-0 0-00 uu-u u-uu(1)
INDF0 2420 2520 4420 4520 N/A N/A N/A
POSTINC0 2420 2520 4420 4520 N/A N/A N/A
POSTDEC0 2420 2520 4420 4520 N/A N/A N/A
PREINC0 2420 2520 4420 4520 N/A N/A N/A
PLUSW0 2420 2520 4420 4520 N/A N/A N/A
FSR0H 2420 2520 4420 4520 ---- 0000 ---- 0000 ---- uuuu
FSR0L 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
WREG 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
INDF1 2420 2520 4420 4520 N/A N/A N/A
POSTINC1 2420 2520 4420 4520 N/A N/A N/A
POSTDEC1 2420 2520 4420 4520 N/A N/A N/A
PREINC1 2420 2520 4420 4520 N/A N/A N/A
PLUSW1 2420 2520 4420 4520 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-3 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’.
6: The Reset value of the PCFG bits depends on the value of the PBADEN Configuration bit (CONFIG3H<1>). When
PBADEN = 1, PCFG<2:0> = 000; when PBADEN = 0, PCFG<2:0> = 111.
FSR1H 2420 2520 4420 4520 ---- 0000 ---- 0000 ---- uuuu
FSR1L 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
BSR 2420 2520 4420 4520 ---- 0000 ---- 0000 ---- uuuu
INDF2 2420 2520 4420 4520 N/A N/A N/A
POSTINC2 2420 2520 4420 4520 N/A N/A N/A
POSTDEC2 2420 2520 4420 4520 N/A N/A N/A
PREINC2 2420 2520 4420 4520 N/A N/A N/A
PLUSW2 2420 2520 4420 4520 N/A N/A N/A
FSR2H 2420 2520 4420 4520 ---- 0000 ---- 0000 ---- uuuu
FSR2L 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
STATUS 2420 2520 4420 4520 ---x xxxx ---u uuuu ---u uuuu
TMR0H 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
TMR0L 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
T0CON 2420 2520 4420 4520 1111 1111 1111 1111 uuuu uuuu
OSCCON 2420 2520 4420 4520 0100 q000 0100 q000 uuuu quuu
HLVDCON 2420 2520 4420 4520 0-00 0101 0-00 0101 u-uu uuuu
WDTCON 2420 2520 4420 4520 ---- ---0 ---- ---0 ---- ---u
(4)
RCON 2420 2520 4420 4520 0q-1 11q0 0q-q qquu uq-u qquu
TMR1H 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
TMR1L 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
T1CON 2420 2520 4420 4520 0000 0000 u0uu uuuu uuuu uuuu
TMR2 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
PR2 2420 2520 4420 4520 1111 1111 1111 1111 1111 1111
T2CON 2420 2520 4420 4520 -000 0000 -000 0000 -uuu uuuu
SSPBUF 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
SSPADD 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
SSPSTAT 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
SSPCON1 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
SSPCON2 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
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-3 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’.
6: The Reset value of the PCFG bits depends on the value of the PBADEN Configuration bit (CONFIG3H<1>). When
PBADEN = 1, PCFG<2:0> = 000; when PBADEN = 0, PCFG<2:0> = 111.
ADRESH 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
ADRESL 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
ADCON0 2420 2520 4420 4520 --00 0000 --00 0000 --uu uuuu
ADCON1 2420 2520 4420 4520 --00 0qqq(6) --00 0qqq(6) --uu uuuu
ADCON2 2420 2520 4420 4520 0-00 0000 0-00 0000 u-uu uuuu
CCPR1H 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
CCPR1L 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
CCP1CON
2420 2520 4420 4520 --00 0000 --00 0000 --uu uuuu
CCPR2H 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
CCPR2L 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
CCP2CON 2420 2520 4420 4520 --00 0000 --00 0000 --uu uuuu
BAUDCON 2420 2520 4420 4520 0100 0-00 0100 0-00 uuuu u-uu
PWM1CON 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
ECCP1AS
2420 2520 4420 4520 0000 00-- 0000 00-- uuuu uu--
CVRCON 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
CMCON 2420 2520 4420 4520 0000 0111 0000 0111 uuuu uuuu
TMR3H 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
TMR3L 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
T3CON 2420 2520 4420 4520 0000 0000 uuuu uuuu uuuu uuuu
SPBRGH 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
SPBRG 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
RCREG 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
TXREG 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
TXSTA 2420 2520 4420 4520 0000 0010 0000 0010 uuuu uuuu
RCSTA 2420 2520 4420 4520 0000 000x 0000 000x uuuu uuuu
EEADR 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
EEDATA 2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
EECON2 2420 2520 4420 4520 0000 0000 0000 0000 0000 0000
EECON1 2420 2520 4420 4520 xx-0 x000 uu-0 u000 uu-0 u000
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-3 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’.
6: The Reset value of the PCFG bits depends on the value of the PBADEN Configuration bit (CONFIG3H<1>). When
PBADEN = 1, PCFG<2:0> = 000; when PBADEN = 0, PCFG<2:0> = 111.
IPR2 2420 2520 4420 4520 11-1 1111 11-1 1111 uu-u uuuu
PIR2 2420 2520 4420 4520 00-0 0000 00-0 0000 uu-u uuuu(1)
PIE2 2420 2520 4420 4520 00-0 0000 00-0 0000 uu-u uuuu
2420 2520 4420 4520 1111 1111 1111 1111 uuuu uuuu
IPR1
2420 2520 4420 4520 -111 1111 -111 1111 -uuu uuuu
2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu(1)
PIR1
2420 2520 4420 4520 -000 0000 -000 0000 -uuu uuuu(1)
2420 2520 4420 4520 0000 0000 0000 0000 uuuu uuuu
PIE1
2420 2520 4420 4520 -000 0000 -000 0000 -uuu uuuu
OSCTUNE 2420 2520 4420 4520 00-0 0000 00-0 0000 uu-u uuuu
TRISE 2420 2520 4420 4520 0000 -111 0000 -111 uuuu -uuu
TRISD 2420 2520 4420 4520 1111 1111 1111 1111 uuuu uuuu
TRISC 2420 2520 4420 4520 1111 1111 1111 1111 uuuu uuuu
TRISB 2420 2520 4420 4520 1111 1111 1111 1111 uuuu uuuu
TRISA(5) 2420 2520 4420 4520 1111 1111(5) 1111 1111(5) uuuu uuuu(5)
LATE 2420 2520 4420 4520 ---- -xxx ---- -uuu ---- -uuu
LATD 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
LATC 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
LATB 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
LATA(5) 2420 2520 4420 4520 xxxx xxxx(5) uuuu uuuu(5) uuuu uuuu(5)
PORTE 2420 2520 4420 4520 ---- xxxx ---- uuuu ---- uuuu
PORTD 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
PORTC 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
PORTB 2420 2520 4420 4520 xxxx xxxx uuuu uuuu uuuu uuuu
PORTA(5) 2420 2520 4420 4520 xx0x 0000(5) uu0u 0000(5) uuuu uuuu(5)
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-3 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’.
6: The Reset value of the PCFG bits depends on the value of the PBADEN Configuration bit (CONFIG3H<1>). When
PBADEN = 1, PCFG<2:0> = 000; when PBADEN = 0, PCFG<2:0> = 111.
PC<20:0>
CALL,RCALL,RETURN 21
RETFIE,RETLW
Stack Level 1
•
•
•
Stack Level 31
On-Chip On-Chip
Program Memory Program Memory
3FFFh
4000h
User Memory Space
PIC18F2420/4420
7FFFh
8000h
PIC18F2520/4520
1FFFFFh
200000h
11111
11110
Top-of-Stack Registers 11101 Stack Pointer
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
OSC1
Q1
Q2 Internal
Q3 Phase
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.2.4 TWO-WORD INSTRUCTIONS the instruction sequence. If the first word is skipped for
some reason and the second word is executed by itself,
The standard PIC18 instruction set has four two-word
a NOP is executed instead. This is necessary for cases
instructions: CALL, MOVFF, GOTO and LSFR. In all
when the two-word instruction is preceded by a condi-
cases, the second word of the instructions always has
tional instruction that changes the PC. Example 5-4
‘1111’ as its four Most Significant bits; the other 12 bits
shows how this works.
are literal data, usually a data memory address.
The use of ‘1111’ in the 4 MSbs of an instruction spec- Note: See Section 5.6 “PIC18 Instruction
ifies a special form of NOP. If the instruction is executed Execution and the Extended Instruc-
in proper sequence – immediately after the first word – tion Set” for information on two-word
the data in the second word is accessed and used by instructions in the extended instruction set.
When ‘a’ = 0:
BSR<3:0> Data Memory Map
The BSR is ignored and the
00h 000h Access Bank is used.
= 0000 Access RAM 07Fh
Bank 0 The first 128 bytes are
GPR 080h
FFh 0FFh general purpose RAM
00h 100h (from Bank 0).
= 0001
Bank 1 GPR The second 128 bytes are
FFh 1FFh Special Function Registers
= 0010 00h 200h (from Bank 15).
Bank 2 GPR
FFh 2FFh When ‘a’ = 1:
= 0011 00h 300h
Bank 3 The BSR specifies the Bank
used by the instruction.
FFh 3FFh
00h 400h
= 0100 Bank 4
FFh 4FFh
= 0101 00h 500h
Bank 5
FFh 5FFh
= 0110 00h 600h
Bank 6
Access Bank
FFh 6FFh
= 0111 00h 700h 00h
Bank 7 Access RAM Low
7Fh
FFh 7FFh Access RAM High 80h
= 1000 00h 800h (SFRs)
Bank 8 FFh
FFh 8FFh
= 1001 00h Unused 900h
Bank 9 Read 00h
FFh 9FFh
00h A00h
= 1010
Bank 10
FFh AFFh
= 1011 00h B00h
Bank 11
FFh BFFh
= 1100 00h C00h
Bank 12
FFh CFFh
= 1101 D00h
Bank 13 00h
FFh DFFh
00h E00h
= 1110
Bank 14
FFh EFFh
00h Unused F00h
= 1111 F7Fh
Bank 15
SFR F80h
FFh FFFh
When ‘a’ = 0:
BSR<3:0> Data Memory Map
The BSR is ignored and the
00h 000h Access Bank is used.
= 0000 Access RAM 07Fh
Bank 0 The first 128 bytes are
GPR 080h
FFh 0FFh general purpose RAM
00h 100h (from Bank 0).
= 0001
Bank 1 GPR The second 128 bytes are
FFh 1FFh Special Function Registers
= 0010 00h 200h (from Bank 15).
Bank 2 GPR
FFh 2FFh When ‘a’ = 1:
= 0011 00h 300h
Bank 3 The BSR specifies the Bank
GPR
used by the instruction.
FFh 3FFh
00h 400h
= 0100 Bank 4 GPR
FFh 4FFh
= 0101 00h 500h
Bank 5 GPR
FFh 5FFh
= 0110 00h 600h
Bank 6
Access Bank
FFh 6FFh
= 0111 00h 700h 00h
Bank 7 Access RAM Low
7Fh
FFh 7FFh Access RAM High 80h
= 1000 00h 800h (SFRs)
Bank 8 FFh
FFh 8FFh
= 1001 00h 900h
Bank 9
FFh 9FFh
00h Unused A00h
= 1010
Bank 10 Read 00h
FFh AFFh
= 1011 00h B00h
Bank 11
FFh BFFh
= 1100 00h C00h
Bank 12
FFh CFFh
= 1101 D00h
Bank 13 00h
FFh DFFh
00h E00h
= 1110
Bank 14
FFh EFFh
00h Unused F00h
= 1111 F7Fh
Bank 15
SFR F80h
FFh FFFh
Bank 3
through
Bank 13
FFh
E00h
00h
Bank 14
F00h FFh
00h
Bank 15
FFFh FFh
Note 1: The Access RAM bit of the instruction can be used to force an override of the selected bank (BSR<3:0>) to
the registers of the Access Bank.
2: The MOVFF instruction embeds the entire 12-bit address in the instruction.
5.3.2 ACCESS BANK however, the instruction is forced to use the Access
Bank address map; the current value of the BSR is
While the use of the BSR with an embedded 8-bit
ignored entirely.
address allows users to address the entire range of
data memory, it also means that the user must always Using this “forced” addressing allows the instruction to
ensure that the correct bank is selected. Otherwise, operate on a data address in a single cycle, without
data may be read from or written to the wrong location. updating the BSR first. For 8-bit addresses of 80h and
This can be disastrous if a GPR is the intended target above, this means that users can evaluate and operate
of an operation, but an SFR is written to instead. on SFRs more efficiently. The Access RAM below 80h
Verifying and/or changing the BSR for each read or is a good place for data values that the user might need
write to data memory can become very inefficient. to access rapidly, such as immediate computational
results or common program variables. Access RAM
To streamline access for the most commonly used data
also allows for faster and more code efficient context
memory locations, the data memory is configured with
saving and switching of variables.
an Access Bank, which allows users to access a
mapped block of memory without specifying a BSR. The mapping of the Access Bank is slightly different
The Access Bank consists of the first 128 bytes of when the extended instruction set is enabled (XINST
memory (00h-7Fh) in Bank 0 and the last 128 bytes of Configuration bit = 1). This is discussed in more detail
memory (80h-FFh) in Block 15. The lower half is known in Section 5.5.3 “Mapping the Access Bank in
as the “Access RAM” and is composed of GPRs. This Indexed Literal Offset Mode”.
upper half is also where the device’s SFRs are
mapped. These two areas are mapped contiguously in 5.3.3 GENERAL PURPOSE REGISTER
the Access Bank and can be addressed in a linear FILE
fashion by an 8-bit address (Figure 5-5). PIC18 devices may have banked memory in the GPR
The Access Bank is used by core PIC18 instructions area. This is data RAM, which is available for use by all
that include the Access RAM bit (the ‘a’ parameter in instructions. GPRs start at the bottom of Bank 0
the instruction). When ‘a’ is equal to ‘1’, the instruction (address 000h) and grow upwards towards the bottom of
uses the BSR and the 8-bit address included in the the SFR area. GPRs are not initialized by a Power-on
opcode for the data memory address. When ‘a’ is ‘0’, Reset and are unchanged on all other Resets.
SPBRGH EUSART Baud Rate Generator Register High Byte 0000 0000 51, 206
SPBRG EUSART Baud Rate Generator Register Low Byte 0000 0000 51, 206
RCREG EUSART Receive Register 0000 0000 51, 213
TXREG EUSART Transmit Register 0000 0000 51, 211
TXSTA CSRC TX9 TXEN SYNC SENDB BRGH TRMT TX9D 0000 0010 51, 202
RCSTA SPEN RX9 SREN CREN ADDEN FERR OERR RX9D 0000 000x 51, 203
EEADR EEPROM Address Register 0000 0000 51, 74, 83
EEDATA EEPROM Data Register 0000 0000 51, 74, 83
EECON2 EEPROM Control Register 2 (not a physical register) 0000 0000 51, 74, 83
EECON1 EEPGD CFGS — FREE WRERR WREN WR RD xx-0 x000 51, 75, 84
IPR2 OSCFIP CMIP — EEIP BCLIP HLVDIP TMR3IP CCP2IP 11-1 1111 52, 101
PIR2 OSCFIF CMIF — EEIF BCLIF HLVDIF TMR3IF CCP2IF 00-0 0000 52, 97
PIE2 OSCFIE CMIE — EEIE BCLIE HLVDIE TMR3IE CCP2IE 00-0 0000 52, 99
IPR1 PSPIP(2) ADIP RCIP TXIP SSPIP CCP1IP TMR2IP TMR1IP 1111 1111 52, 100
PIR1 PSPIF(2) ADIF RCIF TXIF SSPIF CCP1IF TMR2IF TMR1IF 0000 0000 52, 96
PIE1 PSPIE(2) ADIE RCIE TXIE SSPIE CCP1IE TMR2IE TMR1IE 0000 0000 52, 98
OSCTUNE INTSRC PLLEN(3) — TUN4 TUN3 TUN2 TUN1 TUN0 0q-0 0000 27, 52
TRISE(2) IBF OBF IBOV PSPMODE — TRISE2 TRISE1 TRISE0 0000 -111 52, 118
TRISD(2) PORTD Data Direction Register 1111 1111 52, 114
TRISC PORTC Data Direction Register 1111 1111 52, 111
TRISB PORTB Data Direction Register 1111 1111 52, 108
TRISA TRISA7(5) TRISA6(5) PORTA Data Direction Register 1111 1111 52, 105
LATE(2) — — — — — PORTE Data Latch Register ---- -xxx 52, 117
(Read and Write to Data Latch)
LATD(2) PORTD Data Latch Register (Read and Write to Data Latch) xxxx xxxx 52, 114
LATC PORTC Data Latch Register (Read and Write to Data Latch) xxxx xxxx 52, 111
LATB PORTB Data Latch Register (Read and Write to Data Latch) xxxx xxxx 52, 108
LATA LATA7(5) LATA6(5) PORTA Data Latch Register (Read and Write to Data Latch) xxxx xxxx 52, 105
PORTE — — — — RE3(4) RE2(2) RE1(2) RE0(2) ---- xxxx 52, 117
PORTD(2) RD7 RD6 RD5 RD4 RD3 RD2 RD1 RD0 xxxx xxxx 52, 114
PORTC RC7 RC6 RC5 RC4 RC3 RC2 RC1 RC0 xxxx xxxx 52, 111
PORTB RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 xxxx xxxx 52, 108
PORTA RA7(5) RA6(5) RA5 RA4 RA3 RA2 RA1 RA0 xx0x 0000 52, 105
Legend: x = unknown, u = unchanged, — = unimplemented, q = value depends on condition. Shaded cells are unimplemented, read as ‘0’.
Note 1: The SBOREN bit is only available when the BOREN<1:0> Configuration bits = 01; otherwise, it is disabled and reads as ‘0’. See
Section 4.4 “Brown-out Reset (BOR)”.
2: These registers and/or bits are not implemented on 28-pin devices and are read as ‘0’. Reset values are shown for 40/44-pin devices;
individual unimplemented bits should be interpreted as ‘-’.
3: The PLLEN bit is only available in specific oscillator configurations; otherwise, it is disabled and reads as ‘0’. See Section 2.6.4 “PLL in
INTOSC Modes”.
4: The RE3 bit is only available when Master Clear Reset is disabled (MCLRE Configuration bit = 0); otherwise, RE3 reads as ‘0’. This bit is
read-only.
5: RA6/RA7 and their associated latch and direction bits are individually configured as port pins based on various primary oscillator modes.
When disabled, these bits read as ‘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
Note 1: For borrow, the polarity is reversed. A subtraction is executed by adding the 2’s complement of the second
operand. For rotate (RRF, RLF) instructions, this bit is loaded with either bit 4 or bit 3 of the source register.
2: For borrow, the polarity is reversed. A subtraction is executed by adding the 2’s complement of the second
operand. For rotate (RRF, RLF) instructions, this bit is loaded with either the high or low-order bit of the
source register.
000h
When ‘a’ = 0 and f ≥ 60h:
060h
The instruction executes in
080h Bank 0
Direct Forced mode. ‘f’ is inter-
preted as a location in the 100h
Access RAM between 060h 00h
Bank 1
and 0FFh. This is the same as through 60h
locations 060h to 07Fh Bank 14 80h
Valid range
(Bank 0) and F80h to FFFh for ‘f’
(Bank 15) of data memory.
FFh
F00h
Locations below 60h are not Access RAM
Bank 15
available in this addressing
F80h
mode. SFRs
FFFh
Data Memory
BSR
When ‘a’ = 1 (all values of f): 000h 00000000
Bank 0
The instruction executes in
080h
Direct mode (also known as
Direct Long mode). ‘f’ is inter- 100h
preted as a location in one of
the 16 banks of the data Bank 1 001001da ffffffff
memory space. The bank is through
Bank 14
designated by the Bank Select
Register (BSR). The address
can be in any implemented F00h
bank in the data memory Bank 15
space. F80h
SFRs
FFFh
Data Memory
FIGURE 5-10: REMAPPING THE ACCESS BANK WITH INDEXED LITERAL OFFSET ADDRESSING
Example Situation:
ADDWF f, d, a 000h
Bank 0
FSR2H:FSR2L = 120h 05Fh
07Fh
Locations in the region Bank 0
from the FSR2 Pointer 100h
(120h) to the pointer plus Bank 1
120h
05Fh (17Fh) are mapped Window
17Fh 00h
to the bottom of the
Bank 1 Bank 1 “Window”
Access RAM (000h-05Fh). 200h
Locations in Bank 0 from 5Fh
Bank 0
060h to 07Fh are mapped, 7Fh
as usual, to the middle half Bank 2 80h
of the Access Bank. through SFRs
Special Function Registers Bank 14
at F80h through FFFh are FFh
mapped to 80h through Access Bank
FFh, as usual. F00h
Bank 0 addresses below Bank 15
5Fh can still be addressed F80h
by using the BSR. SFRs
FFFh
Data Memory
Instruction: TBLRD*
Program Memory
Table Pointer(1)
Table Latch (8-bit)
TBLPTRU TBLPTRH TBLPTRL
TABLAT
Program Memory
(TBLPTR)
Instruction: TBLWT*
Program Memory
Holding Registers
Table Pointer(1) Table Latch (8-bit)
TBLPTRU TBLPTRH TBLPTRL TABLAT
Program Memory
(TBLPTR)
Note1: The Table Pointer actually points to one of 32 holding registers, the address of which is determined by
TBLPTRL<4: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 FREE bit, when set, will allow a program memory
erase operation. When FREE is set, the erase
Several control registers are used in conjunction with operation is initiated on the next WR command. When
the TBLRD and TBLWT instructions. These include the: FREE is clear, only writes are enabled.
• EECON1 register The WREN bit, when set, will allow a write operation.
• EECON2 register On power-up, the WREN bit is clear. The WRERR bit is
• TABLAT register set in hardware when the WR bit is set and cleared
• TBLPTR registers when the internal programming timer expires and the
write operation is complete.
6.2.1 EECON1 AND EECON2 REGISTERS Note: During normal operation, the WRERR is
The EECON1 register (Register 6-1) is the control read as ‘1’. This can indicate that a write
register for memory accesses. The EECON2 register is operation was prematurely terminated by
not a physical register; it is used exclusively in the a Reset, or a write operation was
memory write and erase sequences. Reading attempted improperly.
EECON2 will read all ‘0’s.
The WR control bit initiates write operations. The bit
The EEPGD control bit determines if the access will be
cannot be cleared, only set, in software; it is cleared in
a program or data EEPROM memory access. When
hardware at the completion of the write operation.
clear, any subsequent operations will operate on the
data EEPROM memory. When set, any subsequent Note: The EEIF interrupt flag bit (PIR2<4>) is set
operations will operate on the program memory. when the write is complete. It must be
The CFGS control bit determines if the access will be cleared in software.
to the Configuration/Calibration registers or to program
memory/data EEPROM memory. When set,
subsequent operations will operate on Configuration
registers regardless of EEPGD (see Section 23.0
“Special Features of the CPU”). When clear, memory
selection access is determined by EEPGD.
Note 1: When a WRERR occurs, the EEPGD and CFGS bits are not cleared. This allows tracing of the error
condition.
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+*
TABLE ERASE
TBLPTR<21:6>
Program Memory
TABLAT
Write Register
8 8 8 8
Program Memory
Note 1: When a WRERR occurs, the EEPGD and CFGS bits are not cleared. This allows tracing of the error
condition.
Wake-up if in
Idle or Sleep modes
TMR0IF
TMR0IE
TMR0IP
RBIF
RBIE
RBIP
INT0IF
INT0IE
Interrupt to CPU
INT1IF Vector to Location
INT1IE
INT1IP 0008h
SSPIF
SSPIE INT2IF
SSPIP INT2IE
INT2IP
GIE/GIEH
ADIF
ADIE
ADIP IPEN
RCIF IPEN
RCIE PEIE/GIEL
RCIP
IPEN
Additional Peripheral Interrupts
High-Priority Interrupt Generation
SSPIF
SSPIE
SSPIP
Interrupt to CPU
TMR0IF Vector to Location
TMR0IE 0018h
ADIF TMR0IP
ADIE
ADIP RBIF
RBIE
RCIF RBIP GIE/GIEH
RCIE PEIE/GIE
RCIP
INT1IF
INT1IE
INT1IP
Additional Peripheral Interrupts
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
Note 1: A mismatch condition will continue to set this bit. Reading PORTB will end the mismatch condition and
allow the bit to be cleared.
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
Note 1: This bit is unimplemented on 28-pin devices and will read as ‘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
Note 1: This bit is unimplemented on 28-pin devices and will read as ‘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
Note 1: This bit is unimplemented on 28-pin devices and will read as ‘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
Note 1: Actual Reset values are determined by device configuration and the nature of the device Reset. See
Register 4-1 for additional information.
FIGURE 10-1: GENERIC I/O PORT Pins RA0 through RA5 may also be used as comparator
inputs or outputs by setting the appropriate bits in the
OPERATION
CMCON register. To use RA<3:0> as digital inputs, it is
also necessary to turn off the comparators.
RD LAT
Note: On a Power-on Reset, RA5 and RA<3:0>
Data are configured as analog inputs and read
Bus D Q as ‘0’. RA4 is configured as a digital input.
WR LAT I/O pin(1)
or Port
CK
The RA4/T0CKI/C1OUT pin is a Schmitt Trigger input.
All other PORTA pins have TTL input levels and full
Data Latch
CMOS output drivers.
D Q The TRISA register controls the direction of the PORTA
pins, even when they are being used as analog inputs.
WR TRIS
CK The user must ensure the bits in the TRISA register are
TRIS Latch Input maintained set when using them as analog inputs.
Buffer
RA0/AN0 RA0 0 O DIG LATA<0> data output; not affected by analog input.
1 I TTL PORTA<0> data input; disabled when analog input enabled.
AN0 1 I ANA A/D input channel 0 and comparator C1- input. Default input
configuration on POR; does not affect digital output.
RA1/AN1 RA1 0 O DIG LATA<1> data output; not affected by analog input.
1 I TTL PORTA<1> data input; disabled when analog input enabled.
AN1 1 I ANA A/D input channel 1 and comparator C2- input. Default input
configuration on POR; does not affect digital output.
RA2/AN2/ RA2 0 O DIG LATA<2> data output; not affected by analog input. Disabled when
VREF-/CVREF CVREF output enabled.
1 I TTL PORTA<2> data input. Disabled when analog functions enabled;
disabled when CVREF output enabled.
AN2 1 I ANA A/D input channel 2 and comparator C2+ input. Default input
configuration on POR; not affected by analog output.
VREF- 1 I ANA A/D and comparator voltage reference low input.
CVREF x O ANA Comparator voltage reference output. Enabling this feature disables
digital I/O.
RA3/AN3/VREF+ RA3 0 O DIG LATA<3> data output; not affected by analog input.
1 I TTL PORTA<3> data input; disabled when analog input enabled.
AN3 1 I ANA A/D input channel 3 and comparator C1+ input. Default input
configuration on POR.
VREF+ 1 I ANA A/D and comparator voltage reference high input.
RA4/T0CKI/C1OUT RA4 0 O DIG LATA<4> data output.
1 I ST PORTA<4> data input; default configuration on POR.
T0CKI 1 I ST Timer0 clock input.
C1OUT 0 O DIG Comparator 1 output; takes priority over port data.
RA5/AN4/SS/ RA5 0 O DIG LATA<5> data output; not affected by analog input.
HLVDIN/C2OUT 1 I TTL PORTA<5> data input; disabled when analog input enabled.
AN4 1 I ANA A/D input channel 4. Default configuration on POR.
SS 1 I TTL Slave select input for MSSP module.
HLVDIN 1 I ANA High/Low-Voltage Detect external trip point input.
C2OUT 0 O DIG Comparator 2 output; takes priority over port data.
OSC2/CLKO/RA6 RA6 0 O DIG LATA<6> data output. Enabled in RCIO, INTIO2 and ECIO modes only.
1 I TTL PORTA<6> data input. Enabled in RCIO, INTIO2 and ECIO modes
only.
OSC2 x O ANA Main oscillator feedback output connection (XT, HS and LP modes).
CLKO x O DIG System cycle clock output (FOSC/4) in RC, INTIO1 and EC Oscillator
modes.
OSC1/CLKI/RA7 RA7 0 O DIG LATA<7> data output. Disabled in external oscillator modes.
1 I TTL PORTA<7> data input. Disabled in external oscillator modes.
OSC1 x I ANA Main oscillator input connection.
CLKI x I ANA Main clock input connection.
Legend: DIG = Digital level output; TTL = TTL input buffer; ST = Schmitt Trigger input buffer; ANA = Analog level input/output;
x = Don’t care (TRIS bit does not affect port direction or is overridden for this option).
RB0/INT0/FLT0/ RB0 0 O DIG LATB<0> data output; not affected by analog input.
AN12
1 I TTL PORTB<0> data input; weak pull-up when RBPU bit is cleared.
Disabled when analog input enabled.(1)
INT0 1 I ST External interrupt 0 input.
FLT0 1 I ST Enhanced PWM Fault input (ECCP1 module); enabled in software.
AN12 1 I ANA A/D input channel 12.(1)
RB1/INT1/AN10 RB1 0 O DIG LATB<1> data output; not affected by analog input.
1 I TTL PORTB<1> data input; weak pull-up when RBPU bit is cleared.
Disabled when analog input enabled.(1)
INT1 1 I ST External Interrupt 1 input.
AN10 1 I ANA A/D input channel 10.(1)
RB2/INT2/AN8 RB2 0 O DIG LATB<2> data output; not affected by analog input.
1 I TTL PORTB<2> data input; weak pull-up when RBPU bit is cleared.
Disabled when analog input enabled.(1)
INT2 1 I ST External interrupt 2 input.
AN8 1 I ANA A/D input channel 8.(1)
RB3/AN9/CCP2 RB3 0 O DIG LATB<3> data output; not affected by analog input.
1 I TTL PORTB<3> data input; weak pull-up when RBPU bit is cleared.
Disabled when analog input enabled.(1)
AN9 1 I ANA A/D input channel 9.(1)
(2)
CCP2 0 O DIG CCP2 compare and PWM output.
1 I ST CCP2 capture input
RB4/KBI0/AN11 RB4 0 O DIG LATB<4> data output; not affected by analog input.
1 I TTL PORTB<4> data input; weak pull-up when RBPU bit is cleared.
Disabled when analog input enabled.(1)
KBI0 1 I TTL Interrupt-on-pin change.
AN11 1 I ANA A/D input channel 11.(1)
RB5/KBI1/PGM RB5 0 O DIG LATB<5> data output.
1 I TTL PORTB<5> data input; weak pull-up when RBPU bit is cleared.
KBI1 1 I TTL Interrupt-on-pin change.
PGM x I ST Single-Supply In-Circuit Serial Programming™ mode entry (ICSP™).
Enabled by LVP Configuration bit; all other pin functions disabled.
RB6/KBI2/PGC RB6 0 O DIG LATB<6> data output.
1 I TTL PORTB<6> data input; weak pull-up when RBPU bit is cleared.
KBI2 1 I TTL Interrupt-on-pin change.
PGC x I ST Serial execution (ICSP) clock input for ICSP and ICD operation.(3)
RB7/KBI3/PGD RB7 0 O DIG LATB<7> data output.
1 I TTL PORTB<7> data input; weak pull-up when RBPU bit is cleared.
KBI3 1 I TTL Interrupt-on-pin change.
PGD x O DIG Serial execution data output for ICSP and ICD operation.(3)
x I ST Serial execution data input for ICSP and ICD operation.(3)
Legend: DIG = Digital level output; TTL = TTL input buffer; ST = Schmitt Trigger input buffer; ANA = Analog level input/output;
x = Don’t care (TRIS bit does not affect port direction or is overridden for this option).
Note 1: Configuration on POR is determined by the PBADEN Configuration bit. Pins are configured as analog inputs by default
when PBADEN is set and digital inputs when PBADEN is cleared.
2: Alternate assignment for CCP2 when the CCP2MX Configuration bit is ‘0’. Default assignment is RC1.
3: All other pin functions are disabled when ICSP or ICD are enabled.
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/RD/AN5 RE0 0 O DIG LATE<0> data output; not affected by analog input.
1 I ST PORTE<0> data input; disabled when analog input enabled.
RD 1 I TTL PSP read enable input (PSP enabled).
AN5 1 I ANA A/D input channel 5; default input configuration on POR.
RE1/WR/AN6 RE1 0 O DIG LATE<1> data output; not affected by analog input.
1 I ST PORTE<1> data input; disabled when analog input enabled.
WR 1 I TTL PSP write enable input (PSP enabled).
AN6 1 I ANA A/D input channel 6; default input configuration on POR.
RE2/CS/AN7 RE2 0 O DIG LATE<2> data output; not affected by analog input.
1 I ST PORTE<2> data input; disabled when analog input enabled.
CS 1 I TTL PSP write enable input (PSP enabled).
AN7 1 I ANA A/D input channel 7; default input configuration on POR.
MCLR/VPP/RE3(1) MCLR — I ST External Master Clear input; enabled when MCLRE Configuration bit is
set.
VPP — I ANA High-voltage detection; used for ICSP™ mode entry detection. Always
available regardless of pin mode.
RE3 —(2) I ST PORTE<3> data input; enabled when MCLRE Configuration bit is
clear.
Legend: DIG = Digital level output; TTL = TTL input buffer; ST = Schmitt Trigger input buffer; ANA = Analog level input/output;
x = Don’t care (TRIS bit does not affect port direction or is overridden for this option).
Note 1: RE3 is available on both 28-pin and 40/44-pin devices. All other PORTE pins are only implemented on 40/44-pin
devices.
2: RE3 does not have a corresponding TRIS bit to control data direction.
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
FOSC/4 0
0
Sync with Set
1 Internal TMR0L TMR0IF
T0CKI pin Programmable 1 Clocks on Overflow
Prescaler
T0SE (2 TCY Delay)
T0CS 8
3
T0PS<2:0>
8
PSA Internal Data Bus
Note: Upon Reset, Timer0 is enabled in 8-bit mode with clock input from T0CKI max. prescale.
FOSC/4 0
0
Sync with Set
1 Internal TMR0L TMR0
High Byte TMR0IF
T0CKI pin Programmable 1 Clocks on Overflow
Prescaler 8
T0SE (2 TCY Delay)
T0CS 3 Read TMR0L
T0PS<2:0>
Write TMR0L
PSA
8
8
TMR0H
8
8
Internal Data Bus
Note: Upon Reset, Timer0 is enabled in 8-bit mode with clock input from T0CKI max. 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
T1OSO/T13CKI 1
Prescaler Synchronize
FOSC/4 0
1, 2, 4, 8 Detect
Internal
Clock 0
T1OSI 2
Sleep Input
T1OSCEN(1) TMR1CS Timer1
On/Off
T1CKPS<1:0>
T1SYNC
TMR1ON
TMR1 Set
Clear TMR1 TMR1L TMR1IF
High Byte
(CCP Special Event Trigger) on Overflow
Note 1: When enable bit, T1OSCEN, is cleared, the inverter and feedback resistor are turned off to eliminate power drain.
TMR1 Set
Clear TMR1 TMR1L TMR1IF
High Byte
(CCP Special Event Trigger) on Overflow
8
Read TMR1L
Write TMR1L
8
8
TMR1H
8
8
Internal Data Bus
Note 1: When enable bit, T1OSCEN, is cleared, the inverter and feedback resistor are turned off to eliminate power drain.
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
4 1:1 to 1:16
T2OUTPS<3:0> Set TMR2IF
Postscaler
2
T2CKPS<1:0> TMR2 Output
(to PWM or MSSP)
TMR2/PR2
Reset Match
1:1, 1:4, 1:16
FOSC/4 TMR2 Comparator PR2
Prescaler
8 8
8
Internal Data Bus
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 to eliminate power drain.
Read TMR1L
Write TMR1L
8
8
TMR3H
8
8
Internal Data Bus
Note 1: When enable bit, T1OSCEN, is cleared, the inverter and feedback resistor are turned off to eliminate power drain.
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
TABLE 15-2: INTERACTIONS BETWEEN CCP1 AND CCP2 FOR TIMER RESOURCES
CCP1 Mode CCP2 Mode Interaction
Capture Capture Each module can use TMR1 or TMR3 as the time base. The time base can be different
for each CCP.
Capture Compare CCP2 can be configured for the Special Event Trigger to reset TMR1 or TMR3
(depending upon which time base is used). Automatic A/D conversions on trigger event
can also be done. Operation of CCP1 could be affected if it is using the same timer as a
time base.
Compare Capture CCP1 can be configured for the Special Event Trigger to reset TMR1 or TMR3
(depending upon which time base is used). Operation of CCP2 could be affected if it is
using the same timer as a time base.
Compare Compare Either module can be configured for the Special Event Trigger to reset the time base.
Automatic A/D conversions on CCP2 trigger event can be done. Conflicts may occur if
both modules are using the same time base.
Capture PWM(1) None
Compare PWM(1) None
PWM(1) Capture None
(1)
PWM Compare None
PWM(1) PWM(1) Both PWMs will have the same frequency and update rate (TMR2 interrupt).
Note 1: Includes standard and Enhanced PWM operation.
4 TMR1H TMR1L
CCP1CON<3:0> Set CCP2IF
4
Q1:Q4
4
CCP2CON<3:0>
T3CCP1 TMR3H TMR3L
T3CCP2
TMR3
Enable
CCP2 pin
Prescaler and CCPR2H CCPR2L
÷ 1, 4, 16 Edge Detect
TMR1
Enable
T3CCP2
TMR1H TMR1L
T3CCP1
Compare Output S Q
Comparator
Match Logic
R
TRIS
4 Output Enable
CCP1CON<3:0>
0 TMR1H TMR1L 0
Compare Output S Q
Comparator
Match Logic
R
TRIS
4 Output Enable
CCPR2H CCPR2L
CCP2CON<3:0>
Duty Cycle
TMR2 = PR2
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
TRISx<x>
CCPR1H (Slave)
P1B P1B
Output TRISx<x>
Comparator R Q
Controller
P1C
P1C
TMR2 (Note 1)
S TRISx<x>
P1D P1D
Comparator
Clear Timer, TRISx<x>
set CCP1 pin and
latch D.C.
PR2 PWM1CON
Note: The 8-bit 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.6 “Programmable
Dead-Band Delay”).
PIC18F4X2X FET
Driver +
P1A V
-
Load
FET
Driver
+
P1B V
-
V-
Half-Bridge Output Driving a Full-Bridge Circuit
V+
PIC18F4X2X
FET FET
Driver Driver
P1A
Load
FET FET
Driver Driver
P1B
V-
Forward Mode
Period
(2)
P1A
Duty Cycle
P1B(2)
P1C(2)
P1D(2)
(1) (1)
Reverse Mode
Period
Duty Cycle
P1A(2)
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.
PIC18F4X2X QC
FET QA FET
Driver Driver
P1A
Load
P1B
FET FET
Driver Driver
P1C
QB QD
V-
P1D
16.4.5.1 Direction Change in Full-Bridge Mode Figure 16-9 shows an example where the PWM
direction changes from forward to reverse at a near
In the Full-Bridge Output mode, the P1M1 bit in the
100% duty cycle. At time t1, the outputs P1A and P1D
CCP1CON register allows user to control the forward/
become inactive, while output P1C becomes active. In
reverse direction. When the application firmware
this example, since the turn-off time of the power
changes this direction control bit, the module will
devices is longer than the turn-on time, a shoot-through
assume the new direction on the next PWM cycle.
current may flow through power devices, QC and QD
Just before the end of the current PWM period, the (see Figure 16-7), for the duration of ‘t’. The same
modulated outputs (P1B and P1D) are placed in their phenomenon will occur to power devices, QA and QB,
inactive state, while the unmodulated outputs (P1A and for PWM direction change from reverse to forward.
P1C) are switched to drive in the opposite direction.
If changing PWM direction at high duty cycle is required
This occurs in a time interval of 4 TOSC * (Timer2
for an application, one of the following requirements
Prescale Value) before the next PWM period begins.
must be met:
The Timer2 prescaler will be either 1, 4 or 16, depend-
ing on the value of the T2CKPS<1:0> bits 1. Reduce PWM for a PWM period before
(T2CON<1:0>). During the interval from the switch of changing directions.
the unmodulated outputs to the beginning of the next 2. Use switch drivers that can drive the switches off
period, the modulated outputs (P1B and P1D) remain faster than they can drive them on.
inactive. This relationship is shown in Figure 16-8.
Other options to prevent shoot-through current may
Note that in the Full-Bridge Output mode, the CCP1 exist.
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.
P1A (Active-High)
P1B (Active-High)
DC
P1C (Active-High)
(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(1)
P1B(1) DC
P1C(1)
P1D(1) DC
tON(2)
External Switch C(1)
tOFF(3)
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
Shutdown Event
ECCPASE bit
PWM Activity
Normal PWM
ECCPASE bit
PWM Activity
Normal PWM
ECCPASE
Cleared by
Start of Shutdown Shutdown Firmware PWM
PWM Period Event Occurs Event Clears Resumes
Edge
Select
2
Clock Select
SSPM<3:0>
RC3/SCK/
SCL
SMP:CKE 4
2 (
TMR2 Output
2
)
Edge
Select Prescaler TOSC
4, 16, 64
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 1: In Master mode, the overflow bit is not set since each new reception (and transmission) is initiated by
writing to the SSPBUF register.
2: When enabled, these pins must be properly configured as input or output.
3: Bit combinations not specifically listed here are either reserved or implemented in I2C™ mode only.
SDO SDI
Write to
SSPBUF
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 1: When enabled, the SDA and SCL pins must be properly configured as inputs or outputs.
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: For bits ACKEN, RCEN, PEN, RSEN, SEN: If the I2C module is not in the Idle mode, these bits may not be
set (no spooling) and the SSPBUF may not be written (or writes to the SSPBUF are disabled).
2: Value that will be transmitted when the user initiates an Acknowledge sequence at the end of a receive.
DS39631E-page 176
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
PIC18F2420/2520/4420/4520
SSPOV (SSPCON1<6>)
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
CKP (SSPCON1<4>)
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
Clear by reading
CKP
DS39631E-page 177
PIC18F2420/2520/4420/4520
FIGURE 17-10:
DS39631E-page 178
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.
PIC18F2420/2520/4420/4520
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>)
CKP (SSPCON1<4>)
DS39631E-page 179
PIC18F2420/2520/4420/4520
PIC18F2420/2520/4420/4520
17.4.4 CLOCK STRETCHING 17.4.4.3 Clock Stretching for 7-Bit Slave
Both 7-Bit and 10-Bit Slave modes implement Transmit Mode
automatic clock stretching during a transmit sequence. 7-Bit Slave Transmit mode implements clock stretch-
The SEN bit (SSPCON2<0>) allows clock stretching to ing 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 Note 1: If the user loads the contents of SSPBUF,
bit is set, the CKP bit in the SSPCON1 register is setting the BF bit before the falling edge of
automatically cleared, forcing the SCL output to be the ninth clock, the CKP bit will not be
held low. The CKP being cleared to ‘0’ will assert the cleared and clock stretching will not occur.
SCL line low. The CKP bit must be set in the user’s
Interrupt Service Routine (ISR) before reception is 2: The CKP bit can be set in software
allowed to continue. By holding the SCL line low, the regardless of the state of the BF bit.
user has time to service the ISR and read the contents
of the SSPBUF before the master device can initiate 17.4.4.4 Clock Stretching for 10-Bit Slave
another receive sequence. This will prevent buffer Transmit Mode
overruns from occurring (see Figure 17-13). 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
the third address sequence is performed, the UA bit is
2: The CKP bit can be set in software regard-
not set, the module is now configured in Transmit
less of the state of the BF bit. The user
mode and clock stretching is controlled by the BF flag
should be careful to clear the BF bit in the
as in 7-Bit Slave Transmit mode (see Figure 17-11).
ISR before the next receive 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
SSPCONx
DS39631E-page 182
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
PIC18F2420/2520/4420/4520
SSPOV (SSPCON1<6>)
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
CKP (SSPCON1<4>)
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 ADDRESSING)
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>)
DS39631E-page 183
PIC18F2420/2520/4420/4520
PIC18F2420/2520/4420/4520
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
determines which device will be the slave addressed by When the interrupt is serviced, the source for the
the master. The exception is the general call address interrupt 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 Addressing mode, then the second
The general call address is recognized when the Gen-
half of the address is not necessary, the UA bit will not
eral Call Enable bit, GCEN, is enabled (SSPCON2<7>
be set and the slave will begin receiving data after the
is set). Following a Start bit detect, 8 bits are shifted into
Acknowledge (Figure 17-15).
the SSPSR and the address is compared 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’
GCEN (SSPCON2<7>)
‘1’
Internal SSPM<3:0>
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
SSPM<3:0> 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
Sr = Repeated Start
DS39631E-page 192
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 ACK
of 10-Bit Address
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 ADDRESSING)
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 Acknowledge
Set SSPIF interrupt 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 ADDRESSING)
DS39631E-page 193
PIC18F2420/2520/4420/4520
PIC18F2420/2520/4420/4520
17.4.12 ACKNOWLEDGE SEQUENCE 17.4.13 STOP CONDITION TIMING
TIMING A Stop bit is asserted on the SDA pin at the end of a
An Acknowledge sequence is enabled by setting the receive/transmit by setting the Stop Sequence Enable
Acknowledge Sequence Enable bit, ACKEN bit, PEN (SSPCON2<2>). At the end of a receive/
(SSPCON2<4>). When this bit is set, the SCL pin is transmit, the SCL line is held low after the falling edge
pulled low and the contents of the Acknowledge data bit of the ninth clock. When the PEN bit is set, the master
are presented on the SDA pin. If the user wishes to gen- will assert the SDA line low. When the SDA line is
erate an Acknowledge, then the ACKDT bit should be sampled low, the Baud Rate Generator is reloaded and
cleared. If not, the user should set the ACKDT bit before counts down to 0. When the Baud Rate Generator
starting an Acknowledge sequence. The Baud Rate times out, the SCL pin will be brought high and one
Generator then counts for one rollover period (TBRG) TBRG (Baud Rate Generator rollover count) later, the
and the SCL pin is deasserted (pulled high). When the SDA pin will be deasserted. When the SDA pin is
SCL pin is sampled high (clock arbitration), the Baud sampled high while SCL is high, the P bit
Rate Generator counts for TBRG. The SCL pin is then (SSPSTAT<4>) is set. A TBRG later, the PEN bit is
pulled low. Following this, the ACKEN bit is automatically cleared and the SSPIF bit is set (Figure 17-24).
cleared, the Baud Rate Generator is turned off and the
MSSP module then goes into Idle mode (Figure 17-23). 17.4.13.1 WCOL Status Flag
If the user writes the SSPBUF when a Stop sequence
17.4.12.1 WCOL Status Flag is in progress, then the WCOL bit is set and the con-
If the user writes the SSPBUF when an Acknowledge tents of the buffer are unchanged (the write doesn’t
sequence is in progress, then WCOL is set and the occur).
contents of the buffer are unchanged (the write doesn’t
occur).
SCL 8 9
SSPIF
Cleared in
SSPIF set at software
the end of receive Cleared in
software SSPIF set 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
BCLIF
SDA
SCL
Set SEN, enable Start SEN cleared automatically because of bus collision.
condition if SDA = 1, SCL = 1 MSSP 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
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
0.3 — — — — — — — — — — — —
1.2 — — — 1.221 1.73 255 1.202 0.16 129 1.201 -0.16 103
2.4 2.441 1.73 255 2.404 0.16 129 2.404 0.16 64 2.403 -0.16 51
9.6 9.615 0.16 64 9.766 1.73 31 9.766 1.73 15 9.615 -0.16 12
19.2 19.531 1.73 31 19.531 1.73 15 19.531 1.73 7 — — —
57.6 56.818 -1.36 10 62.500 8.51 4 52.083 -9.58 2 — — —
115.2 125.000 8.51 4 104.167 -9.58 2 78.125 -32.18 1 — — —
0.3 — — — — — — — — — — — —
1.2 — — — — — — — — — — — —
2.4 — — — — — — 2.441 1.73 255 2.403 -0.16 207
9.6 9.766 1.73 255 9.615 0.16 129 9.615 0.16 64 9.615 -0.16 51
19.2 19.231 0.16 129 19.231 0.16 64 19.531 1.73 31 19.230 -0.16 25
57.6 58.140 0.94 42 56.818 -1.36 21 56.818 -1.36 10 55.555 3.55 8
115.2 113.636 -1.36 21 113.636 -1.36 10 125.000 8.51 4 — — —
0.3 0.300 0.00 8332 0.300 0.02 4165 0.300 0.02 2082 0.300 -0.04 1665
1.2 1.200 0.02 2082 1.200 -0.03 1041 1.200 -0.03 520 1.201 -0.16 415
2.4 2.402 0.06 1040 2.399 -0.03 520 2.404 0.16 259 2.403 -0.16 207
9.6 9.615 0.16 259 9.615 0.16 129 9.615 0.16 64 9.615 -0.16 51
19.2 19.231 0.16 129 19.231 0.16 64 19.531 1.73 31 19.230 -0.16 25
57.6 58.140 0.94 42 56.818 -1.36 21 56.818 -1.36 10 55.555 3.55 8
115.2 113.636 -1.36 21 113.636 -1.36 10 125.000 8.51 4 — — —
0.3 0.300 0.04 832 0.300 -0.16 415 0.300 -0.16 207
1.2 1.202 0.16 207 1.201 -0.16 103 1.201 -0.16 51
2.4 2.404 0.16 103 2.403 -0.16 51 2.403 -0.16 25
9.6 9.615 0.16 25 9.615 -0.16 12 — — —
19.2 19.231 0.16 12 — — — — — —
57.6 62.500 8.51 3 — — — — — —
115.2 125.000 8.51 1 — — — — — —
0.3 0.300 0.00 33332 0.300 0.00 16665 0.300 0.00 8332 0.300 -0.01 6665
1.2 1.200 0.00 8332 1.200 0.02 4165 1.200 0.02 2082 1.200 -0.04 1665
2.4 2.400 0.02 4165 2.400 0.02 2082 2.402 0.06 1040 2.400 -0.04 832
9.6 9.606 0.06 1040 9.596 -0.03 520 9.615 0.16 259 9.615 -0.16 207
19.2 19.193 -0.03 520 19.231 0.16 259 19.231 0.16 129 19.230 -0.16 103
57.6 57.803 0.35 172 57.471 -0.22 86 58.140 0.94 42 57.142 0.79 34
115.2 114.943 -0.22 86 116.279 0.94 42 113.636 -1.36 21 117.647 -2.12 16
0.3 0.300 0.01 3332 0.300 -0.04 1665 0.300 -0.04 832
1.2 1.200 0.04 832 1.201 -0.16 415 1.201 -0.16 207
2.4 2.404 0.16 415 2.403 -0.16 207 2.403 -0.16 103
9.6 9.615 0.16 103 9.615 -0.16 51 9.615 -0.16 25
19.2 19.231 0.16 51 19.230 -0.16 25 19.230 -0.16 12
57.6 58.824 2.12 16 55.555 3.55 8 — — —
115.2 111.111 -3.55 8 — — — — — —
BRG Clock
RCIF bit
(Interrupt)
Read
RCREG
Note: The ABD sequence requires the EUSART module to be configured in Asynchronous mode and WUE = 0.
BRG Clock
ABDEN bit
ABDOVF bit
FFFFh
BRG Value XXXXh 0000h 0000h
TRMT SPEN
BRG16 SPBRGH SPBRG
TX9
Baud Rate Generator TX9D
Write to TXREG
Word 1
BRG Output
(Shift Clock)
TX (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)
TX (pin)
Start bit bit 0 bit 1 bit 7/8 Stop bit Start bit bit 0
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.
18.2.4 AUTO-WAKE-UP ON SYNC BREAK Following a wake-up event, the module generates an
CHARACTER RCIF interrupt. The interrupt is generated synchro-
nously to the Q clocks in normal operating modes
During Sleep mode, all clocks to the EUSART are
(Figure 18-8) and asynchronously, if the device is in
suspended. Because of this, the Baud Rate Generator
Sleep mode (Figure 18-9). The interrupt condition is
is inactive and a proper byte reception cannot be per-
cleared by reading the RCREG register.
formed. The auto-wake-up feature allows the controller
to wake-up due to activity on the RX/DT line while the The WUE bit is automatically cleared once a low-to-
EUSART is operating in Asynchronous mode. high transition is observed on the RX line following the
wake-up event. At this point, the EUSART module is in
The auto-wake-up feature is enabled by setting the
Idle mode and returns to normal operation. This signals
WUE bit (BAUDCON<1>). Once set, the typical receive
to the user that the Sync Break event is over.
sequence on RX/DT is disabled and the EUSART
remains in an Idle state, monitoring for a wake-up event
independent of the CPU mode. A wake-up event con-
sists of a high-to-low transition on the RX/DT line. (This
coincides with the start of a Sync Break or a Wake-up
Signal character for the LIN protocol.)
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
OSC1
Bit Set by User Auto-Cleared
WUE bit(1)
RX/DT Line
RCIF
Cleared Due to User Read of RCREG
Note 1: The EUSART remains in Idle while the WUE bit is set.
RX/DT Line
Note 1
RCIF
Cleared Due to User Read of RCREG
Sleep Command Executed Sleep Ends
Note 1: If the wake-up event requires long oscillator warm-up time, the auto-clear of the WUE bit can occur before the oscillator is ready. This
sequence should not depend on the presence of Q clocks.
2: The EUSART remains in Idle while the WUE bit is set.
Write to TXREG
Dummy Write
BRG Output
(Shift Clock)
Break
TXIF bit
(Transmit Buffer
Reg. Empty Flag)
TRMT bit
(Transmit Shift
Reg. Empty Flag)
SENDB Sampled Here Auto-Cleared
SENDB
(Transmit Shift
Reg. Empty Flag)
RC7/RX/DT
bit 0 bit 1 bit 2 bit 7 bit 0 bit 1 bit 7
Word 1 Word 2
RC6/TX/CK pin
(TXCKP = 0)
RC6/TX/CK pin
(TXCKP = 1)
Write to
TXREG Reg
Write Word 1 Write Word 2
TXIF bit
(Interrupt Flag)
TRMT 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
RC7/RX/DT
pin bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7
RC6/TX/CK pin
(TXCKP = 0)
RC6/TX/CK pin
(TXCKP = 1)
Write to
bit SREN
SREN bit
CREN bit ‘0’ ‘0’
RCIF bit
(Interrupt)
Read
RXREG
Note: Timing diagram demonstrates Sync Master mode with bit, SREN = 1, and bit, BRGH = 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
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 PBADEN Configuration bit. When
PBADEN = 1, PCFG<2:0> = 000; when PBADEN = 0, PCFG<2:0> = 111.
2: AN5 through AN7 are available only on 40/44-pin 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.
CHS<3:0>
1100
AN12
1011
AN11
1010
AN10
1001
AN9
1000
AN8
0111
AN7(1)
0110
AN6(1)
0101
AN5(1)
0100
AN4
VAIN
(Input Voltage) 0011
10-Bit AN3
A/D
Converter 0010
AN2
0001
VCFG<1:0> AN1
VDD(2) 0000
AN0
X0
VREF+ X1
Reference 1X
Voltage VREF- 0X
VSS(2)
Note 1: Channels, AN5 through AN7, are not available on 28-pin devices.
2: I/O pins have diode protection to VDD and VSS.
1022 LSB
1022.5 LSB
1023 LSB
1023.5 LSB
• Set GIE bit
3. Wait the required acquisition time (if required).
4. Start conversion:
Analog Input Voltage
• Set GO/DONE bit (ADCON0 register)
VSS
FIGURE 19-5: 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 TAD1
b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
Automatic
Acquisition Conversion starts Discharge
Time (Holding capacitor is disconnected)
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
Two Common Reference Comparators Two Common Reference Comparators with Outputs
CM<2:0> = 100 CM<2:0> = 101
A VIN- A VIN-
RA0/AN0 RA0/AN0
VIN+ C1 C1OUT VIN+ C1 C1OUT
RA3/AN3/ A RA3/AN3/ A
VREF+ VREF+
RA4/T0CKI/C1OUT*
A VIN-
RA1/AN1
C2 C2OUT RA1/AN1 A VIN-
RA2/AN2/ D VIN+
VREF-/CVREF RA2/AN2/ D VIN+ C2 C2OUT
VREF-/CVREF
RA5/AN4/SS/HLVDIN/C2OUT*
One Independent Comparator with Output Four Inputs Multiplexed to Two Comparators
CM<2:0> = 001 CM<2:0> = 110
A A
RA0/AN0 VIN- RA0/AN0
CIS = 0 VIN-
RA3/AN3/ A VIN+ C1 C1OUT RA3/AN3/ A CIS = 1
VIN+ C1 C1OUT
VREF+ VREF+
RA4/T0CKI/C1OUT* RA1/AN1 A
CIS = 0 VIN-
RA2/AN2/ A CIS = 1
D VIN- VIN+ C2 C2OUT
RA1/AN1 VREF-/CVREF
RA2/AN2/ D VIN+ C2 Off (Read as ‘0’)
CVREF
VREF-/CVREF From VREF Module
A = Analog Input, port reads zeros always D = Digital Input CIS (CMCON<3>) is the Comparator Input Switch
* Setting the TRISA<5:4> bits will disable the comparator outputs by configuring the pins as inputs.
MULTIPLEX
+
Port pins
To RA4 or
RA5 pin
-
D Q Bus
CxINV Data
Read CMCON EN
D Q Set
CMIF
bit
EN CL
From
Other
Reset Comparator
VDD
VT = 0.6V RIC
RS < 10k
Comparator
AIN Input
CPIN ILEAKAGE
VA VT = 0.6V ±100 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
CVRSS = 1
VREF+
VDD
CVRSS = 0 8R
CVR<3:0>
CVREN R
16-to-1 MUX
16 Steps
CVREF
R
R
CVRR 8R
CVRSS = 1
VREF-
CVRSS = 0
PIC18FXXXX
CVREF
R(1)
Module
+
Voltage RA2 CVREF Output
–
Reference
Output
Impedance
Note 1: R is dependent upon the comparator voltage reference configuration bits, CVRCON<3:0> and CVRCON<5>.
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
Set
HLVDIF
HLVDEN
Internal Voltage
BOREN Reference
VDD
VLVD
HLVDIF
Enable HLVD
TIRVST
IRVST
HLVDIF Cleared in Software
Internal Reference is Stable
CASE 2:
VDD
VLVD
HLVDIF
Enable HLVD
TIRVST
IRVST
Internal Reference is Stable
HLVDIF Cleared in Software
VLVD
VDD
HLVDIF
Enable HLVD
IRVST TIRVST
CASE 2:
VLVD
VDD
HLVDIF
Enable HLVD
IRVST TIRVST
300001h CONFIG1H IESO FCMEN — — FOSC3 FOSC2 FOSC1 FOSC0 00-- 0111
300002h CONFIG2L — — — BORV1 BORV0 BOREN1 BOREN0 PWRTEN ---1 1111
300003h CONFIG2H — — — WDTPS3 WDTPS2 WDTPS1 WDTPS0 WDTEN ---1 1111
300005h CONFIG3H MCLRE — — — — LPT1OSC PBADEN CCP2MX 1--- -011
300006h CONFIG4L DEBUG XINST — — — LVP — STVREN 10-- -1-1
300008h CONFIG5L — — — — CP3(1) CP2(1) CP1 CP0 ---- 1111
300009h CONFIG5H CPD CPB — — — — — — 11-- ----
30000Ah CONFIG6L — — — — WRT3(1) WRT2(1) WRT1 WRT0 ---- 1111
30000Bh CONFIG6H WRTD WRTB WRTC — — — — — 111- ----
(1) (1)
30000Ch CONFIG7L — — — — EBTR3 EBTR2 EBTR1 EBTR0 ---- 1111
30000Dh CONFIG7H — EBTRB — — — — — — -1-- ----
3FFFFEh DEVID1 DEV2 DEV1 DEV0 REV4 REV3 REV2 REV1 REV0 xxxx xxxx(2)
3FFFFFh DEVID2 DEV10 DEV9 DEV8 DEV7 DEV6 DEV5 DEV4 DEV3 xxxx xxxx(2)
Legend: x = unknown, u = unchanged, — = unimplemented, q = value depends on condition.
Shaded cells are unimplemented, read as ‘0’.
Note 1: Unimplemented in PIC18F2420/4420 devices; maintain this bit set.
2: See Register 23-12 for DEVID1 values. DEVID registers are read-only and cannot be programmed by the user.
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
Note 1: See Section 26.1 “DC Characteristics: Supply Voltage” for specifications.
2: 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 C = Clearable bit U = Unimplemented bit, read as ‘0’
-n = Value when device is unprogrammed u = Unchanged from programmed state
Note 1: This bit is read-only in normal execution mode; it can be written only in Program mode.
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 = Read-only bit P = Programmable bit U = Unimplemented bit, read as ‘0’
-n = Value when device is unprogrammed u = Unchanged from programmed state
Note 1: These values for DEV<10:3> may be shared with other devices. The specific device is always identified by
using the entire DEV<10:0> bit sequence.
WDTPS<3:0> 4
Sleep
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: This bit has no effect if the Configuration bit, WDTEN, is enabled.
OSC1
TOST(1) TPLL(1)
1 2 n-1 n
PLL Clock
Output
Clock
Transition(2)
CPU Clock
Peripheral
Clock
Program
Counter PC PC + 2 PC + 4 PC + 6
Note 1: TOST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
2: Clock transition typically occurs within 2-4 TOSC.
Sample Clock
Device Oscillator
Clock Failure
Output
CM Output
(Q)
Failure
Detected
OSCFIF
23.4.3 FSCM INTERRUPTS IN time considerably longer than the FCSM sample clock
POWER-MANAGED MODES time, a false clock failure may be detected. To prevent
this, the internal oscillator block is automatically config-
By entering a power-managed mode, the clock multi-
ured as the device clock and functions until the primary
plexer selects the clock source selected by the OSCCON
clock is stable (the OST and PLL timers have timed
register. Fail-Safe Clock Monitoring of the power-
out). This is identical to Two-Speed Start-up mode.
managed clock source resumes in the power-managed
Once the primary clock is stable, the INTRC returns to
mode.
its role as the FSCM source.
If an oscillator failure occurs during power-managed
operation, the subsequent events depend on whether Note: The same logic that prevents false oscilla-
or not the oscillator failure interrupt is enabled. If tor failure interrupts on POR, or wake from
enabled (OSCFIF = 1), code execution will be clocked Sleep, will also prevent the detection of
by the INTOSC multiplexer. An automatic transition the oscillator’s failure to start at all follow-
back to the failed clock source will not occur. ing these events. This can be avoided by
monitoring the OSTS bit and using a
If the interrupt is disabled, subsequent interrupts while timing routine to determine if the oscillator
in Idle mode will cause the CPU to begin executing is taking too long to start. Even so, no
instructions while being clocked by the INTOSC oscillator failure interrupt will be flagged.
source.
As noted in Section 23.3.1 “Special Considerations
23.4.4 POR OR WAKE FROM SLEEP for Using Two-Speed Start-up”, it is also possible to
select another clock configuration and enter an
The FSCM is designed to detect oscillator failure at any alternate power-managed mode while waiting for the
point after the device has exited Power-on Reset primary clock to become stable. When the new power-
(POR) or low-power Sleep mode. When the primary managed mode is selected, the primary clock is
device clock is EC, RC or INTRC modes, monitoring disabled.
can begin immediately following these events.
For oscillator modes involving a crystal or resonator
(HS, HSPLL, LP or XT), the situation is somewhat
different. Since the oscillator may require a start-up
Unimplemented
Read ‘0’s (Unimplemented Memory Space)
1FFFFFh
TBLPTR = 0008FFh
WRT0, EBTR0 = 01
007FFFh
000000h
WRTB, EBTRB = 11
0007FFh
000800h
TBLPTR = 0008FFh
WRT0, EBTR0 = 10
001FFFh
002000h
PC = 003FFEh TBLRD* WRT1, EBTR1 = 11
003FFFh
004000h
WRT2, EBTR2 = 11
005FFFh
006000h
WRT3, EBTR3 = 11
007FFFh
Results: All table reads from external blocks to Blockn are disabled whenever EBTRn = 0.
TABLAT register returns a value of ‘0’.
007FFFh
All bit-oriented instructions have three operands: The Instruction Set Summary, shown in Table 24-2,
lists the standard instructions recognized by the
1. The file register (specified by ‘f’) Microchip Assembler (MPASMTM).
2. The bit in the file register (specified by ‘b’)
Section 24.1.1 “Standard Instruction Set” provides
3. The accessed memory (specified by ‘a’) a description of each instruction.
The bit field designator ‘b’ selects the number of the bit
affected by the operation, while the file register
designator ‘f’ represents the number of the file in which
the bit is located.
Literal operations
15 8 7 0
OPCODE k (literal) MOVLW 7Fh
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
1111 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
BYTE-ORIENTED OPERATIONS
ADDWF f, d, a Add WREG and f 1 0010 01da ffff ffff C, DC, Z, OV, N 1, 2
ADDWFC f, d, a Add WREG and Carry bit to f 1 0010 00da ffff ffff C, DC, Z, OV, N 1, 2
ANDWF f, d, a AND WREG with f 1 0001 01da ffff ffff Z, N 1,2
CLRF f, a Clear f 1 0110 101a ffff ffff Z 2
COMF f, d, a Complement f 1 0001 11da ffff ffff Z, N 1, 2
CPFSEQ f, a Compare f with WREG, Skip = 1 (2 or 3) 0110 001a ffff ffff None 4
CPFSGT f, a Compare f with WREG, Skip > 1 (2 or 3) 0110 010a ffff ffff None 4
CPFSLT f, a Compare f with WREG, Skip < 1 (2 or 3) 0110 000a ffff ffff None 1, 2
DECF f, d, a Decrement f 1 0000 01da ffff ffff C, DC, Z, OV, N 1, 2, 3, 4
DECFSZ f, d, a Decrement f, Skip if 0 1 (2 or 3) 0010 11da ffff ffff None 1, 2, 3, 4
DCFSNZ f, d, a Decrement f, Skip if Not 0 1 (2 or 3) 0100 11da ffff ffff None 1, 2
INCF f, d, a Increment f 1 0010 10da ffff ffff C, DC, Z, OV, N 1, 2, 3, 4
INCFSZ f, d, a Increment f, Skip if 0 1 (2 or 3) 0011 11da ffff ffff None 4
INFSNZ f, d, a Increment f, Skip if Not 0 1 (2 or 3) 0100 10da ffff ffff None 1, 2
IORWF f, d, a Inclusive OR WREG with f 1 0001 00da ffff ffff Z, N 1, 2
MOVF f, d, a Move f 1 0101 00da ffff ffff Z, N 1
MOVFF fs, fd Move fs (source) to 1st word 2 1100 ffff ffff ffff None
fd (destination) 2nd word 1111 ffff ffff ffff
MOVWF f, a Move WREG to f 1 0110 111a ffff ffff None
MULWF f, a Multiply WREG with f 1 0000 001a ffff ffff None 1, 2
NEGF f, a Negate f 1 0110 110a ffff ffff C, DC, Z, OV, N
RLCF f, d, a Rotate Left f through Carry 1 0011 01da ffff ffff C, Z, N 1, 2
RLNCF f, d, a Rotate Left f (No Carry) 1 0100 01da ffff ffff Z, N
RRCF f, d, a Rotate Right f through Carry 1 0011 00da ffff ffff C, Z, N
RRNCF f, d, a Rotate Right f (No Carry) 1 0100 00da ffff ffff Z, N
SETF f, a Set f 1 0110 100a ffff ffff None 1, 2
SUBFWB f, d, a Subtract f from WREG with 1 0101 01da ffff ffff C, DC, Z, OV, N
Borrow
SUBWF f, d, a Subtract WREG from f 1 0101 11da ffff ffff C, DC, Z, OV, N 1, 2
SUBWFB f, d, a Subtract WREG from f with 1 0101 10da ffff ffff C, DC, Z, OV, N
Borrow
SWAPF f, d, a Swap Nibbles in f 1 0011 10da ffff ffff None 4
TSTFSZ f, a Test f, Skip if 0 1 (2 or 3) 0110 011a ffff ffff None 1, 2
XORWF f, d, a Exclusive OR WREG with f 1 0001 10da ffff ffff Z, N
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 the 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 two-word instructions. The second word of these instructions will be executed as a NOP unless the
first word of the instruction retrieves the information embedded in these 16 bits. This ensures that all program memory
locations have a valid instruction.
BIT-ORIENTED OPERATIONS
BCF f, b, a Bit Clear f 1 1001 bbba ffff ffff None 1, 2
BSF f, b, a Bit Set f 1 1000 bbba ffff ffff None 1, 2
BTFSC f, b, a Bit Test f, Skip if Clear 1 (2 or 3) 1011 bbba ffff ffff None 3, 4
BTFSS f, b, a Bit Test f, Skip if Set 1 (2 or 3) 1010 bbba ffff ffff None 3, 4
BTG f, d, a Bit Toggle f 1 0111 bbba ffff ffff None 1, 2
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
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 1 1111 xxxx xxxx xxxx None 4
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 the 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 two-word instructions. The second word of these instructions will be executed as a NOP unless the
first word of the instruction retrieves the information embedded in these 16 bits. This ensures that all program memory
locations have a valid instruction.
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 FSR(f) 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 WREG 1 0000 1010 kkkk kkkk Z, N
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 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 the 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 two-word instructions. The second word of these instructions will be executed as a NOP unless the
first word of the instruction retrieves the information embedded in these 16 bits. This ensures that all program memory
locations have a valid instruction.
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read Process Write to
register ‘f’ Data destination
Note: All PIC18 instructions may take an optional label argument preceding the instruction mnemonic for use in
symbolic addressing. If a label is used, the instruction format then becomes: {label} instruction argument(s).
Before Instruction No No No No
PC = address (HERE) operation operation operation operation
After Instruction
If Zero = 1; Example: HERE CALL THERE, 1
PC = address (Jump)
If Zero = 0; Before Instruction
PC = address (HERE + 2) PC = address (HERE)
After Instruction
PC = address (THERE)
TOS = address (HERE + 4)
WS = W
BSRS = BSR
STATUSS = STATUS
Q1 Q2 Q3 Q4 Q Cycle Activity:
Decode Read Process Write to Q1 Q2 Q3 Q4
register ‘f’ Data destination Decode Read Process Write to
If skip: register ‘f’ Data destination
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 DECFSZ CNT, 1, 1
GOTO LOOP Example: HERE DCFSNZ TEMP, 1, 0
CONTINUE ZERO :
NZERO :
Before Instruction
PC = Address (HERE) Before Instruction
After Instruction TEMP = ?
CNT = CNT – 1 After Instruction
If CNT = 0; TEMP = TEMP – 1,
PC = Address (CONTINUE) If TEMP = 0;
If CNT ≠ 0; PC = Address (ZERO)
PC = Address (HERE + 2) If TEMP ≠ 0;
PC = Address (NZERO)
W = E2h Q1 Q2 Q3 Q4
PRODH = ADh Decode Read Process Write
PRODL = 08h register ‘f’ Data registers
PRODH:
PRODL
Words: 1 C register f
Cycles: 1
Words: 1
Q Cycle Activity:
Cycles: 1
Q1 Q2 Q3 Q4
Decode Read Process Write to Q Cycle Activity:
register ‘f’ Data destination Q1 Q2 Q3 Q4
Decode Read Process Write to
Example: RLNCF REG, 1, 0 register ‘f’ Data destination
Before Instruction
REG = 1010 1011 Example: RRCF REG, 0, 0
After Instruction Before Instruction
REG = 0101 0111 REG = 1110 0110
C = 0
After Instruction
REG = 1110 0110
W = 0111 0011
C = 0
After Instruction Q1 Q2 Q3 Q4
TO = 1† Decode Read Process Write to
PD = 0 register ‘f’ Data destination
Example 1: SUBFWB REG, 1, 0
† If WDT causes wake-up, this bit is cleared.
Before Instruction
REG = 3
W = 2
C = 1
After Instruction
REG = FF
W = 2
C = 0
Z = 0
N = 1 ; result is negative
Example 2: SUBFWB REG, 0, 0
Before Instruction
REG = 2
W = 5
C = 1
After Instruction
REG = 2
W = 3
C = 1
Z = 0
N = 0 ; result is positive
Example 3: SUBFWB REG, 1, 0
Before Instruction
REG = 1
W = 2
C = 0
After Instruction
REG = 0
W = 2
C = 1
Z = 1 ; result is zero
N = 0
ADDFSR Add Literal to FSR ADDULNK Add Literal to FSR2 and Return
Syntax: ADDFSR f, k Syntax: ADDULNK k
Operands: 0 ≤ k ≤ 63 Operands: 0 ≤ k ≤ 63
f ∈ [ 0, 1, 2 ] Operation: FSR2 + k → FSR2,
Operation: FSR(f) + k → FSR(f) (TOS) → PC
Status Affected: None Status Affected: None
Encoding: 1110 1000 ffkk kkkk Encoding: 1110 1000 11kk kkkk
Description: The 6-bit literal ‘k’ is added to the Description: The 6-bit literal ‘k’ is added to the
contents of the FSR specified by ‘f’. contents of FSR2. A RETURN is then
Words: 1 executed by loading the PC with the
Cycles: 1 TOS.
The instruction takes two cycles to
Q Cycle Activity:
execute; a NOP is performed during
Q1 Q2 Q3 Q4 the second cycle.
Decode Read Process Write to This may be thought of as a special
literal ‘k’ Data FSR case of the ADDFSR instruction,
where f = 3 (binary ‘11’); it operates
only on FSR2.
Example: ADDFSR 2, 23h Words: 1
Before Instruction Cycles: 2
FSR2 = 03FFh
After Instruction
Q Cycle Activity:
FSR2 = 0422h
Q1 Q2 Q3 Q4
Decode Read Process Write to
literal ‘k’ Data FSR
No No No No
Operation Operation Operation Operation
Note: All PIC18 instructions may take an optional label argument preceding the instruction mnemonic for use in
symbolic addressing. If a label is used, the instruction syntax then becomes: {label} instruction argument(s).
MOVSS Move Indexed to Indexed PUSHL Store Literal at FSR2, Decrement FSR2
Syntax: MOVSS [zs], [zd] Syntax: PUSHL k
Operands: 0 ≤ zs ≤ 127 Operands: 0 ≤ k ≤ 255
0 ≤ zd ≤ 127
Operation: k → (FSR2),
Operation: ((FSR2) + zs) → ((FSR2) + zd) FSR2 – 1 → FSR2
Status Affected: None
Status Affected: None
Encoding:
Encoding: 1111 1010 kkkk kkkk
1st word (source) 1110 1011 1zzz zzzzs
2nd word (dest.) 1111 xxxx xzzz zzzzd Description: The 8-bit literal ‘k’ is written to the data
memory address specified by FSR2. FSR2
Description The contents of the source register are
is decremented by 1 after the operation.
moved to the destination register. The
This instruction allows users to push values
addresses of the source and destination
onto a software stack.
registers are determined by adding the
7-bit literal offsets ‘zs’ or ‘zd’, Words: 1
respectively, to the value of FSR2. Both
Cycles: 1
registers can be located anywhere in
the 4096-byte data memory space Q Cycle Activity:
(000h to FFFh). Q1 Q2 Q3 Q4
The MOVSS instruction cannot use the Decode Read ‘k’ Process Write to
PCL, TOSU, TOSH or TOSL as the data destination
destination register.
If the resultant source address points to
an indirect addressing register, the Example: PUSHL 08h
value returned will be 00h. If the
resultant destination address points to Before Instruction
an indirect addressing register, the FSR2H:FSR2L = 01ECh
Memory (01ECh) = 00h
instruction will execute as a NOP.
Words: 2 After Instruction
Cycles: 2 FSR2H:FSR2L = 01EBh
Memory (01ECh) = 08h
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Determine Determine Read
source addr source addr source reg
Decode Determine Determine Write
dest addr dest addr to dest reg
SUBFSR Subtract Literal from FSR SUBULNK Subtract Literal from FSR2 and Return
Syntax: SUBFSR f, k Syntax: SUBULNK k
Operands: 0 ≤ k ≤ 63 Operands: 0 ≤ k ≤ 63
f ∈ [ 0, 1, 2 ] Operation: FSR2 – k → FSR2,
Operation: FSR(f) – k → FSRf (TOS) → PC
Status Affected: None Status Affected: None
Encoding: 1110 1001 ffkk kkkk Encoding: 1110 1001 11kk kkkk
Description: The 6-bit literal ‘k’ is subtracted from Description: The 6-bit literal ‘k’ is subtracted from the
the contents of the FSR specified by contents of the FSR2. A RETURN is then
‘f’. executed by loading the PC with the TOS.
Words: 1 The instruction takes two cycles to
execute; a NOP is performed during the
Cycles: 1
second cycle.
Q Cycle Activity: This may be thought of as a special case of
Q1 Q2 Q3 Q4 the SUBFSR instruction, where f = 3 (binary
Decode Read Process Write to ‘11’); it operates only on FSR2.
register ‘f’ Data destination Words: 1
Cycles: 2
Q Cycle Activity:
Example: SUBFSR 2, 23h
Before Instruction Q1 Q2 Q3 Q4
FSR2 = 03FFh Decode Read Process Write to
register ‘f’ Data destination
After Instruction
FSR2 = 03DCh No No No No
Operation Operation Operation Operation
† 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 PIC18F2420/2520/4420/4520
4.5V
Voltage
4.2V
4.0V
3.5V
3.0V
2.5V
2.0V
40 MHz
Frequency
6.0V
5.5V
5.0V PIC18F2420/2520/4420/4520
4.5V
Voltage
4.2V
4.0V
3.5V
3.0V
2.5V
2.0V
25 MHz
Frequency
6.0V
5.5V
5.0V
PIC18LF2420/2520/4420/4520
4.5V
Voltage
4.2V
4.0V
3.5V
3.0V
2.5V
2.0V
4 MHz 40 MHz
Frequency
FMAX = (16.36 MHz/V) (VDDAPPMIN – 2.0V) + 4 MHz
Note: VDDAPPMIN is the minimum voltage of the PIC® device in the application.
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 PIC18FXXXX
300A — 150 600 ns PIC18LFXXXX,
VDD = 2.0V
301 TMC2OV Comparator Mode Change to — — 10 μs
Output Valid
Note 1: Response time measured with one comparator input at (VDD – 1.5)/2, while the other input transitions
from VSS to VDD.
VDD
(HLVDIF can be
VLVD cleared in software)
(HLVDIF set by hardware)
HLVDIF(1)
Note 1: VDIRMAG = 0.
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
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, 31 kHz(1)
PIC18LF2420/2520/4420/4520 -2 +/-1 2 % +25°C VDD = 2.7-3.3V
-5 +/-1 5 % -40°C to +85°C VDD = 2.7-3.3V
PIC18F2420/2520/4420/4520 -2 +/-1 2 % +25°C VDD = 4.5-5.5V
-5 +/-1 5 % -40°C to +85°C VDD = 4.5-5.5V
INTRC Accuracy @ Freq = 31 kHz
PIC18LF2420/2520/4420/4520 26.562 — 35.938 kHz -40°C to +85°C VDD = 2.7-3.3V
PIC18F2420/2520/4420/4520 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.
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
VDD BVDD
35
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.
30 TmcL MCLR Pulse Width (low) 2 — — μs
31 TWDT Watchdog Timer Time-out Period 3.4 4.1 4.71 ms
(no postscaler)
32 TOST Oscillation Start-up Timer Period 1024 TOSC — 1024 TOSC — TOSC = OSC1 period
33 TPWRT Power-up Timer Period 55.6 65.5 75.4 ms
34 TIOZ I/O High-Impedance from MCLR — 2 — μs
Low or Watchdog Timer Reset
35 TBOR Brown-out Reset Pulse Width 200 — — μs VDD ≤ BVDD (see D005)
36 TIRVST Time for Internal Reference — 20 50 μs
Voltage to become Stable
37 TLVD High/Low-Voltage Detect Pulse Width 200 — — μs VDD ≤ VLVD
38 TCSD CPU Start-up Time — 10 — μs
39 TIOBST Time for INTOSC to Stabilize — 1 — μs
T0CKI
40 41
42
T1OSO/T13CKI
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
RD<7:0>
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
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)
79 78
80
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
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 (1) 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.
Test instrument results are compressed to about 0.05 μA for actual values below 0.05 mA.
Measurements below 0.01 mA are suspect and considered unmeasurable .
This is supported by the instrument specifications.
10 5.5
5.0
4.5
4.0
Ipd (uA)
3.5
1
3.0
2.5
2.0
0.1
0.01
-50 -25 0 25 50 75 100 125
Temp (C)
10
125°C
IPD (uA)
1 85°C
25°C
0.1
-40°C
0.01
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 27-3: MAXIMUM IPD vs. VDD ACROSS TEMPERATURE (SLEEP MODE)
100
125°C
10
85°C
IPD (uA)
25°C
-40°C
0.1
0.01
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
2.5
2.0
85°C
IPD (uA)
1.5
25°C
1.0
-10°C
0.5
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 27-5: MAXIMUM T1OSC DELTA CURRENT vs. VDD ACROSS TEMP. (DEVICE IN SLEEP,
TIOSC IN LOW-POWER MODE)
4
85°C
25°C
-10°C
IPD (uA)
0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
14
12
10
IPD (uA)
8
85°C
25°C
6
-40°C
0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
DD
FIGURE 27-7: MAXIMUM T1OSC DELTA CURRENT vs. VDD ACROSS TEMP. (DEVICE IN SLEEP,
T1OSC IN HIGH-POWER MODE)
30
25
20
IPD (uA)
15
85°C
10
25°C
-40°C
0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
V DD (V)
50.00
Device
Held in
RESET MAX
45.00
MAX (85°C)
40.00
TYP (25°C)
IPD (uA)
35.00
MIN (-40°C)
30.00
Device
in
SLEEP
25.00
20.00
2 2.5 3 3.5 4 4.5 5 5.5
VDD (V)
6.00
25°C
4.00 -40°C
IPD (uA)
3.00
2.00
1.00
0.00
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
12.0
10.0
125°C
8.0
85°C
IPD (uA)
6.0
25°C -40°C
4.0
2.0
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
4.2V
8 MHz
4 MHz
2 MHz
IDD (mA)
1 1 MHz
500 kHz
250 kHz
125 kHz
0.1
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
8 MHz
4.2V
4 MHz
2 MHz
IDD (mA)
1 MHz
1
0.1
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
Maximum
100 (-40°C)
Typical
(25°C)
10
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
4.2V
8 MHz
1 4 MHz
2 MHz
IDD (mA)
1 MHz
0.01
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
4.2V
8 MHz
IDD (mA)
4 MHz
1
2 MHz
1 MHz
125 kHz
0.1
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 27-16: TYPICAL AND MAXIMUM IDD ACROSS VDD (RC_IDLE MODE, 31 kHz)
25
20
15
IDD (uA)
Maximum
(85°C)
10
Typical
(25°C)
0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
120.0
Max (-10°C)
100.0
80.0
IDD (uA)
60.0
Typ (85°C)
Typ (25°C)
20.0
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 27-18: TYPICAL AND MAXIMUM SEC_IDLE CURRENT vs. VDD ACROSS TEMPERATURE
(T1OSC IN LOW-POWER MODE)
14.0
12.0
Typ (25°C)
10.0
Max (85°C)
8.0
IDD (uA)
Typ (85°C)
6.0
Typ (-10°C)
4.0
2.0
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
2.5
5.5V
5.0V
2.0
4.5V
IDD (mA)
1.5 4.0V
3.5V
1.0 3.0V
2.5V
2.0V
0.5
0.0
0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0
Fosc (MHz)
FIGURE 27-20: MAXIMUM IDD vs. FOSC, 500 kHz TO 4 MHz (PRI_RUN MODE (EC CLOCK),
-40°C TO +125°C)
4.5
4.0 5.5V
3.5 5.0V
3.0 4.5V
4.0V
IDD (mA)
2.5
2.0 3.5V
1.5 3.0V
1.0 2.5V
2.0V
0.5
0.0
0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0
Fosc (MHz)
5.0V
16
4.5V
14
4.0V
12
IDD (mA)
10
3.5V
8
6
3.0V
4
2.5V
2
2.0V
0
4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
Fosc (MHz)
FIGURE 27-22: MAXIMUM IDD vs. FOSC, 4 MHz TO 40 MHz (PRI_RUN MODE (EC CLOCK),
-40°C TO +125°C)
24
22
5.5V
20
5.0V
18
4.5V
16
4.0V
14
IDD (mA)
12
10 3.5V
6
3.0V
4
2.5V
2
2.0V
0
4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
Fosc (MHz)
22
20
18
5.5V
16
IDD (mA)
5.0V
14
4.5V
12
4.2V
10
4
16 18 20 22 24 26 28 30 32 34 36 38 40
Fosc (MHz)
FIGURE 27-24: MAXIMUM IDD vs. FOSC, HS/PLL (PRI_RUN MODE, -40°C)
24
22
20
5.5V
18
5.0V
16
I DD (mA)
4.5V
14
4.2V
12
10
4
16 18 20 22 24 26 28 30 32 34 36 38 40
Fosc (MHz)
1.0
0.9
5.5V
0.8
5.0V
0.7
4.5V
IDD (mA)
0.6
4.0V
0.5
3.5V
0.4
3.0V
0.3 2.5V
2.0V
0.2
0.1
0.0
0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0
Fosc (MHz)
FIGURE 27-26: MAXIMUM IDD vs. FOSC, 500 kHz TO 4 MHz (PRI_IDLE MODE, -40°C TO +125°C)
1.2
1.1
1.0
5.5V
0.9
5.0V
0.8
4.5V
0.7
IDD (mA)
4.0V
0.6
0.5 3.5V
3.0V
0.4
2.5V
0.3
2.0V
0.2
0.1
0.0
0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0
Fosc (MHz)
11
10
9 5.5V
8 5.0V
7
4.5V
IDD (mA)
6 4.0V
4 3.5V
3
3.0V
2
1 2.5V
2.0V
0
4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
Fosc (MHz)
FIGURE 27-28: MAXIMUM IDD vs. FOSC, 4 MHz TO 40 MHz (PRI_IDLE MODE, -40°C TO +125°C)
12
11
10
5.5V
9
5.0V
8
4.5V
7
IDD (mA)
4.0V
6
5
3.5V
4
3
3.0V
2
1 2.5V
2.0V
0
4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
Fosc (MHz)
11
10
8
5.5V
7
IDD (mA)
5.0V
6
4.5V
4.2V
5
0
16 18 20 22 24 26 28 30 32 34 36 38 40
Fosc (MHz)
FIGURE 27-30: MAXIMUM IDD vs. FOSC, HS/PLL (PRI_IDLE MODE, -40°C)
12
11
10
9
5.5V
8
5.0V
7
IDD (mA)
4.5V
6 4.2V
0
16 18 20 22 24 26 28 30 32 34 36 38 40
Fosc (MHz)
4.0
3.5
VIH Min
(-40°C)
VIH Typ
3.0 (25°C)
VIH Max
(125°C)
2.5
VIN (V)
2.0
1.5
1.0
VIL Max
VIL Typ (-40°C)
0.5 VIL Min
(125°C) (25°C)
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
1.6
VIH Max
(-40°C)
1.4
VIH Typ
(25°C)
VIH Min
1.2 (125°C)
1.0
VIN (V)
0.8
0.6
0.4
0.2
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
1.8
1.6
1.4
Max (85°C)
1.2
VOL (V)
1.0
0.8
Typ (25°C)
0.6
0.4
Min (-40°C)
0.2
0.0
0 5 10 15 20 25
IOL (-ma)
1.8
1.6
1.4
1.2
VOL (V)
1.0
0.8
Max (85°C)
0.6
Typ (25°C)
0.4
0.2
Min (-40°C)
0.0
0 5 10 15 20 25
I OL (-ma)
3.0
2.5
2.0
Max (-40°C)
VOH (V)
1.5
Typ (25°C)
Min (85°C)
1.0
0.5
0.0
0 5 10 15 20 25
I OH (-ma)
5.0
4.5
Max (-40°C)
4.0
3.5
Typ (25°C)
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
I OH (-ma)
Max Freq
8.3
8.2
125°C Typ
85°C Typ
8.1
Freq (MHz)
25°C Typ
8.0
-40°C Typ
7.9
7.8
Min Freq
7.7
7.6
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
35
34
Freq (kHz)
Max (-40°C)
33
32
31
30 Typ (25°C)
29 Min (85°C)
28
27
Min (125°C)
26
25
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
4.6
Longest
4.4
3.8
3.6
3.4
3.2
3.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
XXXXXXXXXXXXXXXXX PIC18F2520-I/SP e3
XXXXXXXXXXXXXXXXX 0810017
YYWWNNN
XXXXXXXXXXXXXXXXXXXX PIC18F2520-E/SO e3
XXXXXXXXXXXXXXXXXXXX 0810017
XXXXXXXXXXXXXXXXXXXX
YYWWNNN
XXXXXXXX 18F2420
XXXXXXXX -I/ML e3
YYWWNNN 0810017
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.
XXXXXXXXXXXXXXXXXX PIC18F4420-I/P e3
XXXXXXXXXXXXXXXXXX 0810017
XXXXXXXXXXXXXXXXXX
YYWWNNN
XXXXXXXXXX PIC18F4520
XXXXXXXXXX -I/ML e3
XXXXXXXXXX 0810017
YYWWNNN
XXXXXXXXXX PIC18F4420
XXXXXXXXXX -I/PT e3
XXXXXXXXXX 0810017
YYWWNNN
NOTE 1
E1
1 2 3
A A2
L c
A1 b1
b e eB
6&! 7,8.
'!
9'&! 7 7: ;
7"')
%! 7 <
& 1,
&
& = =
##4
4!! -
1!&
& = =
"# &
"# >#& . - --
##4>#& . <
: 9& - -?
&
& 9 -
9#
4!! <
6 9#>#& )
9
* 9#>#& ) <
:
*+ 1 = = -
!"
!"#$%&" ' ()"&'"!&)
&#*&&&#
+%&, & !&
- '!
!#.#
&"#'
#%!
& "!
!
#%!
& "!
!!
&$#/ !#
'!
#&
.0
1,2 1!'!
&$& "!
**&
"&&
!
* ,1
#
# $% &'(
#)
!" 3
&'
!&" &4# *!(!!&
4%&
&#&
&&255***'
'54
D
N
E
E1
NOTE 1
1 2 3
e
b
h
α
h
φ c
A A2
L
A1 L1 β
&
I B = <B
9#
4!! < = --
9#>#& ) - =
# %&
D B = B
# %&1
&&
' E B = B
!"
!"#$%&" ' ()"&'"!&)
&#*&&&#
+%&, & !&
- '!
!#.#
&"#'
#%!
& "!
!
#%!
& "!
!!
&$#'' !#
'!
#&
.0
1,2 1!'!
&$& "!
**&
"&&
!
.32 % '!
("!"*&
"&&
(%
%
'&
"
!!
* ,1
D D2
EXPOSED
PAD
E
b
E2
2 2
1 1 K
N N
NOTE 1 L
TOP VIEW BOTTOM VIEW
A3 A1
NOTE 1
E1
1 2 3
A A2
L c
b1
A1
b e eB
6&! 7,8.
'!
9'&! 7 7: ;
7"')
%! 7
& 1,
&
& = =
##4
4!! =
1!&
& = =
"# &
"# >#& . = ?
##4>#& . < = <
: 9& < =
&
& 9 =
9#
4!! < =
6 9#>#& ) - =
9
* 9#>#& ) = -
:
*+ 1 = =
!"
!"#$%&" ' ()"&'"!&)
&#*&&&#
+%&, & !&
- '!
!#.#
&"#'
#%!
& "!
!
#%!
& "!
!!
&$#/ !#
'!
#&
.0
1,2 1!'!
&$& "!
**&
"&&
!
* ,?1
D D2
EXPOSED
PAD
E2
b
2 2
1 1
N N K
NOTE 1 L
A3 A1
* ,-1
D
D1
E
e
E1
N
b
NOTE 1 1 2 3
NOTE 2
A α
c φ
β A1 A2
L L1
& I B -B B
: >#& . 1,
: 9& 1,
##4>#& . 1,
##49& 1,
9#
4!! =
9#>#& ) - -
# %&
D B B -B
# %&1
&&
' E B B -B
!"
!"#$%&" ' ()"&'"!&)
&#*&&&#
,'% !&
!
&
D!E'
- '!
!#.#
&"#'
#%!
& "!
!
#%!
& "!
!!
&$#'' !#
'!
#&
.0
1,2 1!'!
&$& "!
**&
"&&
!
.32 % '!
("!"*&
"&&
(%
%
'&
"
!!
* ,?1
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?
01/02/08