English
Language : 

PIC18FXXK80 Datasheet, PDF (25/52 Pages) Microchip Technology – Flash Microcontroller Programming Specification
PIC18FXXK80 FAMILY
3.2.2 MODIFYING CODE MEMORY
The previous programming example assumed that the
device had been erased entirely prior to programming
(see Section 3.1.1 “ICSP Block 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 Loca-
tions”) 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
(see Section 3.2.1 “Programming”).
The WREN bit must be set if the WR bit in EECON1 is
used to initiate a write sequence.
TABLE 3-12: 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 7F
9C 7F
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
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
<Addr[21:16]>
TBLPTRU
<Addr[8:15]>
TBLPTRH
<Addr[7:0]>
TBLPTRL
Step 4: Enable memory writes and set up an erase.
0000
0000
84 7F
88 7F
BSF EECON1, WREN
BSF EECON1, FREE
Step 5: Initiate erase.
0000
0000
82 7F
00 00
BSF EECON1, WR
NOP - hold PGC high for time P9 and low for time P10.
Step 6: Direct access to configuration memory.
0000
0000
0000
8E 7F
8C 7F
84 7F
BSF EECON1, EEPGD
BSF EECON1, CFGS
BSF EECON1, WREN
Step 7: Direct access to code memory and enable writes.
0000
0000
8E 7F
9C 7F
BSF EECON1, EEPGD
BCF EECON1, CFGS
Step 8: 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 31 times
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 8, where the Address Pointer is incremented by 64 bytes at each iteration of the
loop.
Step 9: Disable writes.
0000
94 7F
BCF EECON1, WREN
 2011 Microchip Technology Inc.
DS39972B-page 25