English
Language : 

PIC16F882_09 Datasheet, PDF (121/328 Pages) Microchip Technology – 28/40/44-Pin, Enhanced Flash-Based 8-Bit CMOS Microcontrollers with nanoWatt Technology
PIC16F882/883/884/886/887
An example of the complete eight-word write sequence
is shown in Example 10-4. The initial address is loaded
into the EEADRH and EEADR register pair; the eight
words of data are loaded using indirect addressing.
EXAMPLE 10-4: WRITING TO FLASH PROGRAM MEMORY
LOOP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This write routine assumes the following:
;
A valid starting address (the least significant bits = '000')
;
is loaded in ADDRH:ADDRL
;
ADDRH, ADDRL and DATADDR are all located in data memory
;
BANKSEL EEADRH
MOVF
ADDRH,W
; Load initial address
MOVWF EEADRH
;
MOVF
ADDRL,W
;
MOVWF EEADR
;
MOVF
DATAADDR,W ; Load initial data address
MOVWF FSR
;
MOVF
INDF,W
; Load first data byte into lower
MOVWF EEDATA
;
INCF
FSR,F
; Next byte
MOVF
INDF,W
; Load second data byte into upper
MOVWF EEDATH
;
INCF
FSR,F
;
BANKSEL EECON1
BSF
EECON1,EEPGD ; Point to program memory
BSF
EECON1,WREN ; Enable writes
BCF
INTCON,GIE ; Disable interrupts (if using)
BTFSC INTCON,GIE ; See AN576
GOTO
$-2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
Required Sequence
MOVLW 55h
; Start of required write sequence:
MOVWF EECON2
; Write 55h
MOVLW 0AAh
;
MOVWF EECON2
; Write 0AAh
BSF
EECON1,WR ; Set WR bit to begin write
NOP
; Required to transfer data to the buffer
NOP
; registers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
BCF
EECON1,WREN ; Disable writes
BSF
INTCON,GIE ; Enable interrupts (comment out if not using interrupts)
BANKSEL EEADR
MOVF
EEADR, W
INCF
EEADR,F
; Increment address
ANDLW 0x0F
; Indicates when sixteen words have been programmed
SUBLW 0x0F
; 0x0F = 16 words
; 0x0B = 12 words (PIC16F884/883/882 only)
; 0x07 = 8 words
; 0x03 = 4 words(PIC16F884/883/882 only)
BTFSS
STATUS,Z
; Exit on a match,
GOTO
LOOP
; Continue if more data needs to be written
© 2009 Microchip Technology Inc.
DS41291F-page 119