AT89c51ED2 EEPROM程序:
#include \# include \
unsigned char w_dat[10]={1,2,3,4,5,6,7,8,9,0}; unsigned char r_dat[10];
unsigned char R_EEPROM_BYTE(unsigned int addr) {
bit ea_temp;
unsigned char dat;
while((EECON&0x01)!=0);//EEBUSY = 0? 等待 ea_temp = EA; EA=0;
EECON = 0x02; //EEE=1; 使能EEPROM dat = XBYTE[addr]; EECON= 0x00; EA=ea_temp; return dat; }
void R_EEPROM_nBYTE(unsigned int saddr,unsigned char num, unsigned char *s) {
unsigned char i; for(i=0;i s[i]=R_EEPROM_BYTE(saddr++); } } void W_EEPROM_BYTE(unsigned int addr ,unsigned char dat) { bit ea_temp; while((EECON&0x01)!=0); ea_temp=EA; EA = 0; EECON = 0x02; // EEE=1; XBYTE[addr]=dat; EECON = 0x00; EA = ea_temp; } void W_EEPROM_nBYTE (unsigned int saddr,unsigned char num, unsigned char *s ) { unsigned char i; for(i=0;i void main() { while(1) { W_EEPROM_nBYTE(0x0000,10 ,w_dat); R_EEPROM_nBYTE(0x0000,10, r_dat); } }