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

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

xjtudll8年前 (2017-08-05)技术心得9720


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

C# WinForm带参数运行 如:1.exe -a

建立好了项目文件后,需要修改的地方有两点! 1:修改 Program 类中的Main方法 加上入口点,并且将参数传递到Form1窗体 2:修改 Form1窗体的构造函数,允许传参。 下面是代码: Program.cs代码如下: namespace ParameterApp {   ...

NSTextfield只允许输入数字

.wiz-todo, .wiz-todo-img {width: 16px; height: 16px; cursor: default; padding: 0 10px 0 2px; vertical-align: -10%;-webkit-user-select: none;} .wiz-t...

IAR如何生成Hex文件

IAR如何生成Hex文件

MSP430在用JTAG下载的时候,Hex文件是用不上的。但是如果用Proteus仿真的话(只有Proteus 7.6及其以上版本才支持MSP430仿真),只支持Hex文件仿真,所以有必要输出Hex文件。 打开IAR的工程选项,选中左边栏的Linker,如图所示。 勾中【Output file】...

Multisim运放输出超过电源电压解决

Multisim运放输出超过电源电压解决

在使用Multisim自带库里的运放的时候,例如LM324M,发现一个问题,运放的输出电压能达到几百V甚至几千V,而电源明显只有几V而已。输出电压超过电源电压,理论上是不可能的,实际上也是不可能的,那么肯定就是仿真有误了,其实根本原因是Multisim里面运放是三脚模型,根本没考虑电源。我们查看LM...

Word批量删除图片、超链接、空格等技巧

Word中的很多批量处理,实际上多是通过查找、替换功能实现的。而要调出“查找和替换面板”很简单,在“工具”菜单中选择“替换”或者按ctrl+H快捷键即可。下文中提到的“查找”或“替换&rdqu...

Android:open failed: EACCES (Permission denied) -

参考资料:http://blog.csdn.net/zxkevin1989/article/details/7464550/ 问题: 从SD卡中读取文件,提示open failed: EACCES (Permission denied) - 原因: 从提示基本就能看出是权限问题了,读取SD卡文件需要...

发表评论

访客

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