Table of Contents Previous topic Next topic
C COMPILER->8051 Specific Features->Absolute Object Location
C variables can be located at absolute locatations using the _at keyword. This feature can be used to simply reserve space used by other programs such as a monitor, or to simplify access to memory mapped I/O.
For example:
long _xdata variable _at 0X8000;
will locate at address 0X8000 and access to it will write or read the four bytes at 0X8000, 0X8001, 0X8002 and 0X8003.
Another example:
struct tag8255 {
unsigned char PortA;
unsigned char PortB;
unsigned char PortC;
unsigned char I_O;
};
#define BASE8255 0xFF00
volatile struct tag8255 _xdata S8255 _at BASE8255;
func()
{
S8255.PortA = 0X88; // write to address 0XFF00
S8255.PortC = 0X98; // write to address 0XFF01
}