I am facing an issue with initialization. I created a project with uVision3. I modified standard start up file STARTUP.A51 for my application as below:
?C_C51STARTUP SEGMENT CODE ?STACK SEGMENT IDATA RSEG ?STACK DS 1 EXTRN CODE (my_main) ;EXTRN CODE (?C_START) ;--- commented ?C_START ;.........Standard Code....... IF PBPSTACK <> 0 EXTRN DATA (?C_PBP) MOV ?C_PBP,#LOW PBPSTACKTOP ENDIF MOV SP,#?STACK-1 ;LJMP ?C_START ;--- commented jump to ?C_START LJMP my_main
NOTE: my_main is a starting function defined in my project.
I am including this modified file in my project. Also i am not including INIT.A51. With this i am facing an issue in my code. Whenever i initialized global data, program wont take it. For example, if i initialized below global variable:
unsigned char counter = 5;
When in code i checked counter value, it is always 0x00. I think this is problem with not calling ?C_START which is defined in INIT.A51. Due to this, all global initialisation is not happening.
Is this correct ? Is there any way to avoid this issue (apart from including INIT.A51)? Can anyone tell me which part of the INIT.A51 file i can copy to STARTUP.A51 before below code
;LJMP ?C_START ;--- commented jump to ?C_START LJMP my_main
so that i cant have this issue ?
Thanks in advance !!
Why are you removing INIT.A51 ?
www.catb.org/.../smart-questions.html
http://www.keil.com/support/man/docs/c51/c51_ap_customfiles.htm
"Can anyone tell me which part of the INIT.A51 file i can copy to STARTUP.A51 [...]"
The solution is simple. If you want your C code (and the CRTL) to see a normalized environment, you have to run all the required initialization functions.
If you don't know what code that must be run, then you also don't know what code to remove. So removing startup code would then be out of the scope.
So why then, when you don't have a 100% knowledge of the basic foundations for the C code to function, have you decided to cut out parts of the initialization code? What are you trying to solve that makes you think it is practical to first put out a ring of fires on the ice and then sit in the middle trying to catch some fish, while the ice is quickly melting all around you?
There is a programming paradigm KISS - Keep It Simple Stupid. It basically says that we should always try the simplest solutions to problems first, to avoid overcomplicating things. What huge problem do you need to solve that makes you reach directly for the big hammer?
I am facing an issue with initialization.
No, you're not. You're not facing an issue, you've just created one.
You foolishly decided to pick an utterly pointless fight with the tools --- and you lost. Yes, that hurts. So here's your lesson to take home for today: don't do that.
Removing INIT.A51 file by sheer accident I found out that if you have no initialized variables you will not have the init file. Of course, the startup is still there (as should be).
thus
char blah = 0; will give an init file
char blah main { blah = 0; will not
Erik
To Erik, I tried to init global variable as
char blah = 5;
However i found that it is initialized with 0 only, not with 5.
To others, It was a mistake done earlier by removing init.a51, trying to fix it.
Thanks for reponses.
So why didn't you just replace the INIT.A51??
As already noted, the purpose of INIT.A51 is documented here: http://www.keil.com/support/man/docs/c51/c51_ap_customfiles.htm
char blah = 5; However i found that it is initialized with 0 only, not with 5.
of course, when you muck with init you will get such. Do not "try to fix it" just start over.
Sure Erik, Will do that.
Thanks...