unsigned char tp; unsigned char volatile pdata HOSTCFG2 _at_ 0x0020; // HOSTCFG2=0x40 at this point tp=HOSTCFG2 & 0x40; //!!! tp is 0x00 instead of 0x40 which is expected //Corresponding Disassembly: C:0x08F1 7820 MOV R0,#HOSTCFG2(0x20) C:0x08F3 E2 MOVX A,@R0 C:0x08F4 5440 ANL A,#HPWRSTATE(0x40) //Why it refers 0x40 as an address instead of a constant here? C:0x08F6 F508 MOV 0x08,A 189: if ((HOSTCFG2 & 0x40)==0x00)
The # means "immediate addressing", which is to say a literal constant, not necessarily an address. In the first line, the #20H happens to be a constant used as address in the second line (MOVX). In the third line, the #40H happens to be a constant value used in the ANL operation. How do you know that HOSTCFG2 is really 0x40? Have you checked the configuration of your pdata area to be sure it matches the hardware? Does your hardware correctly supply the upper 8 bits of the address?
Thanks for your quick response. I tried to move the variables from pdata space to xdata as follows. But still got similar probblems.
unsigned char volatile xdata HPWRSTATE _at_ 0x1040; // In the Debug mode, the HPWRSTATE is shown to be 0x05; if ((HPWRSTATE & 0x0F) ==5) // However the above test turned out to be false; I checked the memory window X:0x1040 is 05h. C:0x0800 900000 MOV DPTR,#C_STARTUP(0x0000) // Don't know why the C51 couldn't use the address 0x1040 here. C:0x0803 E0 MOVX A,@DPTR C:0x0804 540F ANL A,#0x0F C:0x0806 6405 XRL A,#0x05 C:0x0808 701E JNZ C:0828
uVision does not automatically alter the startup code to fit the dialog box values. Those values are used for the debugger, and some of the command-line parameters to the compiler and linker. (See the "linker control string" box on the LX51 tab in uVision.) But they do not get passed in to STARTUP.A51. You must alter that file yourself. Did you get a link error when building this project? The assembler code shown is certainly wrong, since the DPTR isn't being loaded with the proper address. All zeroes makes me think that offset wasn't updated.
I have seen quite often tha when a label match a constant, the tools pick the label. Thus if HPWRSTATE(0x40) indeed is address 0x40 that is exactly what happens. Erik
Yes. Most tools will just pick the first symbol that matches the value that they see. But it doesn't bother me that the symbol is CSTARTUP. It bothers me that the immediate value in the instruction is 0000H when the _at_ keyword assigns the address 1040H. The code should read:
C:0x0800 900000 MOV DPTR,#SomeSymbol(0x1040)