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

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

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


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://xjtudll.cn/Exp/465/

标签: keil51
分享给朋友:

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

Android error:Duplicate ID, tag null, or parent id with another fragment(fragment嵌套问题)

参考资料:http://stackoverflow.com/questions/14083950/duplicate-id-tag-null-or-parent-id-with-another-fragment-for-com-google-androi 跟参考资料里的这个人一样,我也碰到了这个...

Office 2003正版验证破解方法

唉,公司电脑自动更新后,突然提示我Office是盗版,于是每次打开office文件,都会提示盗版,任务栏也有个图标。在网上搜索了一下,找到了解决办法。操作如下:运行:regedit命令,打开注册表删除注册表[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\1...

金蝶K3单据编码规则扩展方法解密

金蝶K3单据编码规则扩展方法解密

https://baijiahao.baidu.com/s?id=1603718041512798752&wfr=spider&for=pc 在实施客户过程中,客户对单据编码规则提了一些简单的需求: 需求一:内贸订单和外贸订单希望能够通过前缀编码来区分。 需求二:系统订单编码规则为&...

Keil新增STC 51型号

Keil新增STC 51型号

STC官网提供的方法: (详见:http://www.mcu-memory.com/) 备份KEIL安装目录下的UV2.CDB或者UV3.CDB文件(在文件夹UV2或者UV3里面),然后用STC提供的同名的CDB文件覆盖。 这种方法操作起来很简单,但缺点是在器件选型时,只能选择STC单片机,其他的都...

Keil得到C编译之后的汇编代码

Keil得到C编译之后的汇编代码

在Options for Target --> Listing标签页下 在C Compiler Listing: \*.lst部分中勾选Assembly Code,这样生成的LST文件中就会包含汇编源码了。 找到相应的lst文件,如图所示: 用记事本打开,里面就有汇编代码了...

CC2541  HOGP Android 5.x无法自动回连

CC2541 HOGP Android 5.x无法自动回连

参考资料: https://e2e.ti.com/support/wireless_connectivity/bluetooth_low_energy/f/538/t/406142 问题: 使用CC254x做BLE键盘,利用HOGP(HID Over Gatt Profile),成功实现了键盘的功能...

发表评论

访客

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