HI,
How to specify a address while writing to EEPROM in 89c51ED2.
It is writing to EEPROM when I give the following code after setting the flags of EECON register.
XBYTE[0x0050] = '1';
But if I declare a variable with following type and assign a value to it, it is not writing to EEPROM
unsigned char xdata *addr; *addr = '1';
//after setting all the flags i write this code for assigning;
*addr = '2';
But this is not writing to EEPROM.
Kindly provide the solution for this.
So then, expanding the macros and adding one set of braces to aid visualization, we have:
Write(unsigned char xdata* Addr, char element) { while(EECON = EECON & 0X01) { EA = 0; } EECON = EECON | 0X02; *Addr = element; EECON = EECON & 0X00; EA = 1; }
Is that what you intended?
Dear,
I have called the function in the following manner Write(0x0050,'x'); While defining I used following format.
void Write(unsigned char xdata* Addr,char element)
While writing I have given this code after setring the EECON register. (*Addr) = element;
But I am unable to write to EEPROM.
CODE:
#define BUSY EECON = EECON & 0X01 #define E_EECON EECON = EECON | 0X02 #define D_EECON EECON = EECON & 0X00 Write(unsigned char xdata* Addr, char element) { while(BUSY) EA = 0; E_EECON; *Addr = element; D_EECON; EA = 1; }
Is addr (_not_ *addr) initialized anywhere ? If it is not, you're writing to an unspecified memory location, which would generally be considered a Bad Thing(tm).
View all questions in Keil forum