I am not sure, if I have understood the usage of the PDATA segment properly. When pdata is used (in the compact memory model), the variables in the external memory can be addressed with MOVX A,@Rx , which will save some processor cycles compared to the MOVX A,DPTR command. The high byte of the memory address will be in P2 (that are the A8..A15 signals). When I want to use PDATA, I have to include a modified STARTUP.A51 and tell the linker the location of the PDATA-segment and that it has to link STARTUP.OBJ, too. Is it possible to use PDATA and XDATA (different pages from PDATA) simultaneously? Is it possible to use PDATA and external program memory? I have seen, that P2 is loaded with the PDATA page in STARTUP. I think, every external access to a page that is not the PDATA page will "corrupt" P2 as the high byte of PDATA. Why I ask? I have a project, that I didn't write the software for and the guy who did it is hopefully resting in peace. Now I have to modify the software a bit, but I cannot get a running code. Unfortunately all *.M51 and *.OBJ files were deleted, so I cannot retrieve the compiler and linker options that were originally used anymore. My configuration is 64k of external code memory and 32k of external RAM. Originally, the code contains some xdata and some pdata variables. I guess, that mixing the kind of variables kinda screws up everything and that the external code access do also corrupt the pdata variables.
Generally speaking you should not have any difficulty with a project that includes both pdata and xdata. Things get interesting if you try to move the page that is accessed by pdata - that is you change the value of P2. Is that what is happening in your source code?
I have seen, that P2 is loaded with the PDATA page in STARTUP. I think, every external access to a page that is not the PDATA page will "corrupt" P2 as the high byte of PDATA. Not if done with MOVX (XDATA to you C people). With MOVX P2 is only set to the high address for the required time to read the XDATA, then returns to the preset value. Erik
It is possible to use 'xdata' and 'pdata' at the same time. All standard 8051 devices save the content of P2 when executing MOVX @DPTR instructions. The P2 value is output to the BUS when executing MOVX @Ri instructions. Therefore it is save to intermix both address methods in the same application. Please check also with the device datasheet. Some variants with on-chip xdata RAM always address memory page 0 with MOVX @Ri when on-chip xdata RAM is enabled. It should be noted that this behaviour is correctly simulated by uVision2.
The following knowledgebase article discusses how to configure and use PDATA with chips that have on-chip XDATA. http://www.keil.com/support/docs/1848.htm Jon