Maybe I have some setting wrong in my project. At the beginning of my main source file, I include a header that declares several variables as externs. Then I declare and initialize them after the #include.
Main Source:
#include <header.h> ... const char DEVICE_NAME[] = "ELC"; const char VERSION_NUMBER[] = "F1.0M1.0"; const char CONTROL_PANEL = 1; ... void main(void) { ... }
Header (header.h):
#ifndef _HEADER_H #define _HEADER_H ... extern char DEVICE_NAME[],VERSION_NUMBER[],CONTROL_PANEL; ... #endif
The variables are then used in implementation code in another file. This other file and the header are common to several projects that I'm working. (I have restructured my projects per our last discussion.)
The problem that I'm experiencing is that all of the data is initialized to 0 at the beginning of main() rather than the specified values. I don't have any of the .A51 initialization files in my project, so what could be causing this?
Thanks.
I don't have any of the .A51 initialization files in my project, so what could be causing this?
That very thing might just be causing it. INIT.A51 does the job that's not being done in your project. So how about you try putting it into your project and see if that makes a change?
So how about you try putting it into your project and see if that makes a change?
No change. All of my preset string variables are still zeroed out. Is there anything more that I need to do than just add it to my project?
From the documentation, it seems like INIT.A51 clears all of the memory at device startup. I don't want it cleared; I want it to initialize properly.
Is there anything more that I need to do than just add it to my project?
It has to be the last entry in your project. Otherwise it won't work.
From the documentation, it seems like INIT.A51 clears all of the memory at device startup.
I don't know which documentation you're referring to, but no, that's not what INIT.A51 does. It initializes explicitly initialized variables.
Okay. New information. In the implementation of my header file, I have a large (5000) char array in xdata that I initialize to 0. When I reduce the size to 250, the other variables initialize as they're supposed to. It appears that the array is initializing over the other variables.
#ifndef _HEADER_H #define _HEADER_H ... extern char DEVICE_NAME[],VERSION_NUMBER[],CONTROL_PANEL; extern char output_buffer[]; ... #endif
Implementation (header.c):
#ifndef _HEADER_C #define _HEADER_C #include <header.h> ... char output_buffer[5000] = {0}; ... #endif
If I move the declaration to the main source file, the code works, even with the larger array.
#include <header.h> ... char output_buffer[5000] = {0}; const char DEVICE_NAME[] = "ELC"; const char VERSION_NUMBER[] = "F1.0M1.0"; const char CONTROL_PANEL = 1; ... void main(void) { ... }
#ifndef _HEADER_C #define _HEADER_C #include <header.h> ... #endif
Why would the compiler overlap memory allocation in the first case, but not the second?
[edit] All of the
char output_buffer
should be
char xdata output_buffer
View all questions in Keil forum