当前位置:首页 > 技术心得 > 正文内容

C51: LOCATING INITIALIZED VARIABLES AT ABSOLUTE ADDRESSES 如何初始化绝对定址的变量

xjtudll9年前 (2017-08-05)技术心得13130


http://www.keil.com/support/docs/301.htm

QUESTION 问题描述

I want to locate some initialized constants and variables in memory, but I can't initialize and locate them with the _at_ keyword. What's wrong?

我想初始化一些常量和变量,但我无法初始化成功当我使用_at_绝对定址后。

ANSWER 答案

C51 does not allow you to both locate a variable using the _at_ keyword and initialize it. You may use the linker to locate the variable.

Keil C51常量或变量使用_at_关键词绝对定址后,将无法直接初始化。但是可以先初始化变量,然后通过编译器设置绝对定址。

For example, if you want to locate an initialized constant array into code space...

举例如下:

  1. Declare your array as follows: 首先在C文件里申明并初始化变量
    char const code My_Array[] = {   1,2,3,4,5 };
  2. Go to your linker map file a see what the segment name is for this array. Note that during this process you will probably get a warning about an unused function or something similar. This is because the compiler is expecting your array to be a function since you specified that it is in code space. Don't worry about this warning.
    查看Map文件,寻找数组的segment的名字。
    如果程序中没有用到数组,可能会有warning提示。
    69da49f9-cc42-43ab-a368-fb6f0e5e64b8

    这个警告可以忽略。我们需要知道的是segment的名字。
    例如Map文件:
    98b00312-5d51-453d-8293-0354616e5978

    C文件名称是Temp.c,所以其segment名字是“ ?CO?TEMP”

  3. Use the BL51 CODE directive or the LX51 SEGMENTS directive to specify the location of the constant segment. If the C source file name is TEMP.C the constant segment is named ?CO?TEMP. The entry ?CO?TEMP(0x5000) in the linker directive locates the segment to absolute memory address 5000h.
    如果是BL51,填入: ?CO?TEMP(0x5000)。如下图所示,0x5000表示地址。
    8e0dea59-f6b8-4365-893c-d334d1eaf8ce

    如果是LX51,填入?CO?TEMP(C:0x5000) 不要搞错了,与BL51是不同的。
    8c9383d9-5551-44e5-bf0c-2d70d41fdaf2

If you use µVision2 and BL51 enter ?CO?TEMP(0x5000) under Options for Target - BL51 Locate - Code:. For LX51, enter ?CO?TEMP(C:0x5000) under Options for Target - LX51 Locate - User Segments.

设置完后,重新编译,查看Map文件,我们就会发现temp.c被定址到了0x5000。

eab1e583-a19d-4064-a2db-3103c8cf1d98

这个方法有个很大的缺点,就是只能定址segment,由于文件名先天性就是一个segment,所以将数组单独放在一个c文件里,间接实现了数组的绝对定址。

SEE ALSO


扫描二维码推送至手机访问。

版权声明:本文由鸟的天空发布,如需转载请注明出处。

本文链接:http://www.xjtudll.cn/Exp/465/

标签: keil51
分享给朋友:

“C51: LOCATING INITIALIZED VARIABLES AT ABSOLUTE ADDRESSES 如何初始化绝对定址的变量” 的相关文章

QQ for Mac老提示密码错误

这段时间,一直在折腾黑苹果,好不容易将黑苹果装的差不多了,下了个QQ for Mac,安装什么的都很顺利,但是就是死活登陆不上。 1、检查过大小写,确认过密码,没错。在Windows下可以使用;在Mac系统中,Web QQ也可使用。 2、采用复制粘贴的方法将密码粘贴到密码框,依旧提示密码错误。...

VSPD + Keil 实现串口的仿真调试

VSPD + Keil 实现串口的仿真调试

VSPD顾名思义就是在本本上虚拟串口,实际上这个软件做的就是虚拟出一对已经互联的串口。 上面就是虚拟出来了com3和com4,而且已经交叉(默认)连接了,这样相当于本本的com3、com4在外面已经连好了,下面要做的就是在内部分别赋予com3和com4所属终端了。 com4—&mda...

检测NSWindow关闭

You can declare your custom class to conform to NSWindowDelegate protocol. Set an instance of your custom class to be the delegate of your wind...

Android Studio升级至3.1出现AAPT2 error的解决办法

Android Studio升级至3.1出现AAPT2 error的解决办法

android studio从2.3升级到3.1.3之后,编译提示:AAPT2 error: check logs for details 网上的方法一堆,但几乎都没啥用。以下部分内容引用简书: https://www.jianshu.com/p/2a63c5710ee9 1:Android Stu...

win7怎样彻底删除打印机驱动

win7怎样彻底删除打印机驱动

https://zhidao.baidu.com/question/1802002455667765027.html 1、开始---设备和打印机:随便选择一个打印机图标,选择打印机服务器属性; 2、单击打印服务器属性---驱动程序---删除,选择删除驱动程序和驱动程序包,点确定; 3、无法删除...

Storyboard已关联下面的TableView,为什么TabView的Cell显示不出来

问题: Storyboard已关联下面的TableView,为什么TabView的Cell显示不出来 原因及解决办法: 很简单,你的代码没有设置,SB里面的TableViewController要关联一个类,你需要添加好,并且注意下面这两个代理方法的返回值 - (NSInteger)numberO...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。