English
Language : 

PIC18F87K22 Datasheet, PDF (114/548 Pages) Microchip Technology – 64/80-Pin, High-Performance, 1-Mbit Enhanced Flash Microcontrollers with 12-Bit A/D and nanoWatt XLP Technology
PIC18F87K22 FAMILY
7.4 Erasing Flash Program Memory
The erase blocks are:
• PIC18FX5K22 and PIC18FX6K22 – 32 words or
64 bytes
• PIC18FX7K22 – 64 words or 128 bytes
Word erase in the Flash array is not supported.
When initiating an erase sequence from the micro-
controller itself, a block of 64 or 128 bytes of program
memory is erased. The Most Significant 16 bits of the
TBLPTR<21:6> point to the block being erased. The
TBLPTR<5:0> bits are ignored.
The EECON1 register commands the erase operation.
The EEPGD bit must be set to point to the Flash
program memory. The WREN bit must be set to enable
write operations. The FREE bit is set to select an erase
operation.
For protection, the write initiate sequence for EECON2
must be used.
A long write is necessary for erasing the internal Flash.
Instruction execution is halted while in a long write
cycle. The long write will be terminated by the internal
programming timer.
7.4.1
FLASH PROGRAM MEMORY
ERASE SEQUENCE
The sequence of events for erasing a block of internal
program memory location is:
1. Load the Table Pointer register with the address
of row to be erased.
2. Set the EECON1 register for the erase operation:
• Set the EEPGD bit to point to program memory
• Clear the CFGS bit to access program memory
• Set the WREN bit to enable writes
• Set the FREE bit to enable the erase
3. Disable the interrupts.
4. Write 0x55 to EECON2.
5. Write 0xAA to EECON2.
6. Set the WR bit.
This begins the row erase cycle.
The CPU will stall for the duration of the erase
for TIW. (See parameter D133A.)
7. Re-enable interrupts.
EXAMPLE 7-2: ERASING A FLASH PROGRAM MEMORY ROW
ERASE_ROW
Required
Sequence
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
BCF
BSF
BSF
BCF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
BSF
CODE_ADDR_UPPER
TBLPTRU
CODE_ADDR_HIGH
TBLPTRH
CODE_ADDR_LOW
TBLPTRL
EECON1, EEPGD
EECON1, CFGS
EECON1, WREN
EECON1, FREE
INTCON, GIE
0x55
EECON2
0xAA
EECON2
EECON1, WR
INTCON, GIE
; load TBLPTR with the base
; address of the memory block
; point to Flash program memory
; access Flash program memory
; enable write to memory
; enable Row Erase operation
; disable interrupts
; write 55h
; write 0AAh
; start erase (CPU stall)
; re-enable interrupts
DS39960B-page 114
Preliminary
 2010 Microchip Technology Inc.