This is an example demonstration how to read On-chip
2K EEPROM of ATMEL AT89S8252 with KEIL C51.
As we know that there are On-chip 2K
EEPROM in AT89S8252 which is helpfully for applications that need to store some data even power supplies disconnected.

The on-chip EEPROM data memory is selected by setting
the bit in the register at SFR address
location 96H. The EEPROM address range is from 000H to
7FFH. The instructions are used to access the
EEPROM. To access off-chip data memory with the MOVX
instructions, the EEMEN bit needs to be set to “0”.
The bit in the WMCON register needs to be set to
“1” before any byte location in the EEPROM can be written.
User software should reset EEMWE bit to “0” if no further
EEPROM write is required. EEPROM write cycles in the
serial programming mode are self-timed and typically take
2.5 ms. The progress of EEPROM write can be monitored
by reading the RDY/BSY bit (read-only) in SFR WMCON.
RDY/BSY = 0 means programming is still in progress and
RDY/BSY = 1 means EEPROM write cycle is completed
and another write cycle can be initiated.
In addition, during EEPROM programming, an attempted
read from the EEPROM will fetch the byte being written
with the MSB complemented. Once the write cycle is completed,
true data are valid at all bit locations.
To access the 2K on-chip EEPROM in KEIL C51 we must include the reg8252.h file into our file.
Read/Write 2K On-chip EEPROM function(KEIL C51 V7.5)
void (unsigned char xdata * ADDR,unsigned char EEP_Data);
unsigned char (unsigned char xdata * ADDR);
void (unsigned char xdata * ADDR,unsigned char EEP_Data)
{
EA=0;
WMCON|=EEMEN_ | EEMWE_;
*ADDR=EEP_Data;
WMCON &= ~EEMEN_;
WMCON &= ~EEMWE_;
while((WMCON&WDTRST_)==0)
EA=1;
}
unsigned char (unsigned char xdata *ADDR)
{
unsigned char EEP_DATA;
EA=0;
WMCON|=EEMEN_;
EEP_DATA = *ADDR;
WMCON &= ~EEMEN_;
EA=1;
return EEP_DATA;
}
|