2010-2015 Microchip Technology Inc. DS30009622M-page 25
PIC18F2XXX/4XXX FAMILY
TABLE 3-5: WRITE CODE MEMORY CODE SEQUENCE
4-Bit
Command
Data Payload Core Instruction
Step 1: Direct access to code memory and enable writes.
0000
0000
8E A6
9C A6
BSF EECON1, EEPGD
BCF EECON1, CFGS
Step 2: Load write buffer.
0000
0000
0000
0000
0000
0000
0E <Addr[21:16]>
6E F8
0E <Addr[15:8]>
6E F7
0E <Addr[7:0]>
6E F6
MOVLW <Addr[21:16]>
MOVWF TBLPTRU
MOVLW <Addr[15:8]>
MOVWF TBLPTRH
MOVLW <Addr[7:0]>
MOVWF TBLPTRL
Step 3: Repeat for all but the last two bytes.
1101 <MSB><LSB> Write 2 bytes and post-increment address by 2.
Step 4: Load write buffer for last two bytes.
1111
0000
<MSB><LSB>
00 00
Write 2 bytes and start programming.
NOP - hold PGC high for time P9 and low for time P10.
To continue writing data, repeat Steps 2 through 4, where the Address Pointer is incremented by 2 at each iteration of the loop.
PIC18F2XXX/4XXX FAMILY
DS30009622M-page 26 2010-2015 Microchip Technology Inc.
FIGURE 3-4: PROGRAM CODE MEMORY FLOW
FIGURE 3-5: TABLE WRITE AND START PROGRAMMING INSTRUCTION TIMING (
1111)
Start Write Sequence
All
locations
done?
No
Done
Start
Yes
Hold PGC Low
for Time P10
Load 2 Bytes
to Write
Buffer at <Addr>
All
bytes
written?
No
Yes
and Hold PGC
High until Done
N = 1
LoopCount = 0
Configure
Device for
Writes
N = 1
LoopCount =
LoopCount + 1
N = N + 1
and Wait P9
1234
12 1516
123 4
PGC
P5A
PGD
PGD = Input
n
11
1
1
34 65
P9
P10
Programming Time
nnn
nn n n
00
12
000
16-Bit
Data Payload
0
3
0
P5
4-Bit Command 16-Bit Data Payload
4-Bit Command
2010-2015 Microchip Technology Inc. DS30009622M-page 27
PIC18F2XXX/4XXX FAMILY
3.2.1 MODIFYING CODE MEMORY
The previous programming example assumed that the device had been Bulk Erased prior to programming (see
Section 3.1.1 “High-Voltage ICSP Bulk Erase”). It may be the case, however, that the user wishes to modify only a
section of an already programmed device.
The appropriate number of bytes required for the erase buffer must be read out of code memory (as described in
Section 4.2 “Verify Code Memory and ID Locations”) and buffered. Modifications can be made on this buffer. Then,
the block of code memory that was read out must be erased and rewritten with the modified data.
The WREN bit must be set if the WR bit in EECON1 is used to initiate a write sequence.
TABLE 3-6: MODIFYING CODE MEMORY
4-Bit
Command
Data Payload Core Instruction
Step 1: Direct access to code memory.
Step 2: Read and modify code memory (see Section 4.1 “Read Code Memory, ID Locations and Configuration Bits).
0000
0000
8E A6
9C A6
BSF EECON1, EEPGD
BCF EECON1, CFGS
Step 3: Set the Table Pointer for the block to be erased.
0000
0000
0000
0000
0000
0000
0E <Addr[21:16]>
6E F8
0E <Addr[8:15]>
6E F7
0E <Addr[7:0]>
6E F6
MOVLW <Addr[21:16]>
MOVWF TBLPTRU
MOVLW <Addr[8:15]>
MOVWF TBLPTRH
MOVLW <Addr[7:0]>
MOVWF TBLPTRL
Step 4: Enable memory writes and set up an erase.
0000
0000
84 A6
88 A6
BSF EECON1, WREN
BSF EECON1, FREE
Step 5: Initiate erase.
0000
0000
82 A6
00 00
BSF EECON1, WR
NOP - hold PGC high for time P9 and low for time P10.
Step 6: Load write buffer. The correct bytes will be selected based on the Table Pointer.
0000
0000
0000
0000
0000
0000
1101
.
.
.
1111
0000
0E <Addr[21:16]>
6E F8
0E <Addr[8:15]>
6E F7
0E <Addr[7:0]>
6E F6
<MSB><LSB>
.
.
.
<MSB><LSB>
00 00
MOVLW <Addr[21:16]>
MOVWF TBLPTRU
MOVLW <Addr[8:15]>
MOVWF TBLPTRH
MOVLW <Addr[7:0]>
MOVWF TBLPTRL
Write 2 bytes and post-increment address by 2.
Repeat as many times as necessary to fill the write buffer
Write 2 bytes and start programming.
NOP - hold PGC high for time P9 and low for time P10.
To continue modifying data, repeat Steps 2 through 6, where the Address Pointer is incremented by the appropriate number of bytes
(see Table 3-4) at each iteration of the loop. The write cycle must be repeated enough times to completely rewrite the contents of
the erase buffer.
Step 7: Disable writes.
0000 94 A6 BCF EECON1, WREN

PIC18F2510T-I/SO

Mfr. #:
Manufacturer:
Microchip Technology
Description:
8-bit Microcontrollers - MCU 32KB 1536 RAM 25I/O
Lifecycle:
New from this manufacturer.
Delivery:
DHL FedEx Ups TNT EMS
Payment:
T/T Paypal Visa MoneyGram Western Union