PIC18FXX2/XX8: Flash Microcontroller Programming Specification
PIC18FXX2/XX8: Flash Microcontroller Programming Specification
RC2 17 24 RC5
RC3 18 23 RC4
RA3
RA2
RA1
RA0
RB7
RB6
RB5
RB4
RD0 RD3
NC
NC
19 22
RD1 20 21 RD2
6
5
4
3
2
1
44
43
42
41
40
RA4 7 39 RB3
RA5 8 38 RB2
RE0 9 PIC18F4X2 37 RB1
RE1 10 36 RB0
RE2 11 PIC18F4X8 35 VDD
RC6
RC5
RC4
RD3
RD2
RD1
RD0
RC3
RC2
RC1
12 34
NC
VDD VSS
VSS 13 33 RD7
OSC1 14 44L PLCC 32 RD6
OSC2 15 31 RD5
RC0 16 30 RD4
NC 171 29 RC7
19
20
21
22
23
24
25
26
27
28
8
44
43
42
41
40
39
38
37
36
35
34
RC7 1 33 NC
RD4 2 32 RC0
RD5 3 PIC18F4X2 31 OSC2
RC1
RC2
RC3
RD0
RD1
RD2
RD3
RC4
RC5
RC6
NC
RD6 4 30 OSC1
RD7 5 PIC18F4X8 29 VSS
VSS 6 28 VDD
VDD 7 27 RE2
44L QFP RE1
RB0 8 26
RB1 9 25 RE0
RB2 10 24 RA5
RB3 11 23 RA4
RC6
RC5
RC4
RD3
RD2
RD1
RD0
RC3
RC2
RC1
RC0
12
13
14
15
16
17
18
19
20
21
22
44
43
42
41
40
39
38
37
36
35
34
33 OSC2
NC
NC
RB4
RB5
RB6
RB7
MCLR/VPP
RA0
RA1
RA2
RA3
RC7 1
RD4 2 32 OSC1
RD5 3 31 VSS
RD6 4 PIC18F4X2 30 AVSS
RD7 5 29 VDD
PIC18F4X8 28 VDD
VSS 6
VDD 7 27 RE2
AVDD 8 44L QFN 26 RE1
RB0 9 25 RE0
RB1 10 24 RA5
RB2 11 23 RA4
12
13
14
15
16
17
18
19
20
21
22
RB3
NC
RB4
RB5
RB6
RB7
MCLR/VPP
RA0
RA1
RA2
RA3
Note: Not all multiplexed pin definitions are shown. Refer to the appropriate data sheet for complete pin descriptions.
000000h
Boot Block Boot Block CPB, WRTB, EBTRB
0001FFh
000200h
Block 0 Block 0 CP0, WRT0, EBTR0
001FFFh
002000h
Block 1 Block 1 CP1, WRT1, EBTR1
003FFFh
004000h
Unimplemented
Block 2 CP2, WRT2, EBTR2
Read ‘0’s
005FFFh
006000h
Unimplemented
Block 3 CP3, WRT3, EBTR3
Read ‘0’s
007FFFh
008000h
Unimplemented Unimplemented
Read ‘0’s Read ‘0’s (Unimplemented Memory Space)
1FFFFFh
CONFIG1L 300000h
CONFIG1H 300001h
CONFIG2L 300002h
CONFIG2H 300003h
1FFFFFh CONFIG3L 300004h
CONFIG3H 300005h
Configuration CONFIG4L 300006h
and ID CONFIG4H 300007h
Space CONFIG5L 300008h
CONFIG5H 300009h
CONFIG6L 30000Ah
2FFFFFh CONFIG6H 30000Bh
CONFIG7L 30000Ch
CONFIG7H 30000Dh
3FFFFFh
VDD
VDD
SDATA VIH
PGM
SCLK
SDATA
SDATA = Input
SCLK
SDATA = Input
All instructions are 20 bits, consisting of a leading 4-bit Table Read, post-increment 1001
command followed by a 16-bit operand, which depends Table Read, post-decrement 1010
on the type of command being executed. To input a Table Read, pre-increment 1011
command, SCLK is cycled four times. The commands
needed for programming and verification are shown in Table Write 1100
Table 2-3. Table Write, post-increment by 2 1101
Depending on the 4-bit command, the 16-bit operand Table Write, post-decrement by 2 1110
represents 16 bits of input data or 8 bits of input data Table Write, start programming 1111
and 8 bits of output data.
Throughout this specification, commands and data are
TABLE 2-4: SAMPLE COMMAND
presented as illustrated in Figure 2-4. The 4-bit com-
mand is shown MSb first. The command operand, or SEQUENCE
“Data Payload”, is shown <MSB><LSB>. Figure 2-7 4-Bit Data
Core Instruction
demonstrates how to serially present a 20-bit Command Payload
command/operand to the device.
1101 3C 40 Table Write,
post-increment by 2
2.6.2 CORE INSTRUCTION
The core instruction passes a 16-bit instruction to the
CPU core for execution. This is needed to setup
registers as appropriate for use with other commands.
P4
P3
SDATA 1 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 1 0 0 n n n n
0 4 C 3
4-bit Command 16-bit Data Payload Fetch Next 4-bit Command
SDATA = Input
SDATA 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 n n
4-bit Command 16-bit 4-bit Command NOP 4-bit Command Erase Time 16-bit
Data Payload Data Payload
SDATA = Input
Start
Addr = 0
Configure
Device for
Multi-Panel Erase
Addr = Addr + 64
Delay P9 + P10
Time for Erase
to Occur
All
No panels
done?
Yes
Done
Typically, all of the program buffers are written in paral- The code sequence to program a PIC18FXX2/XX8
lel (Multi-Panel Write mode). In other words, in the case device is shown in Figure 3-4. The flowchart shown in
of a 32-Kbyte device (4 panels with an 8-byte buffer per Figure 3-5 depicts the logic necessary to completely
panel), 32 bytes will be simultaneously programmed write a PIC18FXX2/XX8 device.
during each programming sequence. In this case, the Note: The TBLPTR register must contain the
offset of the write within each panel is the same (see same offset value when initiating the pro-
Figure 3-4). Multi-Panel Write mode is enabled by gramming sequence as it did when the
appropriately configuring the programming control write buffers were loaded.
register located at 3C0006h.
Panel n
TBLPTR<21:13> = (n – 1)
Panel 3
TBLPTR<21:13> = 2
Panel 2
TBLPTR<21:13> = 1
Panel 1
TBLPTR<21:13> = 0
To continue writing data, repeat steps 2 through 5, where the Address Pointer is incremented by 8 in each panel at each iteration of
the loop.
Start
N=1
LoopCount = 0
Configure
Device for
Multi-Panel Writes
Load 8 Bytes
N=N+1 to Panel N Write
Buffer at <Addr>
All
No panel buffers
written?
N=1 Yes
LoopCount =
LoopCount + 1 Start Write Sequence
and Hold SCLK
High Until Done
No All
locations
done?
Yes
Done
FIGURE 3-6: TABLE WRITE AND START PROGRAMMING INSTRUCTION TIMING (1111)
P10
1 2 3 4 1 2 3 4 5 6 15 16 1 2 3 4 1 2 3
SCLK P9
P5 P5A
SDATA 1 1 1 1 n n n n n n n n 0 0 0 0 0 0 0
4-bit Command 16-bit Data Payload 4-bit Command Programming Time 16-bit
Data Payload
SDATA = Input
Step 9: Load write buffer for panel. The correct panel will be selected based on the Table Pointer.
To continue writing data, repeat step 8, where the Address Pointer is incremented by 8 at each iteration of the loop.
SCLK
P5 P5A
0 0 0 0 n n
SDATA
4-bit Command BSF EECON1, WR Poll WR bit, Repeat Until Clear 16-bit Data
(see below) Payload
SDATA = Input
1 2 3 4 1 2 15 16 1 2 3 4 1 2 15 16
SCLK
P5 P5A P5 P5A
Poll WR bit
0 0 0 0 0 0 0 0
SDATA
4-bit Command MOVF EECON1, W, 0 4-bit Command MOVWF TABLAT Shift Out Data
(see Figure 4-6)
Note 1: See Figure 4-4 for details on Shift Out Data timing.
Step 3(2): Set Table Pointer for config byte to be written. Write even/odd addresses.
Note 1: If the code protection bits are programmed while the program counter resides in the same block, then the interaction of
code protection logic may prevent further table writes. To avoid this situation, move the program counter outside the
code protection area (e.g., GOTO 100000h).
2: Enabling the write protection of configuration bits (WRTC = 0 in CONFIG6H) will prevent further writing of configuration
bits. Always write all the configuration bits before enabling the write protection for configuration bits.
Start Start
Program Program
LSB MSB
Done Done
Step 2: Read memory into Table Latch and then shift out on SDATA, LSb to MSb.
1001 00 00 TBLRD *+
1 2 3 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4
SCLK
P5 P6 P5A
P14
Start
Does Does
No No
word = expect Failure, word = expect Failure,
data? Report data? Report
Error Error
Yes Yes
All All
No No ID locations
code memory
verified? verified?
Yes Yes
Done
1 2 3 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4
SCLK
P5 P6 P5A
P14
4.5 Verify Data EEPROM If it is determined that the device is not blank, then the
device should be Bulk Erased (see Section 3.1) before
A data EEPROM address may be read via a sequence any attempt to program is made.
of core instructions (4-bit command, ‘0000’) and then
output on SDATA via the 4-bit command, ‘0010’ (shift Given that “Blank Checking” is merely code and data
out data holding register). The result may then be EEPROM verification with FFh expect data, refer to
immediately compared to the appropriate data in the Section 4.4 and Section 4.2 for implementation details.
programmer’s memory for verification. Refer to
Section 4.4 for implementation details of reading data FIGURE 4-5: BLANK CHECK FLOW
EEPROM.
Start
4.6 Blank Check
The term “Blank Check” means to verify that the device Blank Check Device
has no programmed memory cells. All memories must
be verified: code memory, data EEPROM, ID locations,
and configuration bits. The Device ID registers
(3FFFFEh:3FFFFFh) should be ignored. Is
device Yes
Continue
A “blank” or “erased” memory cell will read as a ‘1’. So, blank?
“Blank Checking” a device merely means to verify that
all bytes read as FFh, except the configuration bits. No
Unused (reserved) configuration bits will read ‘0’ (pro-
Abort
grammed). Refer to Table 5-2 for blank configuration
expect data for the various PIC18FXX2/XX8 devices.
Param
Sym Characteristic Min Max Units Conditions
No.
D110 VIHH High Voltage Programming Voltage on 9.00 13.25 V
MCLR/VPP
D110A VIHL Low Voltage Programming Voltage on 2.00 5.50 V
MCLR/VPP
D111 VDD Supply Voltage during programming 2.00 5.50 V Normal
programming
4.50 5.50 V Bulk erase
operations
D112 IPP Programming Current on MCLR/VPP — 300 A
D113 IDDP Supply Current during programming — 5 mA
D031 VIL Input Low Voltage VSS 0.2 VSS V
D041 VIH Input High Voltage 0.8 VDD VDD V
D080 VOL Output Low Voltage — 0.6 V IOL = 8.5 mA
D090 VOH Output High Voltage VDD – 0.7 — V IOH = -3.0 mA
D012 CIO Capacitive loading on I/O pin (SDATA) — 50 pF To meet AC
specifications
P2 Tsclk Serial Clock (SCLK) period 100 — ns VDD = 5.0V
1 — s VDD = 2.0V
P2A TsclkL Serial Clock (SCLK) Low time 40 — ns VDD = 5.0V
400 — ns VDD = 2.0V
P2B TsclkH Serial Clock (SCLK) High time 40 — ns VDD = 5.0V
400 — ns VDD = 2.0V
P3 Tset1 Input Data Setup Time to serial clock 15 — ns
P4 Thld1 Input Data Hold Time from SCLK 15 — ns
P5 Tdly1 Delay between 4-bit command and 20 — ns
command operand
P5A Tdly1a Delay between 4-bit command 20 — ns
operand and next 4-bit command
P6 Tdly2 Delay between last SCLK of 20 — ns
command byte to first SCLK of read
of data word
P9 Tdly5 SCLK High time 1 — ms
(minimum programming time)
P10 Tdly6 SCLK Low time after programming 5 — s
(high voltage discharge time)
P11 Tdly7 Delay to allow self-timed data write or 10 — ms
bulk erase to occur
P12 Thld2 Input Data Hold time from 2 — s
MCLR/VPP
P13 Tset2 VDD Setup time to MCLR/VPP 100 — ns
P14 Tvalid Data Out Valid from SCLK 10 — ns
P15 Tset3 PGM Setup time to MCLR/VPP 2 — s
• 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.
01/05/10