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

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

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


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 如何初始化绝对定址的变量” 的相关文章

Altium在生成PCB时,怎样取消掉room空间?

Altium在生成PCB时,怎样取消掉room空间?

从原理图生成PCB时 总会生成一个或多个网络区域 该区域ROOM在一般的情况下没有什么作用 反而会对我们的设计会带来一些不便 那怎么样才能取消此区域(room空间)呢! 方法一 在导入到pcb中时 我们执行变更的 选项栏中将room的选项的勾去掉 这样导入pcb时就不会把room导入了 方法二...

sql查询存储过程的修改记录和时间

–查询建立时间–表select * from sysobjects where id=object_id(N’表名’) and xtype=‘U’–表的结构select * from syscolumns where id=object_id(N’表名’)–存储过程select * from sys...

LCD基本常识

1、LCD的玻璃厚度有1.1mm、0.7mm、0.55mm和0.4mm,成品总厚度分别为2.8mm、2.0mm、1.7mm和1.4mm,如果是FSTN产品,那么总厚度需要再增加0.1mm。 2、LCD的视角范围,STN产品视角范围最大,HTN产品次之,TN产品视角范围最小。对于多路产品,如果路数大于...

Word中如何定位

Word中如何定位

文章来源:http://cuiyingfeng.blog.51cto.com/43841/61155 大家在日常工作中经常会接触word文档,在使用编辑时基本上会遇到如下两个问题: 1、我从目录中选择一个条目,跳入正文,现在想返回目录重新选择条目 2、我修改了一个地方,在浏览了这篇文档一部分内...

Xcode ios模拟器下载及安装教程

Xcode ios模拟器下载及安装教程

1 通过Xcode下载 最新版的Xcode安装后,通常只带最新ios系统的模拟器。例如,Xcode 5.01就只带了ios7.03的模拟器。通过Xcode可以下载早期版本的模拟器。 Xcode->Preferences->Downloads Downloads下的Components就...

群晖Apache 忽略文件名大小写

群晖Apache 忽略文件名大小写

参考资料:https://www.cnblogs.com/shipment/p/14767848.html 1、SSH登录群晖ssh  admin@201.201.201.1682、修改conf文件权限为777sudo chmod 777 /volume1/@appstore/Apache...

发表评论

访客

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