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.
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).
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; }
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?
Sorry for what I have sended the code actually the code was while(BUSY); was the code.
Please regreet the mistake.
OK then. What about the EECON assignment inside the 'while' condition? It is legitimate C and might be your intention, but I'm just checking on that too.
To answer my own question regarding your intention, that can't be your intention. The assignment clears the EEE bit, disabling the EEPROM space.
Yes, I just went ahead and spent time downloading the datasheet to quickly determine this for myself, never having used the device before.
The problem is thar this device contains internal XRAM and EEPROM how to write at the specific location in the EEPROM.
Actually I used seprate pointer variable which contains the address where the data has to be stored but it is not storing in the EEPROM.
Kindly send the program which solves the above problem that would be great help form U.
View all questions in Keil forum