2.7 Writing Code Memory

Figure 2-7 shows a high-level overview for writing to the code memory.

Figure 2-8 provides the ICSP programming details for writing the code memory.

Code memory is written two instruction words at a time. Two words are loaded into the write latches, located at 0xFA0000 and 0xFA0002, using the packed data format shown in Figure 2-7. The destination address is loaded into the NVMADR and NVMADRU registers. Next, the write cycle is initiated by setting the WREN bit in the NVMCON register. The WR bit in NVMCON will be cleared in hardware once the double-word write is complete. This process is repeated for all memory locations to be programmed.

Figure 2-7. Packed Instruction Word Format
Figure 2-8. Program Code Memory Flow
Table 2-6. Serial Instruction Execution for Programming Code Memory: Two-Word Latch Writes

Command

(Binary)

Data

(Hex)

Description

Step 1: Exit the Reset vector.

0000

0000

0000

0000

0000

0000

0000

000000

000000

000000

040200

000000

000000

000000

NOP

NOP

NOP

GOTO 0x200

NOP

NOP

NOP

Step 2: Initialize the TBLPAG register for writing to the latches.

0000

0000

200FAC

8802AC

MOV #0xFA, W12

MOV W12, TBLPAG

Step 3: Load W0:W2 with the next two packed instruction words to program.

0000

0000

0000

2xxxx0

2xxxx1

2xxxx2

MOV #<LSW0>, W0

MOV #<MSB1:MSB0>, W1

MOV #<LSW1>, W2

Step 4: Set the Read Pointer (W6) and Write Pointer (W7), and load the (next set of) write latches.

0000

0000

0000

0000

0000

0000

0000

0000

0000

0000

0000

0000

0000

0000

0000

0000

EB0300

000000

EB0380

000000

BB0BB6

000000

000000

BBDBB6

000000

000000

BBEBB6

000000

000000

BB0B96

000000

000000

CLR W6

NOP

CLR W7

NOP

TBLWTL [W6++], [W7]

NOP

NOP

TBLWTH.B [W6++], [W7++]

NOP

NOP

TBLWTH.B [W6++], [++W7]

NOP

NOP

TBLWTL.W [W6], [W7]

NOP

NOP

Step 5: Set the NVMADRU/NVMADR register pair to point to the correct address.

0000

0000

0000

0000

2xxxx3

2xxxx4

884693

8846A4

MOV #DestinationAddress<15:0>, W3

MOV #DestinationAddress<23:16>, W4

MOV W3, NVMADR

MOV W4, NVMADRU

Step 6: Set the NVMCON register to program two instruction words.

0000

0000

0000

0000

0000

24001A

000000

88468A

000000

000000

MOV #0x4001, W10

NOP

MOV W10, NVMCON

NOP

NOP

Step 7: Initiate the write cycle.

0000

0000

0000

0000

0000

0000

0000

0000

200551

8846B1

200AA1

8846B1

A8E8D1

000000

000000

000000

MOV #0x55, W1

MOV W1, NVMKEY

MOV #0xAA, W1

MOV W1, NVMKEY

BSET NVMCON, #WR

NOP

NOP

NOP

Step 8: Generate clock pulses for the program operation to complete until the WR bit is cleared.

0000

0000

0000

0000

0000

0001

0000

0000

0000

0000

0000

0000

0000

000000

804680

00000

887E60

000000

<VISI>

000000

000000

000000

040200

000000

000000

000000

NOP

MOV NVMCON, W0

NOP

MOV W0, VISI

NOP

Clock out contents of the VISI register.

NOP

NOP

NOP

GOTO 0x200

NOP

NOP

NOP

Repeat until the WR bit is cleared.

Step 9: Repeat Steps 3-8 until all code memory has been programmed.