My code is just as simple as below:
static unsigned int xdata user_timer_count[8]; static unsigned int xdata count[8]; void func1() { } void main() { int j; user_timer_count[2] = 1000; count[2] = user_timer_count[2]; while(1) { for(j=0;j<8;j++) { if(count[j]==0) continue; if(count[j]==1) { count[j] = user_timer_count[j]; func1(); continue; } --count[j]; } } }
The question is when I declare count as xdata, my program crashes in a uncertain time later. Even after I press reset button, It doesn't work properly. I have to turn down the power and restart.
when I declare:
static unsigned int count[8];
It seem to worked well. I don't know whether it will crash some longer time later, or it's all right. I'm using Small Momery Model, on-chip ROM and XROM. Who can give me some suggestion?
P89C669 has 768 Bytes on-chip XRAM, from 0x0-0x2FF.
The Memory layout is
XDATA (0x0-0x2FF), HDATA (0x0-0x2FF), EDATA(0x7F0000-0x7F04FF), ECODE (0x800000-0x817FFF), HCONST (0x800000-0x817FFF))
.. set the appropiate SFR bit(s) to enable internal xdata (see the datasheet) in (a local copy of) startup.a51.
Erik
It's already set.
startup.a51
; EXTRAM: Enable on-chip XDATA RAM ; When disabled, off-chip XDATA space is accessed ; XDATA access (External XDATA space) ; EXTRAM Val Description ; --- --- ----------- EXTRAM EQU 0; 0 = access on-chip XDATA RAM ; ; 1 = disable on-chip XDATA and access off-chip XDATA space
Is there something else?
I just don't undersatnd why program run well for a while and then crashes.
static unsigned int xdata user_timer_count[8]; static unsigned int count[8];
runs properly but
static unsigned int xdata user_timer_count[8]; static unsigned int xdata count[8];
doesn't.
Did you test that you have RAM there?