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
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
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; }
'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; } } }
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)
"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?