
PIC18F2XJXX/4XJXX FAMILY
DS39687E-page 12
2009 Microchip Technology Inc.
3.2
Code Memory Programming
Programming code memory is accomplished by first
loading data into the write buffer and then initiating a
programming sequence. The write buffer for all devices
in the PIC18F2XJXX/4XJXX family is 64 bytes. It can
be mapped to any 64-byte block beginning at 000000h.
The actual memory write sequence takes the contents
of this buffer and programs the 64-byte block of code
memory indicated by the Table Pointer.
Write buffer locations are not cleared following a write
operation; the buffer retains its data after the write is
complete. This means that the buffer must be written
with 64 bytes on each operation. If there are locations
in the code memory that are to remain empty, the
corresponding locations in the buffer must be filled with
FFFFh. This avoids rewriting old data from the previous
cycle.
The programming duration is internally timed. After a
Start Programming command is issued (4-bit com-
mand, ‘1111’), a NOP is issued, where the 4th PGC is
held high for the duration of the programming time, P9.
The
code
sequence
to
program
a
PIC18F2XJXX/4XJXX family device is shown in
the
logic
necessary
to
completely
write
a
PIC18F2XJXX/4XJXX family device. The timing
diagram that details the Start Programming command
TABLE 3-3:
WRITE CODE MEMORY CODE SEQUENCE
Note 1: The TBLPTR register must point to the
same region when initiating the program-
ming sequence as it did when the write
buffers were loaded.
4-Bit
Command
Data Payload
Core Instruction
Step 1: Enable writes.
0000
84 A6
BSF
EECON1, WREN
Step 2: Load write buffer.
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. Any unused locations should be filled with FFFFh.
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.
To continue writing data, repeat steps 2 through 4, where the Address Pointer is incremented by 2 at each iteration of the loop.