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

uVision 4 compiler memory allocation

Hi All,

I am using DS89C450 MCU and writing my C code using uVision 4 compiler. In my DS89, I had a SRAM of 1kB and I would like to declare a 500 variable of unsigned char therefore I use

unsigned char xdata IR[500];

When I compiler with uVision 4, it show no error and therefore I burn the Hex code into my MCU. However, when I write and then read the IR[500], it give incorrect value

I therefore proceed to use debugger to troubleshoot my code and everything works fine in the debugger. My code does not have any problem.

Therefore I suspect uVision 4 had assign the IR[500] to non SRAM location and therefore the value is actually not written and read.

I would like to know how can I make sure uVision4 assign the SRAM location correctly and is there any setting I need to set before compiling?

Pls help. Thanks a lot

Parents
  • I therefore proceed to use debugger to troubleshoot my code and everything works fine in the debugger. My code does not have any problem.

    That conclusion is premature. Just because code works in one (rather unrealistic) environment, doesn't mean the code "does not have any problem". It's just as likely that the environment just didn't trigger the problem.

    Therefore I suspect uVision 4 had assign the IR[500] to non SRAM location and therefore the value is actually not written and read.

    Why suspect when you can check? The linker tells you exactly where it put everything. All you have to do is look in the map file. That's what you got it for.

    That said, I'll second Per's suggestion: most likely you forgot to tell the tools that you're going to be using the internal XRAM of your controller. Oh, and "telling the tools" would typically include a change to the startup code.

Reply
  • I therefore proceed to use debugger to troubleshoot my code and everything works fine in the debugger. My code does not have any problem.

    That conclusion is premature. Just because code works in one (rather unrealistic) environment, doesn't mean the code "does not have any problem". It's just as likely that the environment just didn't trigger the problem.

    Therefore I suspect uVision 4 had assign the IR[500] to non SRAM location and therefore the value is actually not written and read.

    Why suspect when you can check? The linker tells you exactly where it put everything. All you have to do is look in the map file. That's what you got it for.

    That said, I'll second Per's suggestion: most likely you forgot to tell the tools that you're going to be using the internal XRAM of your controller. Oh, and "telling the tools" would typically include a change to the startup code.

Children