English
Language : 

PIC16F87 Datasheet, PDF (35/214 Pages) Microchip Technology – 18/20/28-Pin Enhanced FLASH Microcontrollers with nanoWatt Technology
PIC16F87/88
An example of the complete four-word write sequence
is shown in Example 3-5. The initial address is loaded
into the EEADRH:EEADR register pair; the four words
of data are loaded using indirect addressing, assuming
that a row erase sequence has already been
performed.
EXAMPLE 3-5: WRITING TO FLASH PROGRAM MEMORY
; This write routine assumes the following:
; 1. The 32 words in the erase block have already been erased.
; 2. A valid starting address (the least significant bits = '00') is loaded into EEADRH:EEADR
; 3. This example is starting at 0x100, this is an application dependent setting.
; 4. The 8 bytes (4 words) of data are loaded, starting at an address in RAM called ARRAY.
; 5. This is an example only, location of data to program is application dependent.
; 6. word_block is located in data memory.
BANKSEL EECON1
BSF
EECON1,EEPGD
BSF
EECON1,WREN
;prepare for WRITE procedure
;point to program memory
;allow write cycles
BANKSEL word_block
MOVLW .4
MOVWF word_block
;prepare for 4 words to be written
LOOP
BANKSEL
MOVLW
MOVWF
MOVLW
MOVWF
BANKSEL
MOVLW
MOVWF
EEADRH
0x01
EEADRH
0x00
EEADR
ARRAY
ARRAY
FSR
BANKSEL
MOVF
MOVWF
INCF
MOVF
MOVWF
INCF
EEDATA
INDF,W
EEDATA
FSR,F
INDF,W
EEDATH
FSR,F
;Start writing at 0x100
;load HIGH address
;load LOW address
;initialize FSR to start of data
;indirectly load EEDATA
;increment data pointer
;indirectly load EEDATH
;increment data pointer
BANKSEL
MOVLW
MOVWF
MOVLW
MOVWF
BSF
NOP
NOP
EECON1
0x55
EECON2
0xAA
EECON2
EECON1,WR
;required sequence
;set WR bit to begin write
;instructions here are ignored as processor
BANKSEL
INCF
BANKSEL
DECFSZ
GOTO
EEADR
EEADR,f
word_block
word_block,f
loop
;load next word address
;have 4 words been written?
;NO, continue with writing
BANKSEL EECON1
BCF
EECON1,WREN
BSF
INTCON,GIE
;YES, 4 words complete, disable writes
;enable interrupts
 2003 Microchip Technology Inc.
Preliminary
DS30487B-page 33