PIC16F/LF1946/47
EXAMPLE 11-4:
ERASING ONE ROW OF PROGRAM MEMORY
; This row erase routine assumes the following:
; 1. A valid address within the erase block is loaded in ADDRH:ADDRL
; 2. ADDRH and ADDRL are located in shared data memory 0x70 - 0x7F
BCF
INTCON,GIE
EEADRL
ADDRL,W
EEADRL
ADDRH,W
; Disable ints so required sequences will execute properly
; Load lower 8 bits of erase address boundary
; Load upper 6 bits of erase address boundary
BANKSEL
MOVF
MOVWF
MOVF
MOVWF
BSF
BCF
BSF
BSF
EEADRH
EECON1,EEPGD
EECON1,CFGS
EECON1,FREE
EECON1,WREN
; Point to program memory
; Not configuration space
; Specify an erase operation
; Enable writes
MOVLW
MOVWF
MOVLW
MOVWF
BSF
55h
EECON2
0AAh
EECON2
EECON1,WR
; Start of required sequence to initiate erase
; Write 55h
;
; Write AAh
; Set WR bit to begin erase
; Any instructions here are ignored as processor
; halts to begin erase sequence
; Processor will stop here and wait for erase complete.
NOP
NOP
; after erase processor continues with 3rd instruction
BCF
BSF
EECON1,WREN
INTCON,GIE
; Disable writes
; Enable interrupts
DS41414A-page 114
Preliminary
2010 Microchip Technology Inc.