
PIC16F627A/628A/648A
DS40044A-page 92
Preliminary
2002 Microchip Technology Inc.
13.7
Using the Data EEPROM
The data EEPROM is a high endurance, byte address-
able array that has been optimized for the storage of
frequently changing information (e.g., program vari-
ables or other data that are updated often). Frequently
changing values will typically be updated more often
than specification D124. If this is not the case, an array
refresh must be performed. For this reason, variables
that change infrequently (such as constants, IDs, cali-
bration, etc.) should be stored in FLASH program
memory.
A simple data EEPROM refresh routine is shown in
Example 13-4.
EXAMPLE 13-4:
DATA EEPROM REFRESH ROUTINE
13.8
DATA EEPROM OPERATION
DURING CODE PROTECT
When the device is code protected, the CPU is able to
read and write data to the Data EEPROM.
TABLE 13-1:
REGISTERS/BITS ASSOCIATED WITH DATA EEPROM
Note:
If data EEPROM is only used to store con-
stants and/or data that changes rarely, an
array refresh is likely not required. See
specification D124.
clrf
bcf
bcf
bcf
bsf
EEADR
EECON1,CFGS
EECON1,EEPGD
INTCON,GIE
EECON1,WREN
; Start at address 0
; Set for memory
; Set for Data EEPROM
; Disable interrupts
; Enable writes
; Loop to refresh array
; Read current address
;
; Write 55h
;
; Write AAh
; Set WR bit to begin write
; Wait for write to complete
Loop
bsf
movlw
movwf
movlw
movwf
bsf
btfsc
bra
incfsz
bra
EECON1,RD
55h
EECON2
AAh
EECON2
EECON1,WR
EECON1,WR
$-2
EEADR,F
Loop
; Increment address
; Not zero, do it again
bcf
bsf
EECON1,WREN
INTCON,GIE
; Disable writes
; Enable interrupts
Address
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
Power-on
Reset
Value on all
other
RESETS
9Ah
EEDATA
EEPROM data register
xxxx xxxx
uuuu uuuu
9Bh
EEADR
EEPROM address register
xxxx xxxx
uuuu uuuu
9Ch
EECON1
EECON2
(1)
—
—
—
—
WRERR
WREN
WR
RD
---- x000
---- q000
9Dh
EEPROM control register 2
---- ----
---- ----
Legend:
x = unknown, u = unchanged, - = unimplemented read as '0', q = value depends upon condition.
Shaded cells are not used by data EEPROM.
EECON2 is not a physical register
Note
1: