Hi, I am using c51 keil compiler with cygnal chip c8051C020. I find problem in initilise static variable. exp. main() { static unsigned char i =0 ; i++; } when i write this type of code & simulate it ,i find that i is not initilise to 0. Note:this is just example code & not the actual program i work. If any specify me the reasion it will help me lot. Regards, Pandurang S.
Read the Manual about INIT.A51, what it does, and why you may need it.
hi, Thanks for reply. At present i worked with few project and never include the start.A51 & init.A51 file in my project, but never face this type of problem, which i am facing presently. What is reason for it. Regards, Pandurang S.
static unsigned char i =0 ;
unsigned char i =0 ;
hi, The code that i have put in the forum is just an examle,i am using the static variable not in main routine but in other function which i calling in main routine. And in any way the variable should initilise to 0 even if it not make any sense. Regards, Pandurang S.
never include the start.A51 & init.A51 And in any way the variable should initilise to 0 even if it not make any sense. what does not make sense is that you "never include" the code that initializes the variables and the complain that they are not initialized. Erik
"The code that i have put in the forum is just an examle" Please don't do that, it is a waste of our time. Copy and paste the code you are using, do not retype it as you will make mistakes.
hi, I have add the INIT.A51 & STARTUP.A51 files.But still i have facing the same problem (i.e. static variable not initilise to proper value). Regards, Pandurang S.
still i have facing the same problem (i.e. static variable not initilise to proper value). if you are using internal XRAM you will not, unless you put all memory related initialize at the very beginning of (a renamed copy of) startup.a51. Erik
"I have add the INIT.A51 & STARTUP.A51 files.But still i have facing the same problem (i.e. static variable not initilise to proper value)." Including those files in your project will not make any difference unless you modify them.
"if you are using internal XRAM you will not, unless you put all memory related initialize at the very beginning of (a renamed copy of) startup.a51." I don't understand what you're trying to say here, so I doubt the OP will be able to make much sense of it. Can you explain better?
I don't understand what you're trying to say here, so I doubt the OP will be able to make much sense of it. Can you explain better? If you "knew" the f020 the OP is using, you would. The f020 has a rather intricate memory configuring process and if that is not dome before the "clear XRAM" in startup and "init XRAM variables" in init, the processes are writing "out in thin air" Erik
"The f020 has a rather intricate memory configuring process and if that is not dome before the "clear XRAM" in startup and "init XRAM variables" in init, the processes are writing "out in thin air"" I thought that one defaulted to using internal XDATA?
I thought that one defaulted to using internal XDATA? you're right this one does.
hi, Thanks to all for immediate reply. "Including those files in your project will not make any difference unless you modify them" What modification i have to make? Regards, Pandurang S.
those required for your chip here is an example for a f12x
STARTUP1: ;---------------------------------------------------------------- ; Watchdog Timer Configuration mov SG_WDTCN,#0DEh ; Disable WDT mov SG_WDTCN,#0ADh ; takes 2 writes ; CROSSBAR REGISTER CONFIGURATION mov SG_SFRPAGE,#00Fh mov SF_XBR0, #004h ; XBAR0: UART0 enabled mov SF_XBR1, #00ch ; XBAR1: INT0, T1 to port pin mov SF_XBR2, #040h ; XBAR2: crossbar enbl & non-mpx memory ; Select Pin I/0 mov SG_SFRPAGE, #00Fh; mov SF_P0MDOUT, #011h ; Output configuration for SG_P0 TxD PP, remaining open drain mov SF_P1MDOUT, #0ffh ; Output configuration for SG_P1 all are push-pull mov SF_P2MDOUT, #0ffh ; Output configuration for SG_P2 all are push-pull mov SF_P3MDOUT, #0ffh ; Output configuration for SG_P3 all are push-pull mov SF_P4MDOUT, #0c3h ; Output configuration for SF_P4 mixed mov SF_P5MDOUT, #0ffh ; Output configuration for SF_P5 all are push-pull mov SF_P6MDOUT, #0ffh ; Output configuration for SF_P6 all are push-pull mov SF_P7MDOUT, #0ffh ; Output configuration for SF_P7 all are open drain mov SF_P1MDIN, #0FFh ; Input configuration for P1 mov SG_SFRPAGE,#000h mov S0_EMI0CF,#038h ; External Memory Configuration Register ; Oscillator Configuration ; internaql oswcillator, system clock = 48MHz mov SG_SFRPAGE,#000h mov S0_FLSCL,#090h mov SG_SFRPAGE,#00fh orl SF_PLL0CN,#001h mov SF_PLL0DIV,#001h mov SF_PLL0FLT,#021h mov SF_PLL0MUL,#002h clr A ; Wait 5us for initialization djnz SG_ACC, $ orl SF_PLL0CN, #002h Pll_Wait: mov A,SF_PLL0CN jnb SG_ACC.4,Pll_Wait mov SF_OSCICN,#083h mov SF_CLKSEL,#002h mov SG_SFRPAGE,#000h mov S0_RSTSRC,#002h ; Reset Source Register mov S0_EMI0TC,#000h ; External Memory Timing ; clear (i)data