We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I try to accces external Memory using XDATA.
I use the following code:
extern volatile unsigned char xdata interface_register _at_ 0x3;
This is the variable I want to acces, like this:
interface_register = 0x82;
Everything ok, so far.
But when I run the code in the simulator, it doesn't work. The compiler generated the following code(dissasembled):
40: interface_register = 0x82; // Interface konfigurieren: PA = Out, PB = IN, PC = OUT 41: C:0x00FB 900000 MOV DPTR,#0x0000 C:0x00FE 7482 MOV A,#DPL(0x82) C:0x0100 F0 MOVX @DPTR,A
So far as I can see, the Datapointer is not set correct. It should be set to 0x02. I can't find the problem.
The corresponding code from the listing is:
; SOURCE LINE # 27 0009 900000 MOV DPTR,#interface_register 000C 748B MOV A,#08BH 000E F0 MOVX @DPTR,A
The compiler used the # Operator to get the value of interface_register, to load it into DPTR. But why does the compiler use the # Operator? It should use the @ Operator to get the definend adress of interface_register (0x2).
Any suggestions? What did I do wrong?
Thanks
"But why does this not work with xdata variables?"
I doubt it's anything to do with xdata - it'll be the _at_ that's causing the problem!
Think about it: _at_ is only really relevant in a data definition - it is at best irrelevant in an extern declaration