This document includes the programming specifications
for the following devices:
• PIC18F2221• PIC18F4221
• PIC18F2321• PIC18F4321
• PIC18F2410• PIC18F4410
• PIC18F2420• PIC18F4420
• PIC18F2455• PIC18F4455
• PIC18F2480• PIC18F4480
• PIC18F2510• PIC18F4510
• PIC18F2515• PIC18F4515
• PIC18F2520• PIC18F4520
• PIC18F2525• PIC18F4525
• PIC18F2550• PIC18F4550
• PIC18F2580• PIC18F4580
• PIC18F2585• PIC18F4585
• PIC18F2610• PIC18F4610
• PIC18F2620• PIC18F4620
• PIC18F2680• PIC18F4680
2.0PROGRAMMING OVERVIEW
PIC18F2XX0/2X21/2XX5/4XX0/4X21/4XX5 devices
can be programmed using either the high-voltage
In-Circuit Serial Programming™ (ICSP™) method or
the low-voltage ICSP method. Both methods can be
done with the device in the users’ system. The
low-voltage ICSP method is slightly different than the
high-voltage method and these differences are noted
where applicable. This programming specification
applies to PIC18F2XX0/2X21/2XX5/4XX0/4X21/4XX5
devices in all package types.
2.1Hardware Requirements
In High-Voltage ICSP mode, PIC18F2XX0/2X21/2XX5/
4XX0/4X21/4XX5 devices require two programmable
power supplies: one for VDD and one for MCLR/VPP/
RE3. Both supplies should have a minimum resolution
of 0.25V. Refer to Section 6.0 “AC/DC Characteris-
tics Timing Requirements for Program/Verify Test
Mode” for additional hardware parameters.
2.1.1LOW-VOLTAGE ICSP
PROGRAMMING
In Low-Voltage ICSP mode, PIC18F2XX0/2X21/2XX5/
4XX0/4X21/4XX5 devices can be programmed using a
VDD source in the operating range. The MCLR/VPP/
RE3 does not have to be brought to a different voltage,
but can instead be left at the normal operating voltage.
Refer to Section 6.0 “AC/DC Characteristics TimingRequirements for Program/Verify Test Mode” for
additional hardware parameters.
2.2Pin Diagrams
The pin diagrams for the PIC18F2XX0/2X21/2XX5/
4XX0/4X21/4XX5 family are shown in Figure 2-1 and
Figure 2-2.
TABLE 2-1:PIN DESCRIPTIONS (DURING PROGRAMMING):
PIC18F2XX0/2X21/2XX5/4XX0/4X21/4XX5
Pin Name
MCLR
/VPP/RE3VPPPProgramming Enable
(2)
DD
V
(2)
V
SS
RB5PGMILow-Voltage ICSP™ Input when LVP
RB6PGCISerial Clock
RB7PGDI/OSerial Data
Legend:I = Input, O = Output, P = Power
Note 1:See Figure 5-1
FIGURE 2-2:PIC18F2XX0/2X21/2XX5/4XX0/4X21/4XX5 FAMILY PIN DIAGRAMS
/ICPORTS
44-Pin TQFP
The following devices are included in
40-pin TQFP parts:
• PIC18F4221• PIC18F4515
• PIC18F4321• PIC18F4525
• PIC18F4410• PIC18F4550
• PIC18F4420• PIC18F4580
• PIC18F4455• PIC18F4585
• PIC18F4480• PIC18F4610
• PIC18F4510• PIC18F4620
• PIC18F4520• PIC18F4680
RC7
RD4
RD5
RD6
RD7
V
SS
VDD
RB0
RB1
RB2
RB3
1
2
3
4
5
6
7
8
9
10
11
RC6
RC5
44
43
121314
RC4
RD3
RD2
RD1
414039
42
PIC18F4XXX
15
16
17
(1)
RD0
RC3
RC2
RC1
363435
37
38
1819202122
NC
33
32
31
30
29
28
27
26
25
24
23
(1)
NC
RC0
OSC2
OSC1
V
SS
VDD
RE2
RE1
RE0
RA5
RA4
/ICVPP
Note 1: These pins are NC (No Connect) for all devices listed
above with the exception of the PIC18F4221,
PIC18F4321, PIC18F4455 and the PIC18F4550
devices (see Section 2.8 “Dedicated ICSP/ICDPort (44-Pin TQFP Only)” for more information on
programming these pins in these devices).
44-Pin QFN
The following devices are included in
44-pin QFN parts:
For PIC18FX6X0 devices, the code memory space
extends from 0000h to 0FFFFh (64 Kbytes) in four
16-Kbyte blocks. For PIC18FX5X5 devices, the code
memory space extends from 0000h to 0BFFFFh
(48 Kbytes) in three 16-Kbyte blocks. Addresses
0000h through 07FFh, however, define a “Boot Block”
region that is treated separately from Block 0. All of
these blocks define code protection boundaries within
the code memory space.
The size of the Boot Block in PIC18F2585/2680/4585/
4680 devices can be configured as 1, 2 or 4K words
(see Table 5-1). This is done through the BBSIZ<1:0>
bits in the Configuration register, CONFIG4L. It is
important to note that increasing the size of the Boot
Block decreases the size of Block 0.
DeviceCode Memory Size (Bytes)
PIC18F2515
PIC18F2525
PIC18F2585
PIC18F4515
PIC18F4525
PIC18F4585
PIC18F2610
PIC18F2620
PIC18F2680
PIC18F4610
PIC18F4620
PIC18F4680
FIGURE 2-3:MEMORY MAP AND THE CODE MEMORY SPACE
FOR PIC18FX5X5/X6X0 DEVICES
000000h
01FFFFh
Code Memory
64 Kbytes
(PIC18FX6X0)
MEMORY SIZE/DEVICE
MEMORY
000000h-00BFFFh (48K)
000000h-00FFFFh (64K)
48 Kbytes
(PIC18FX5X5)
Address
Range
200000h
3FFFFFh
Unimplemented
Read as ‘0’
Configuration
and ID
Space
11/100100
Boot
Block*
Block 0
Boot
Block*
Block 0
Boot
Block*
Block 0
Block 1
Block 1
Block 2
Block 3
Unimplemented
Reads all ‘0’s
BBSIZ<1:0>
11/100100
Boot
Block*
Block 0
Unimplemented
Reads all ‘0’s
Boot
Block*
Block 0
Block 1
Block 2
Boot
Block*
Block 0
000000h
0007FFh
000800h
000FFFh
001000h
001FFFh
002000h
003FFFh
004000h
007FFFh
008000h
00BFFFh
00C000h
00FFFFh
01FFFFh
Note: Sizes of memory areas are not to scale.
* Boot Block size is determined by the BBSIZ1:BBSIZ0 bits in CONFIG4L.
extends from 000000h to 007FFFh (32 Kbytes) in four
8-Kbyte blocks. For PIC18FX4X5 devices, the code
memory space extends from 000000h to 005FFFh
(24 Kbytes) in three 8-Kbyte blocks. Addresses
000000h through 0007FFh, however, define a “Boot
Block” region that is treated separately from Block 0. All
of these blocks define code protection boundaries
within the code memory space.
extends from 000000h to 003FFFh (16 Kbytes) in two
8-Kbyte blocks. Addresses 000000h through 0003FFh,
however, define a “Boot Block” region that is treated
separately from Block 0. All of these blocks define code
protection boundaries within the code memory space.
space extends from 0000h to 03FFFh (16 Kbytes) in
one 16-Kbyte block. For PIC18F2580/4580 devices,
the code memory space extends from 0000h to
07FFFh (32 Kbytes) in two 16-Kbyte blocks.
Addresses 0000h through 07FFh, however, define a
“Boot Block” region that is treated separately from
Block 0. All of these blocks define code protection
boundaries within the code memory space.
DeviceCode Memory Size (Bytes)
PIC18F2480
PIC18F4480
PIC18F2580
PIC18F4580
The size of the Boot Block in PIC18F2480/2580/4480/
4580 devices can be configured as 1 or 2K words (see
Table 5-1). This is done through the BBSIZ bit in the
Configuration register, CONFIG4L. It is important to
note that increasing the size of the Boot Block
decreases the size of Block 0.
FIGURE 2-6:MEMORY MAP AND THE CODE MEMORY SPACE
FOR PIC18F2480/2580/4480/4580 DEVICES
000000h
01FFFFh
Code Memory
Unimplemented
Read as ‘0’
32 Kbytes
(PIC18FX580)
10 1 0
Boot Block*
MEMORY SIZE/DEVICE
BBSIZ<0>
Boot Block*
Boot Block*
MEMORY
000000h-003FFFh (16K)
000000h-007FFFh (32K)
16 Kbytes
(PIC18FX480)
Boot Block*
Address
Range
000000h
0007FFh
000800h
000FFFh
001000h
Block 0Block 0
200000h
Configuration
and ID
Space
3FFFFFh
Unimplemented
Reads all ‘0’s
Note: Sizes of memory areas are not to scale.
* Boot Block size is determined by the BBSIZ bit in CONFIG4L.
space extends from 0000h to 00FFFh (4 Kbytes) in one
4-Kbyte block. For PIC18F2321/4321 devices, the
code memory space extends from 0000h to 01FFFh
(8 Kbytes) in two 4-Kbyte blocks. Addresses 0000h
through 07FFh, however, define a variable “Boot Block”
region that is treated separately from Block 0. All of
these blocks define code protection boundaries within
the code memory space.
DeviceCode Memory Size (Bytes)
PIC18F2221
PIC18F4221
PIC18F2321
PIC18F4321
The size of the Boot Block in PIC18F2221/2321/4221/
4321 devices can be configured as 256, 512 or
1024 words (see Figure 2-7). This is done through the
BBSIZ<1:0> bits in the Configuration register,
CONFIG4L (see Table 5-1). It is important to note that
increasing the size of the Boot Block decreases the
size of Block 0.
FIGURE 2-7:MEMORY MAP AND THE CODE MEMORY SPACE
FOR PIC18F2221/2321/4221/4321 DEVICES
MEMORY SIZE/DEVICE
000000h
01FFFFh
200000h
Code Memory
Unimplemented
Read as ‘0’
11/10010011/10/0100
Boot Block*
1K word
Block 0
1K word
8Kbytes
(PIC18FX321)
Boot Block*
512 words
Block 0
1.5K words
BBSIZ<1:0>
Boot Block*
256 words
Block 0
1.75K words
MEMORY
4Kbytes
(PIC18FX221)
Boot Block*
512 words
Block 0
0.5K words
000000h-000FFFh (4K)
000000h-001FFFh (8K)
Address
Range
Boot Block*
256 words
Block 0
0.75K words
Block 1
1K word
000000h
0001FFh
000200h
0003FFh
000400h
0007FFh
000800h
000FFFh
001000h
Configuration
and ID
Space
3FFFFFh
Note: Sizes of memory areas are not to scale.
* Boot Block size is determined by the BBSIZ<1:0> bits in CONFIG4L.
In addition to the code memory space, there are three
blocks that are accessible to the user through table
reads and table writes. Their locations in the memory
map are shown in Figure 2-8.
Users may store identification information (ID) in eight
ID registers. These ID registers are mapped in
addresses 200000h through 200007h. The ID locations
read out normally, even after code protection is applied.
2.3.1MEMORY ADDRESS POINTER
Memory in the address space, 0000000h to 3FFFFFh,
is addressed via the Table Pointer register, which is
comprised of three Pointer registers:
• TBLPTRU, at RAM address 0FF8h
• TBLPTRH, at RAM address 0FF7h
• TBLPTRL, at RAM address 0FF6h
Locations 300000h through 30000Dh are reserved for
the configuration bits. These bits select various device
options and are described in Section 5.0 “Configura-
TBLPTRUTBLPTRHTBLPTRL
Addr[21:16]Addr[15:8]Addr[7:0]
tion Word”. These configuration bits read out normally,
even after code protection.
Locations 3FFFFEh and 3FFFFFh are reserved for the
device ID bits. These bits may be used by the program-
The 4-bit command, ‘0000’ (core instruction), is used to
load the Table Pointer prior to using many read or write
operations.
mer to identify what device type is being programmed
and are described in Section 5.0 “ConfigurationWord”. These device ID bits read out normally, even
after code protection.
FIGURE 2-8:CONFIGURATION AND ID LOCATIONS FOR PIC18F2XX0/2X21/2XX5/4XX0/4X21/4XX5
Figure 2-9 shows the high-level overview of the
programming process. First, a Bulk Erase is performed.
Next, the code memory, ID locations and data EEPROM
are programmed (selected devices only, see Section 3.3“Data EEPROM Programming”). These memories are
then verified to ensure that programming was successful.
If no errors are detected, the configuration bits are then
programmed and verified.
FIGURE 2-9:HIGH-LEVEL
PROGRAMMING FLOW
Start
Perform Bulk
Erase
Program Memory
Program IDs
2.5Entering and Exiting High-Voltage
ICSP Program/Verify Mode
As shown in Figure 2-10, the High-Voltage ICSP
Program/Verify mode is entered by holding PGC and
PGD low and then raising MCLR/VPP/RE3 to VIHH
(high voltage). Once in this mode, the code memory,
data EEPROM (selected devices only, see Section 3.3“Data EEPROM Programming”), ID locations and
configuration bits can be accessed and programmed in
serial fashion. Figure 2-11 shows the exit sequence.
The sequence that enters the device into the Program/
Verify mode places all unused I/Os in the high-impedance
state.
2.6Entering and Exiting Low-Voltage
ICSP Program/Verify Mode
When the LVP configuration bit is ‘1’ (see Section 5.3
“Single-Supply ICSP Programming”), the
Low-Voltage ICSP mode is enabled. As shown in
Figure 2-12, Low-Voltage ICSP Program/Verify mode
is entered by holding PGC and PGD low, placing a logic
high on PGM and then raising MCLR
In this mode, the RB5/PGM pin is dedicated to the
programming function and ceases to be a general
purpose I/O pin. Figure 2-13 shows the exit sequence.
The sequence that enters the device into the Program/
Verify mode places all unused I/Os in the high-impedance
state.
FIGURE 2-12:ENTERING LOW-VOLTAGE
PROGRAM/VERIFY MODE
P15
MCLR/VPP/RE3
VDD
VIH
PGM
PGD
PGC
VIH
PGD = Input
FIGURE 2-13:EXITING LOW-VOLTAGE
PROGRAM/VERIFY MODE
P16
MCLR/VPP/RE3
VDD
PGM
PGD
PGC
VIH
PGD = Input
/VPP/RE3 to VIH.
P12
P18
VIH
2.7Serial Program/Verify Operation
The PGC pin is used as a clock input pin and the PGD
pin is used for entering command bits and data input/
output during serial operation. Commands and data are
transmitted on the rising edge of PGC, latched on the
falling edge of PGC and are Least Significant bit (LSb)
first.
2.7.14-BIT COMMANDS
All instructions are 20 bits, consisting of a leading 4-bit
command followed by a 16-bit operand, which depends
on the type of command being executed. To input a
command, PGC is cycled four times. The commands
needed for programming and verification are shown in
Ta bl e 2 -7 .
Depending on the 4-bit command, the 16-bit operand
represents 16 bits of input data or 8 bits of input data
and 8 bits of output data.
Throughout this specification, commands and data are
presented as illustrated in Table 2-8. The 4-bit
command is shown Most Significant bit (MSb) first. The
command operand, or “Data Payload”, is shown
<MSB><LSB>. Figure 2-14 demonstrates how to
serially present a 20-bit command/operand to the
device.
2.7.2CORE INSTRUCTION
The core instruction passes a 16-bit instruction to the
CPU core for execution. This is needed to set up
registers as appropriate for use with other commands.
TABLE 2-7:COMMANDS FOR
PROGRAMMING
Description
Core Instruction
(Shift in16-bit instruction)
Shift out TABLAT register0010
Table Read1000
Table Read, post-increment1001
Table Read, post-decrement1010
Table Read, pre-increment1011
Table Write1100
Table Write, post-increment by 21101
Table Write, start programming,
post-increment by 2
The PIC18F4221/4321 and PIC18F4455/4550 44-pin
TQFP devices are designed to support an alternate
programming input, the dedicated ICSP/ICD port. The
primary purpose of this port is to provide an alternate
In-Circuit Debugging (ICD) option and free the pins
(RB6, RB7 and MCLR
debugging the application. In conjunction with ICD
capability, however, the dedicated ICSP/ICD port also
provides an alternate port for ICSP.
Setting the ICPORT configuration bit enables the
dedicated ICSP/ICD port. The dedicated ICSP/ICD
port functions the same as the default ICSP/ICD port;
however, alternate pins are used instead of the default
pins. Table 2-9 identifies the functionally equivalent
pins for ICSP purposes:
The dedicated ICSP/ICD port is an alternate port. Thus,
ICSP is still available through the default port even
though the ICPORT configuration bit is set. When the
) that would normally be used for
10 111315 161412
9
P5A
IH is seen on the MCLR/VPP/RE3 pin prior to applying
V
IH to the ICRST/ICVPP pin, then the state of the
V
ICRST/ICV
seen on ICRST/ICV
PP/RE3, then the state of the MCLR/VPP/RE3 pin is
V
PP pin is ignored. Likewise, when the VIH is
PP prior to applying VIH to MCLR/
234
1
nnnn
Fetch Next 4-Bit Command
ignored.
Note:The ICPORT configuration bit can only be
programmed through the default ICSP
port. Chip Erase functions through the
dedicated ICSP/ICD port do not affect this
bit.
When the ICPORT configuration bit is set
(dedicated ICSP/ICD port enabled), the
NC/ICPORTS pin must be tied to either
DD or VSS.
V
The ICPORT configuration bit must be
maintained clear for all 28-pin and 40-pin
devices; otherwise, unexpected operation
may occur.
Programming includes the ability to erase or write the
various memory regions within the device.
In all cases except high-voltage ICSP Bulk Erase, the
EECON1 register must be configured in order to
operate on a particular memory region.
When using the EECON1 register to act on code
memory, the EEPGD bit must be set (EECON1<7> = 1)
and the CFGS bit must be cleared (EECON1<6> = 0).
The WREN bit must be set (EECON1<2> = 1) to
enable writes of any sort (e.g., erases) and this must be
done prior to initiating a write sequence. The FREE bit
must be set (EECON1<4> = 1) in order to erase the
program space being pointed to by the Table Pointer.
The erase or write sequence is initiated by setting the
WR bit (EECON1<1> = 1). It is strongly recommended
that the WREN bit only be set immediately prior to a
program erase.
3.1ICSP Erase
3.1.1HIGH-VOLTAGE ICSP BULK ERASE
Erasing code or data EEPROM is accomplished by
configuring two Bulk Erase Control registers located at
3C0004h and 3C0005h. Code memory may be erased
portions at a time, or the user may erase the entire
device in one action. Bulk Erase operations will also
clear any code-protect settings associated with the
memory block erased. Erase options are detailed in
Table 3-1. If data EEPROM is code-protected
(CPD = 0), the user must request an erase of data
EEPROM (e.g., 0084h as shown in Table 3-1).
The code sequence to erase the entire device is shown
in Table 3-2 and the flowchart is shown in Figure 3-1.
Note:A Bulk Erase is the only way to reprogram
code-protect bits from an ON state to an
OFF state.
0E 3C
6E F8
0E 00
6E F7
0E 05
6E F6
0F 0F
0E 3C
6E F8
0E 00
6E F7
0E 04
6E F6
87 87
00 00
00 00
Core Instruction
MOVLW 3Ch
MOVWF TBLPTRU
MOVLW 00h
MOVWF TBLPTRH
MOVLW 05h
MOVWF TBLPTRL
Write 0Fh to 3C0005h
MOVLW 3Ch
MOVWF TBLPTRU
MOVLW 00h
MOVWF TBLPTRH
MOVLW 04h
MOVWF TBLPTRL
Write 8787h TO 3C0004h
to erase entire
device.
NOP
Hold PGD low until
erase completes.
FIGURE 3-1:BULK ERASE FLOW
TABLE 3-1:BULK ERASE OPTIONS
Description
Chip Erase0F87h
Erase Data EEPROM
Erase Boot Block0081h
Erase Config Bits0082h
Erase Code EEPROM Block 00180h
Erase Code EEPROM Block 10280h
Erase Code EEPROM Block 20480h
Erase Code EEPROM Block 30880h
Note 1: Selected devices only, see Section 3.3
“Data EEPROM Programming”.
The actual Bulk Erase function is a self-timed
operation. Once the erase has started (falling edge of
the 4th PGC after the NOP command), serial execution
will cease until the erase completes (parameter P11).
During this time, PGC may continue to toggle but PGD
must be held low.