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

Problem initializing global variables

Hello!

I'm using a AT89c51RC Controller for my application.

When I define global variables with an initial value,
they are not always initialized correctly.

Example:

signed int test=3;

If I place the variable on the beginning of the xdata
memory space, then they are initialized correctly. But if
I place the variable at the back of xdata, they have wrong
values like -16235.

I have deleted or commented out all loops in my programm,
so there cannot be a memory overflow, that is produced be me.

If I initialize the variables later within my program manually,
everything works correctly -> so the error must occur before the program
starts.

I also checked out the amount of xdata that is used by my
program, but its far from being full.

Is it possible, that there is an error in the startup.a51 or init.a51 files?

I use no reentrant functions, so I disabled the XBPSTACK but
that changed nothing ...

Maybe someone can help me or give me a hint

Josef

Parents
  • But if I place the variable at the back of xdata, they have wrong values like -16235.

    a recollection, which may not apply, is that some chips have been described (AARGH) with memory size that include both (I)DATA and EDATA e.g. 1k will give you 768 bytes of ERAM ("internal external RAM). I DO believe the RD2 is one of those, check your datasheet

    could that be the case for you?

    some write/reads will work in nonexisting memory, due to incomplete (but sufficient) address decoding and then be overwrittn by writes to another matching address.

    Erik

    PS I fell in that trap once :(

Reply
  • But if I place the variable at the back of xdata, they have wrong values like -16235.

    a recollection, which may not apply, is that some chips have been described (AARGH) with memory size that include both (I)DATA and EDATA e.g. 1k will give you 768 bytes of ERAM ("internal external RAM). I DO believe the RD2 is one of those, check your datasheet

    could that be the case for you?

    some write/reads will work in nonexisting memory, due to incomplete (but sufficient) address decoding and then be overwrittn by writes to another matching address.

    Erik

    PS I fell in that trap once :(

Children