
This document information is the intellectual property of Megawin Technology Co., Ltd.
28
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
The following example code shows how to use both on-chip XRAM and external RAM in an application. To view
G_array1[ ], select
“Display xdata from on-chip XRAM”; and to view G_array2[ ], select “Display xdata from
external RAM
”.
Example of using both on-chip XRAM and external RAM
unsigned char xdata G_array1[512] _at_ 0x0000; // in 'xdata' space, will use on-chip XRAM
unsigned char xdata G_array2[512] _at_ 0x0000; // in 'xdata' space, will use ext. RAM
unsigned int i;
AUXR&=0xFD; //clear AUXR.1 for on-chip XRAM
for (i=0; i<512; i++) G_array1[i]=0x5A; // fill XRAM with 0x5A
AUXR|=0x02; //set AUXR.1 for external RAM
for (i=0; i<512; i++) G_array2[i]=0xA5; // fill ext. RAM with 0xA5
Note that there will be a linking warning listed below. However, it doesn
’t matter because we intentionally declare
G_array1 and G_array2 in the same address space. In fact, we access to the different physical memory
controlled by bit-1 of AUXR.
7.3 Code Optimization and Source-Level Debugging
As shown in the following source code, the C51 compiler won
’t generate any machine code for “
L_var1=0x38;
”
because this statement becomes meaningless due to its following statement
“
L_var1=0xC7;
”. For code
optimization,
“
L_var1=0x38;
” will be optimized out unless the code optimization is disabled as described in
Section 4.4
.
unsigned char L_var1;
L_var1=0x38; // ! Note: this statement may be optimized out by the C51 compiler
L_var1=0xC7;
So, during source-level debugging,
L_var1
will never show
0x38
but may show a random number when this
statement is just executed. In fact, there in no machine code for this statement. The user should pay attention to
it!
Sometimes, for debugging purpose, the user may disable the compiler
’s code optimization. Note that once the
compiler
’s code optimization is disabled, there may be some linking errors which won’t occur when the code
optimization is enabled. For example, refer to the following linking error message, it means the variables you use
exceed the RAM an MCU has. To make this error disappear, the only way is to enable the compiler
’s code
optimization to let the compiler make more efficient use of the RAM.