博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
KEIL C51中的_at_ 关键字
阅读量:5503 次
发布时间:2019-06-16

本文共 2931 字,大约阅读时间需要 9 分钟。

 

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

“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

3

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; /* list at idata 0x40 */

char xdata text[256] _at_ 0xE000; /* array at xdata 0xE000 */

int xdata i1 _at_ 0x8000; /* int at xdata 0x8000 */

void main ( void ) {

link.next = (void *) 0;

i1 = 0x1234;

text [0] = 'a';

}

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 */

 

The _at_ Keyword

The third method of accessing absolute memory locations is to use the _at_

keyword when you declare variables in your C source files. 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; /* list at idata 0x40 */

char xdata text[256] _at_ 0xE000; /* array at xdata 0xE000 */

int xdata i1 _at_ 0x8000; /* int at xdata 0x8000 */

void main ( void ) {

link.next = (void *) 0;

i1 = 0x1234;

text [0] = 'a';

}

Refer to “Absolute Variable Location” on page 104 for more information about

the _at_ keyword.

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.

转载于:https://www.cnblogs.com/nsoft/archive/2012/06/25/2562683.html

你可能感兴趣的文章
订阅linux kernel的mail list
查看>>
mysql 批量更新多条记录(且不同值)的实现方法
查看>>
Hadoop上路_02-hadoop介绍和环境准备
查看>>
JFinal多参数搜索条件自动组装及参数传递
查看>>
Lua与ObjC的交互
查看>>
c++ ios_base register_callback方法使用
查看>>
Java中为什么需要Object类,Object类为什么是所有类的父类
查看>>
数据库答案拼接,前台调用
查看>>
在Hadoop-1.2.1中跑著名的wordcount例程
查看>>
css3 -webkit-flex 布局
查看>>
大数据Benchmark
查看>>
windows server2008多用户远程登陆设置方法
查看>>
sencha touch巧妙使用请求超时提升用户体验
查看>>
15. 3Sum
查看>>
26. Remove Duplicates from Sorted Array
查看>>
在使用AngularJS的过程中了解Promise(二)
查看>>
ArrayList源码解析
查看>>
基于SpringMVC、Maven以及Mybatis的环境搭建
查看>>
Java中的小数是怎么存储的?(转载学习)
查看>>
SpringBoot笔记2——项目属性配置详解
查看>>