Specifications
PIC16F627A/628A/648A
DS40044B-page 92 Preliminary 2004 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
variables 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, calibration, 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
constants and/or data that changes rarely,
an array refresh is likely not required. See
specification D124.
BANKSEL 0X80 ;select Bank1
CLRF EEADR ;start at address 0
BCF INTCON, GIE ;disable interrupts
BSF EECON1, WREN ;enable EE writes
Loop
BSF EECON1, RD ;retrieve data into EEDATA
MOVLW 0x55 ;first step of ...
MOVWF EECON2 ;... required sequence
MOVLW 0xAA ;second step of ...
MOVWF EECON2 ;... required sequence
BSF EECON1, WR ;start write sequence
BTFSC EECON1, WR ;wait for write complete
GOTO $ - 1
#IFDEF __16F648A ;256 bytes in 16F648A
INCFSZ EEADR, f ;test for end of memory
#ELSE ;128 bytes in 16F627A/628A
INCF EEADR, f ;next address
BTFSS EEADR, 7 ;test for end of memory
#ENDIF ;end of conditional assembly
GOTO Loop ;repeat for all locations
BCF EECON1, WREN ;disable EE writes
BSF INTCON, GIE ;enable interrupts (optional)
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
— — — — WRERR WREN WR RD ---- x000 ---- q000
9Dh EECON2
(1)
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.
Note 1: EECON2 is not a physical register.










