This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Write Function Call does not work properly

Hi, I need to write to specific memory location, but when the program calls the function to do it, it does not.
This is the function

void EEPROMwrite(unsigned int adr, unsigned int dat)
{
EA=0; // disable Interrupts during write
DEECON=(unsigned int)((adr>>8)&0x01); // mode: write byte, set address
DEEDAT=dat; // set write data
DEEADR=(unsigned char) adr; // start write
EA=1;
while((DEECON&0x80)==0); // wait until write is complete
}

I have noticed that when this function is called, DEECON = 0x0E, which is wrong and skips the instruction where DEECON=(unsigned int)((adr>>8)&0x01);
Then it gets the data to be written, the address, sets EA and gets out of the function. it does not wait until written is complete why?
Thanks

Parents
  • "How come when I test the EEPROM sample program it works fine, but in my program it does not."

    Must be some mistake or misunderstanding in your program, surely?
    Look carefully at what you changed in going from the sample to your own program.

    Go back to the sample, then make just one change at a time to make it like your program. The point that it starts going wrong is, obviously, the bit to look at!


    Have you tried comparing the generated assembler?

Reply
  • "How come when I test the EEPROM sample program it works fine, but in my program it does not."

    Must be some mistake or misunderstanding in your program, surely?
    Look carefully at what you changed in going from the sample to your own program.

    Go back to the sample, then make just one change at a time to make it like your program. The point that it starts going wrong is, obviously, the bit to look at!


    Have you tried comparing the generated assembler?

Children
  • Andy Neil, I did just what you said. changed one thing at the time. In fact I made the sample program just like the writing section of my program...(mostly changing characters to interger variables). It still works fine in the modified sample, but not in my program. I will keep checking...otherwise I'll post it for you to see.
    Thank you

  • "mostly changing characters to interger variables"

    Aha!

    Is that wise? Is it valid?
    Are you sure that is safe?

    Remember: the 8051 is an 8-bit processor, and ints are 16 bits in C51.
    Therefore, changing anything from char to int makes a BIG difference to the code generated by the compiler!

    In particular, because the code now has to deal with all these 16-bit values in two 8-bit halves, you are much more susceptible to interrupts happening in the middle of the operation and messing things up!

    Are you sure you have specified everything as volatile that needs it?