English
Language : 

PIC16F193X Datasheet, PDF (332/418 Pages) Microchip Technology – 28/40/44-Pin Flash-Based, 8-Bit CMOS Microcontrollers with LCD Driver and nanoWatt Technology
PIC16F193X/LF193X
EXAMPLE 23-5: WRITING TO FLASH PROGRAM MEMORY
; This write routine assumes the following:
; 1. A valid starting address (the least significant bits = 00)is loaded in ADDRH:ADDRL
; 2. The 8 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 EEADRH
; Bank 3
MOVF ADDRH,W
; Load initial address
MOVWF EEADRH
;
MOVF ADDRL,W
;
MOVWF EEADRL
;
MOVF DATAADDRL,W
; Load initial data address
MOVWF FSR0L
;
MOVF DATAADDRH,W
; Load initial data address
MOVWF FSR0H
;
LOOP
MOVIW
MOVWF
MOVIW
MOVWF
BSF
BCF
BSF
BSF
INDF0++
EEDATL
INDF0++
EEDATH
EECON1,EEPGD
EECON1,CFGS
EECON1,WREN
EECON1,LWLO
; Load first data byte into lower
;
; Load second data byte into upper
;
; Point to program memory
; Not configuration space
; Enable writes
; Only Load Write Latches
MOVLW
MOVWF
MOVLW
MOVWF
BSF
55h
EECON2
AAh
EECON2
EECON1,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 EEADR,W
XORLW 0x08
ANDLW 0x08
BTFSC STATUS,Z
GOTO START_WRITE
INCF
GOTO
EEADR,F
LOOP
START_WRITE
BCF
EECON1,LWLO
MOVLW
MOVWF
MOVLW
MOVWF
BSF
55h
EECON2
AAh
EECON2
EECON1,WR
NOP
NOP
BCF
EECON1,WREN
; Check if lower two bits of address are ‘00’
; Check if we’re on the last of 8 addresses
;
; Exit if last of eight 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
DS41364A-page 330
Preliminary
© 2008 Microchip Technology Inc.