English
Language : 

PIC18CXX2_13 Datasheet, PDF (58/304 Pages) Microchip Technology – High Performance Microcontrollers with 10-bit A/D
PIC18CXX2
FIGURE 5-3:
HOLDING REGISTER AND THE WRITE BLOCK
Program Memory (x 2-bits)
Block n
Write Block
MSB
Block n + 1
Holding Register
Block n + 2
The write to the MSB of the Write Block
causes the entire block to be written to pro-
gram memory. The program memory block
that is written depends on the address that is
written to in the MSB of the Write Block.
5.2.2.1 Operation
The long write is what actually programs words of data
into the internal memory. When a TBLWT to the MSB of
the write block occurs, instruction execution is halted.
During this time, programming voltage and the data
stored in internal latches is applied to program memory.
For a long write to occur:
1. MCLR/VPP pin must be at the programming
voltage
2. LWRT bit must be set
3. TBLWT to the address of the MSB of the write
block
If the LWRT bit is clear, a short write will occur and pro-
gram memory will not be changed. If the TBLWT is not
to the MSB of the write block, then the programming
phase is not initiated.
Setting the LWRT bit enables long writes when the
MCLR pin is taken to VPP voltage. Once the LWRT bit
is set, it can be cleared only by performing a POR or
MCLR Reset.
To ensure that the memory location has been well pro-
grammed, a minimum programming time is required.
The long write can be terminated after the program-
ming time has expired by a RESET or an interrupt.
Having only one interrupt source enabled to terminate
the long write ensures that no unintended interrupts will
prematurely terminate the long write.
5.2.2.2 Sequence of Events
The sequence of events for programming an internal
program memory location should be:
1. Enable the interrupt that terminates the long
write. Disable all other interrupts.
2. Clear the source interrupt flag.
3. If Interrupt Service Routine execution is desired
when the device wakes, enable global
interrupts.
4. Set LWRT bit in the RCON register.
5. Raise MCLR/VPP pin to the programming
voltage, VPP.
6. Clear the WDT (if enabled).
7. Set the interrupt source to interrupt at the
required time.
8. Execute the Table Write for the lower (even)
byte. This will be a short write.
9. Execute the Table Write for the upper (odd) byte.
This will be a long write. The microcontroller will
then halt internal operations. (This is not the
same as SLEEP mode, as the clocks and
peripherals will continue to run.) The interrupt
will cause the microcontroller to resume
operation.
10. If GIE was set, service the interrupt request.
11. Lower MCLR/VPP pin to VDD.
12. Verify the memory location (Table Read).
DS39026D-page 58
 1999-2013 Microchip Technology Inc.