This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C51: variables in XDATA - why doesn't that work?

Hi everybody,

I would like to access a variable in XDATA from different .c source files.

Obviously, that doesn't work the way i'm doing it, but what am I doing wrong?

Here is a tiny code example that shows the problem:

8<-----------------------------------------
(main.c)
unsigned char xdata receivedstring[1] _at_ 0x124;
unsigned char a;
void testfunction(void);

void main(void)
{ receivedstring[0]='q'; a=receivedstring[0]; testfunction(); while(1);
}

8<-----------------------------------------
(test.c)
extern unsigned char xdata receivedstring[1] _at_ 0x124;
unsigned char b;
void testfunction(void);

void testfunction(void){ b = receivedstring[0]; //doesn't work
}

8<-----------------------------------------

I would expect the variable 'b' to be set to 'q' at the end of the program. Watching at receivedstring[0] in the testfunction shows that its content is 'q' at address 0x0124, but the assembly shows that the content of 0x0000 instead of 0x0124 is assigned to the variable 'b':

8<-----------------------------------------
//assembly translation:

7: void testfunction(void){

8: b = receivedstring[0];
C:0x001A 900000 MOV DPTR,#0x0000 //why not "DPTR,#0x0124" ?
C:0x001D E0 MOVX A,@DPTR
C:0x001E F509 MOV b(0x09),A

9: }
C:0x0020 22 RET

8<-----------------------------------------

Thanks for any help!

Tobias

Parents
  • The device i use is the Oregano systems IP core. There is no bit to enable the XRAM.
    The Assembly code of the 'main.c' file shows that it accesses the XRAM at 0x0124:

         5: void main(void)
         6: {
         7:         receivedstring[0]='q';
    C:0x001D    900124   MOV      DPTR,#receivedstring(0x0124)
    C:0x0020    7471     MOV      A,#0x71
    C:0x0022    F0       MOVX     @DPTR,A
         8:         a=receivedstring[0];
    C:0x0023    F508     MOV      a(0x08),A
    
    

    And...: Yes, in the startup file, it only clears the XRAM address range. Should i add anything else here?

    Thanks, Tobias

Reply
  • The device i use is the Oregano systems IP core. There is no bit to enable the XRAM.
    The Assembly code of the 'main.c' file shows that it accesses the XRAM at 0x0124:

         5: void main(void)
         6: {
         7:         receivedstring[0]='q';
    C:0x001D    900124   MOV      DPTR,#receivedstring(0x0124)
    C:0x0020    7471     MOV      A,#0x71
    C:0x0022    F0       MOVX     @DPTR,A
         8:         a=receivedstring[0];
    C:0x0023    F508     MOV      a(0x08),A
    
    

    And...: Yes, in the startup file, it only clears the XRAM address range. Should i add anything else here?

    Thanks, Tobias

Children