Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
50
Добавлен:
14.04.2015
Размер:
1.37 Mб
Скачать

104

Chapter 3. Language Extensions

 

 

Absolute Variable Location

Variables may be located at absolute memory locations in your C program source modules using the _at_ keyword. The usage for this feature is:

type memory_space variable_name _at_ constant;

 

where:

 

 

memory_space

is the memory space for the variable. If missing from the

 

 

declaration, the default memory space is used. Refer to

3

 

 

“Memory Models” on page 94 for more information about

 

the default memory space.

 

 

 

type

is the variable type.

 

variable_name

is the variable name.

 

constant

is the address at which to locate the variable.

The absolute address following _at_ must conform to the physical boundaries of the memory space for the variable. The Cx51 compiler checks for invalid address specifications.

NOTE

If you use the _at_ keyword to declare a variable that accesses an XDATA peripheral, you may require the volatile keyword to ensure that the C compiler does not optimize out necessary memory accesses.

The following restrictions apply to absolute variable location:

1.Absolute variables cannot be initialized.

2.Functions and variables of type bit cannot be located at an absolute address.

Keil Software — Cx51 Compiler User’s Guide

105

 

 

The following example demonstrates how to locate several different variable types using the _at_ keyword.

struct link

{

struct link idata *next; char code *test; };

struct link list idata

_at_ 0x40;

char xdata text[256]

_at_ 0xE000;

int xdata i1

_at_ 0x8000;

void main ( void ) { link.next = (void *) 0; i1 = 0x1234; text [0] = 'a';

}

/* list at idata 0x40 */ /* array at xdata 0xE000 */ /* int at xdata 0x8000 */

3

You may wish to declare your variables in one source module and access them in another. Use the following external declarations to access the _at_ variables defined above in another source file.

struct link

 

 

{

 

 

struct link idata *next;

 

char

code *test;

 

};

 

 

extern struct link idata list;

/* list at idata 0x40 */

extern char xdata text[256];

/* array at xdata 0xE000 */

extern int xdata i1;

/* int at xdata 0x8000 */

Соседние файлы в папке HLP