English
Language : 

PIC16LF720_11 Datasheet, PDF (165/244 Pages) Microchip Technology – 20-Pin Flash Microcontrollers with nanoWatt XLP Technology
PIC16(L)F720/721
EXAMPLE 18-2: WRITING TO FLASH PROGRAM MEMORY
; This write routine assumes the following:
; 1. A valid starting address (the least significant bits = ‘00000’)is loaded in ADDRH:ADDRL
; 2. The 64 bytes of data are loaded, starting at the address in DATADDR
; 3. ADDRH, ADDRL and DATADDR are all located in shared data memory 0x70 - 0x7f
;
BANKSEL PMADRH
; Bank 3
MOVF ADDRH,W
; Load initial address
MOVWF PMADRH
;
MOVF ADDRL,W
;
MOVWF PMADRL
;
MOVF DATAADDRL,W
; Load initial data address
MOVWF FSR0L
;
MOVF DATAADDRH,W
; Load initial data address
MOVWF FSR0H
;
LOOP
MOVIW
MOVWF
MOVIW
MOVWF
BSF
BSF
INDF0++
PMDATL
INDF0++
PMDATH
PMCON1,WREN
PMCON1,LWLO
; Load first data byte into lower
;
; Load second data byte into upper
;
; Enable writes
; Only Load Write Latches
MOVLW
MOVWF
MOVLW
MOVWF
BSF
55h
PMCON2
AAh
PMCON2
PMCON1,WR
; Start of required write sequence:
; Write 55h
;
; Write AAh
; Set WR bit to begin write
NOP
; Any instructions here are ignored as processor
; halts to begin write sequence
NOP
; processor will stop here and wait for write complete
; after write processor continues with 3rd instruction
MOVF
XORLW
ANDLW
BTFSC
GOTO
PMADR,W
0x1F
0x1F
STATUS,Z
START_WRITE
INCF
GOTO
PMADR,F
LOOP
START_WRITE
BCF
PMCON1,LWLO
MOVLW
MOVWF
MOVLW
MOVWF
BSF
55h
PMCON2
AAh
PMCON2
PMCON1,WR
NOP
NOP
BCF
PMCON1,WREN
; Check if lower five bits of address are ‘11111’
; Check if we’re on the last of 8 addresses
;
; Exit if last of 32 words,
;
; Still loading latches Increment address
; Write next latches
; No more Latches only; Actually start write
; Start of required write sequence:
; Write 55h
;
; Write AAh
; Set WR bit to begin write
; Any instructions here are ignored as processor
; halts to begin write sequence
; processor will stop here and wait for write complete
; after write processor continues with 3rd instruction
; Disable writes
 2011 Microchip Technology Inc.
Preliminary
DS41430B-page 165