Hi Keil,
I sloved the EEPROM problem with AT89C51ED2, the problem was in the memory module selection.
Since I had selected large memory model, the EEPROM was not working, when I changed it to Small memory model,it started working fine.
But now my problem is my project is designed for Large memory model , How can I make this code work for Large memory model??
I checked it for Read operation, It was working fine, but It was not able to write to EEPROM with this large model!!
The code is,
/*======================================================================== FUNCTION TO WRITE DATA TO INTERNAL E2ROM OF AT89C51ED2 ========================================================================*/ void WriteE2ROM(unsigned char xdata *Addr,unsigned int e_data) { unsigned char idata FBuffer[6]; char idata i=-1; sprintf(FBuffer,"%d",(unsigned int)e_data); do { while(BUSY); EA=0; E_EEPROM; i++; // WRITE *(Addr+i) =FBuffer[i]; D_EEPROM; EA=1; }while(FBuffer[i]!='\0'); } /*=============================================================== FUNCTION TO READ DATA TO INTERNAL E2ROM OF AT89C51ED2 ===============================================================*/ unsigned int ReadE2ROM(unsigned char xdata *Addr) { unsigned char idata EBuffer[6]; unsigned int idata FData; unsigned char idata i=0; while(BUSY); EA=0; E_EEPROM; while(*(Addr+i)!='\0') { EBuffer[i] = *(Addr+i); // READ i++; } D_EEPROM; EA=1; EBuffer[i]='\0'; FData=atoi(EBuffer); return FData; }
Is there any better approch to write to eeprom ??? If it is please send me the correct way to approch the problem.
you simply remove all the memory type specifiers like xdata, idata ... and try by selecting the Large memory model.
"you simply remove all the memory type specifiers like xdata, idata"
If you do that, everything (inlcuding function parameters, etc) will be placed into the default memory space. The default memory space is defined by the memory model. For the LARGE memory model, the default memory space is XDATA.
The problem lies in the use of XDATA, as Dan Henry explains in this thread on the same subject: http://www.keil.com/forum/docs/thread8204.asp
Therefore, using the LARGE memory model in this case will not work - as Dan explained.
"Is there any better approch to write to eeprom ??? If it is please send me the correct way to approch the problem."
As Dan Henry says, if your 'C' has to use the LARGE memory model, then you need to write your EEPROM access routines (both read and write) in assembler: http://www.keil.com/forum/docs/thread8204.asp
Dear,
How can I write Assembly Code in C
Please explain in Clear
If you have any sample code please send to me
"How can I write Assembly Code in C"
You can't!
Instead, you CALL your assembler routines from 'C'
http://www.keil.com/support/man/docs/c51/c51_ap_ctoasm.htm
The easiest way to create the necessary assembler source is:
1. Write "skeletons" of the required functions in 'C'
2. Get the 'C' compiler to convert these into assembler source by using the SRC directive http://www.keil.com/support/man/docs/c51/c51_src.htm
3. Delete the 'C' file - it has served its purpose; it is no longer required
4. Complete the assembler functions in the assembler source file generated above by the compiler
See also: http://www.keil.com/download/docs/53.asp
View all questions in Keil forum