Keil Logo

C51: AVOIDING STARTUP INITIALIZATION OF STATIC VARIABLES


Information in this article applies to:

  • C51 Version 5.50

QUESTION

I have a C function which contains some xdata static variables. When the device is reset I do not want the locations those variables are stored at to be initialized to 00H by the startup code. How can that be achieved?

ANSWER

The file STARTUP.A51 includes the code for initialization of data memory and is included with every project if required. By default the XDATA is not initialized however the STARTUP.A51 file allows this to be easily configured.

The easiest way to avoid initialization of static or global variables is by performing the following steps:

  1. Absolutely locate the variables at particular locations e.g:
    xdata static unsigned int foo _at_ 0xF3C1;
    
  2. Copy the STARTUP.A51 file to your project.
  3. Edit the STARTUP.A51 file so that the static variable locations are not initialized.

If you include all your static variables in a single structure then you can absolutely locate that structure rather than every single variable.

Note that you need to copy INIT.A51 to your project directory and modify it if you want to remove initialization of all global variables.

MORE INFORMATION

SEE ALSO

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Tuesday, October 24, 2006


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.