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

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

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


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

Excel如何直接用SQL语言进行数据查询

Excel如何直接用SQL语言进行数据查询

打开excel,点击数据选项卡,现有连接。 弹出的对话框,点击浏览更多按钮。 选择要打开的数据文件,点击打开。 点击选择需要具体调用的工作表,点击确定。 弹出的导入数据对话框,点击属性按钮。 弹出的连接属性对话框,选择定义选项卡。 在下方的命令文本框中输入需要的SQL查询语句,点击确定即...

cc254x:不能打开cc254x_ubl_pp.js

参考文献: http://www.deyisupport.com/question_answer/wireless_connectivity/bluetooth/f/103/t/77943.aspx  问题:不能打开cc254x_ubl_pp.js 解决办法: 1、某些情况下可以忽略这...

宏与子程序的区别

宏和子程序都是为了简化源程序的编写,提高程序的可维护性,但是它们二者之间存在着以下本质的区别:1、在源程序中,通过书写宏名来引用宏,而子程序是通过CALL指令来调用;2、汇编程序对宏通过宏扩展来加入其定义体,宏引用多少次,就相应扩展多少次,所以,引用宏不会缩短目标程序;而子程序代码在目标程序中只出现...

把存储过程结果集插入临时表

--使用sp_helpserver 显示可用的服务器。  exec sp_helpserver  --打开服务器的"data access"属性  exec sp_serveroption '服务器名',...

老单单据上下查,某些字段在上下查出来的界面看不到

https://vip.kingdee.com/questions/55600564193023233/answers/55600565182629120 问题描述: 例如:将外购入库上的【保管】字段显示在序时簿界面,但是在采购发票序时簿上查外购入库单的界面看不到【保管】,查询起来不方便。 解决方案...

光耦,大有用处

光耦,百度百科是这样说的:耦合器(optical coupler,英文缩写为OC)亦称光电隔离器,简称光耦,是开关电源电路中常用的器件。耦合器以光为媒介传输电信号。它对输入、输出电信号有良好的隔离作用,所以,它在各种电路中得到广泛的应用。目前它已成为种类最多、用途最广的光电器件之一。光耦合器一般由三...

发表评论

访客

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