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

XDATA problem

Hopefully someone can Help,

I'm working on a project with the Atmel AT89C51ED2 processor. I have selected the AT89C51RD2 controller from the device database (If I'm not mistaken the only difference is the EEPROM which I'm not using..... Yet).
I have a project which works correctly (in the simulator) except when Xdata is used. I have gone through tens of threads and can not find the answer.
I have edited the Startup.A51 code which seems to work (clears 0x6FF bytes of data) cleared bit 1 of AUXR. All seems to be OK. I suspect the simulator, I have checked the memory mapping, and that also seems to be OK. Everything is working except Xdata.

Any thoughts of anything else I can try..??

Any suggestions appreciated.

Regards
John Garrelts

  • Internal or external xdata? Have you modified STARTUP.A51 to initialize whatever memory map registers this part has to select on-chip xdata versus off-chip xdata? Is the xdata on the target hardware known to work?

  • This problem is with internal Xdata. I can't try it on a live system seeing as the hardware is not ready yet. The problem I'm having is in the simulator. After compiling, if I look at the listings everything seems fine, All the correct bits seem to be set. I think it has something to do with the simulator somewhere.

    I include some parts of the listings, maybe you can see something I've done wrong there.

    XDATASTART      EQU     0H      ; the absolute start-address of XDATA memory
    XDATALEN        EQU     6FFH    ; the length of XDATA memory in bytes.
    
    STARTUP1:
    
    ;		AUXR	Bit 1 (clear to 0 to enable on-chip XRAM)
    ;		0x6FF = 1792 Bytes	XXX100XX
    ;		0x3FF = 1024 Bytes	XXX011XX
    ;		0x300 = 768  Bytes	XXX010XX
    ;		0x1FF = 512  Bytes	XXX001XX
    ;		0x100 = 256  Bytes	XXX000XX
    ;		Bits ->			7------0
    ;		Bit 1 cleared to enable OnChip Xdata
    ;			For size see list above
    		CLR	A
    		ADD	A, #10H
    		MOV 	AUXR, A
    

    I did notice something else when going several other listings. Could it be that I have the use the static preprocessor?

    Thanks for your response, appreciated

    Regards
    John Garrelts

  • "This problem is with internal Xdata."

    So what exactly is happening?

    In what way is it "not working?"

  • STARTUP1:
    
    ;		AUXR	Bit 1 (clear to 0 to enable on-chip XRAM)
    ;		0x6FF = 1792 Bytes	XXX100XX
    ;		0x3FF = 1024 Bytes	XXX011XX
    ;		0x300 = 768  Bytes	XXX010XX
    ;		0x1FF = 512  Bytes	XXX001XX
    ;		0x100 = 256  Bytes	XXX000XX
    ;		Bits ->			7------0
    
    So what are all these 12-bit values?

  • I'll go back to basic's to make it all more understandable.

    I left my application a wrote a simple C program setting a byte in Xdata.

    #include <89c51rd2.H>
    
    Xdata unsigned char test;
    
    
    void main(void){
      test = 0xFF;
      }
    

    When run in the simulator test is not set to 'FF'.
    If I change test to Idata or Data, all works.
    The list shown in the listing above, shows the preset value's in AUXR. With 3 bits it is possible to select the size of the Internal Xdat (in AUXR)

    Regards
    John

  • 'test' is probably being optimised away. Add a couple of extra lines of code which modify or use test then try again.

  • Got it... :)

    It was most probably optimised out, just as Stefan said. I used the following program to test it. I thought, no way this can be optimised out.... it won't fit anywhere else. Anyway worked first time running. At least I know xdata works... one worry less. Thanks to everyone for the support and help, much appreciated :)

    #include <89c51rd2.H>
    #include <stdio.h>
    
    
    xdata unsigned int temp[895];
    
    
    void main(void)
    	{
    		unsigned int i;
    			while(1)
    			{
    				for(i = 0; i<895; i++)
    					{
    					temp[i] = i;
    					}
    			}
    	}
    

    Again thanks
    Regards
    John

  • It was most probably optimised out...

    Here's what I get for the compiler output. As you can see, the access to xdata was not "optimized out". Maybe there was another reason this didn't work.

    line level    source
    
       1
       2
       3          xdata unsigned char test;
       4
       5
       6          void main(void){
       7   1        test = 0xFF;
       8   1        }
    
    ASSEMBLY LISTING OF GENERATED OBJECT CODE
    
                 ; FUNCTION main (BEGIN)
                                               ; SOURCE LINE # 6
                                               ; SOURCE LINE # 7
    0000 900000      R     MOV     DPTR,#test
    0003 74FF              MOV     A,#0FFH
    0005 F0                MOVX    @DPTR,A
                                               ; SOURCE LINE # 8
    0006 22                RET
                 ; FUNCTION main (END)

    Jon

  • "As you can see, the access to xdata was not "optimized out". Maybe there was another reason this didn't work."

    Presumably test would have been optimised out had it been an automatic variable?