We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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"
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
I typically design 8051 code using the SMALL model and use explicit xdata qualifiers where necessary, so I have never needed to try this, but you might try explicitly declaring and defining your EEPROM routines to use the SMALL model in your otherwise LARGE model project. For example:
void WriteE2ROM(unsigned char xdata *Addr,unsigned int e_data) small { } unsigned int ReadE2ROM(unsigned char xdata *Addr) small { }
Don't forget to also qualify the extern declarations.
That might be a way of avoiding the assembly language routine.
I'll post this in the other thread also. Why two threads were necessary, I don't know.
"I have never needed to try this, but you might try explicitly declaring and defining your EEPROM routines to use the SMALL model in your otherwise LARGE model project"
I think I did try this once, and it didn't work. I think I contacted Keil support and they said, "don't do that - it won't work"
One thing to remember is that C51 has different runtime libraries for each memory model: http://www.keil.com/support/man/docs/c51/c51_lib_files.htm this is going to be tricky if you mix models in one project...! :-0
1) "Since I had selected large memory model" WHY??? is it because you are too lazy? 2) The sulution is glaringly simple. If you REALLY are too LAZY to write effective code and want to use the LARGE memory model, then rewrite/recompile the EEPROM code.
Erik
"I had selected large memory model"
"WHY??? is it because you are too lazy?"
It may be the case that it is most appropriate in this particular application to have most variables in XDATA. In that case, it makes sense to use the LARGE model and only give specific memory-space qualifiers to the exceptions