Hello, Some of the variables that my program uses(may contain also big ,multidimensional arrays) have default values, which are used during the code operations and may be modified during the program's runtime. defining a variables using:
volatile xdata arrayName = [0x01, 0x03, 0x02, 0x04...];
volatile code arrayName = [0x01, 0x03, 0x02, 0x04...];
No, there is no such method. Because there can't be. Initializers have to be in read-only code memory so you can load them into the device as part of the program, where they will survive a power-cycle of the device. But modifiable variables must be in RAM. Thus, an initialized modifiable variable must exist in two separate copies. Nothing to be done about it. There's one possible way around this, though: computed startup values. I.e. you can do the initialization manually, instead of leaving it to the compiler, and express it in a more compact manner than a list of values. If you're lucky.
Dear Hans, In the application that I am working on - both the code and the xdata areas will be located in a 64KByte of RAM. During the reset stage, the program code will be loaded into the 8051's RAM by an external controller, and only after the 8051's code is loaded into it's RAM - the 8051 will be unreset. Therefore, there is no point in creating a code that will hold the default values of the variables (which, BTW, is not computable) in a place in the RAM that holds the code, and then copy the same init values into the xdata area in the same RAM (and by doing that, duplicating the initiated variables size). Defining a variable to be in the code space will put the default values in a single place in the HEX file (that will be loaded into the RAM), but' as I said before, will case a restriction: The array will be read only. About Andrew's answer: XCONST is not mentioned in the C51 User guide. I didn't see any place that describes and tells me if this can declare a modifiable variable, but by the name I can guess that it is also not writable are. Am I correct ? Is there any other way that you can think of, that will help me get the functionality that I need ? Amit.
http://www.keil.com/support/man/docs/c51/c51_userclass.asp Also do a 'Search' of the Forum & Knowledgebase
http://www.keil.com/support/man/docs/c51/c51_userclass.asp Also, do the 'Search' of this forum, and the Knowledgebase.
Hmmm... dunno why that came up twice...?
I saw that link already. ( http://www.keil.com/support/man/docs/c51/c51_userclass.asp ) It says "XCONST - Constants in const xdata space (XDATA class)." but doesn't say whether it is a modifiable area (variable) or not. Also, doesn't the fact that it is not mentioned in the C51 User guide means that it may not be supported by the C51 compiler / linker ? Amit.
"... it is not mentioned in the C51 User guide means ..." Which particular version(s) of the guide(s)? I think the latest is the online version; the printed versions (including the PDFs installed with the tools) are quite out of date? It certainly works with the current C51, but does require LX51 (not BL51).
"doesn't say whether it is a modifiable area" True. I'm not sure about that. You may need to contact Keil support direct on that one.
View all questions in Keil forum