打印
[AVR单片机]

怎么用ICCAVR把一串字符串写到固定flash地址?

[复制链接]
4455|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
yzjgod|  楼主 | 2012-7-23 14:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
yzjgod|  楼主 | 2012-7-23 16:02 | 只看该作者
没有人吗,哎,自己解决了,方法见下

#pragma abs_address:0x7F0
char var1[] = "abcdefg";
#pragma end_abs_address
说明书上的一些其他用法
The compiler generates code and data into different "areas." See Assembler Directives. The areas used by the compiler, ordered here by increasing memory address, are:
Read-Only Memory
vectors - this area contains the interrupt vectors.
func_lit - function table area. Each word in this area contains the address of a function entry or a label for the switch table. To be fully compatible with the Code Compressor (tm), all indirect function references must be through an extra level of indirection. This is done automatically for you in C if you invoke a function by using a function pointer. In assembly, the following example illustrates:
; assume _foo is the name of the function
.area func_lit
PL_foo:: .word _foo        ; create a function table entry
.area text
call PL_foo
efunc_lit - extended function table area. This serves the same function as func_lit except that each entry is a 3 byte function address. This is only needed for the ATMega256x devices.
idata - the initial values for the global data and strings are stored in this area and copied to the data area at startup time.
lit - this area contains integer and floating-point constants, etc.
text - this area contains program code.
Data Memory
data - this is the data area containing initialized global and static variables, and strings. The initial values of the global variables and strings are stored in the idata area and copied to the data area at startup time.
bss - this is the data area containing C global variables without explicit initialization. Per ANSI C definition, these variables get initialized to zero at startup time.
noinit - you use #pragma data:noinit to put global variables that you do not want any initialization. For example:
#pragma data:noinit
int junk;
#pragma data:data
EEPROM Memory
eeprom - this area contains the EEPROM data. EEPROM data is written to <output file>.eep as an Intel HEX file regardless of the output file format.

The job of the linker is to collect areas of the same types from all the input object files and concatenate them together in the output file. See Linker Operations.
User Defined Memory Regions

In most cases, you do not need to specify the exact location of a particular data item. For example, if you have a global variable, it will be allocated somewhere in the data area, and you do not need to specify its location.

However, there are occasions where you want to specify the exact location for a data item or a group of data:
battery-backed SRAM, dual-port SRAM, etc. - sometimes it is necessary to allocate some items in special RAM regions.

There are two ways to handle this.
relocatable area - in an assembly module, you can create a new program area and then you can specify its starting address under the Advanced->Other Options edit box in Compiler Options: Target. For example, in an assembly file:
.area battery_sram
_var1:: .blkw 1                                ; note _ in the front
_var2:: .blkb 1                                ; and two colons

In C, these variables can be declared as:
extern int var1;
extern char var2;

Let's say the battery-backed SRAM starts at 0x4000. In the Advanced=>Other Options edit box, you write:
-bbattery_sram:0x4000

Please refer to the Compiler Options: Target page for full description of address specifier.
absolute area - you can also define program areas that have absolute starting addresses, eliminating the need to specify the address to the linker. For example, using the same example as before, you can write the following in an assembly file:
.area battery_sram(abs)
.org 0x4000
_var1:: .blkw 1                                ; note _ in the front
_var2:: .blkb 1                                ; and two colons

The (abs) attribute tells the assembler that the area does not need relocation and it is valid to use the .org directive in the area. In this example, we use .org to set the starting address. In C the declaration will be exactly the same as before.

If you have data that have initialized values, then you can also use the following pragma in C to define them (note this only works with data that have initialized values):
#pragma abs_address:0x4000
int var1 = 5;
char var2 = 0;
#pragma end_abs_address

使用特权

评论回复
板凳
yzjgod|  楼主 | 2012-7-24 08:41 | 只看该作者
二姨家死水一潭

使用特权

评论回复
地板
yzjgod|  楼主 | 2012-9-3 15:04 | 只看该作者
谁回一个,我要结贴了

使用特权

评论回复
5
efen| | 2012-9-3 15:25 | 只看该作者
嘻嘻,我来:lol
顺便问一下,LZ的说明书哪来的

使用特权

评论回复
6
yzjgod|  楼主 | 2012-9-3 15:30 | 只看该作者
5# efen 就是help文件啊

使用特权

评论回复
7
johnrita| | 2016-3-2 17:28 | 只看该作者
有用,顶贴!!

使用特权

评论回复
8
avrgb| | 2016-3-17 16:55 | 只看该作者
能回答下我定义指针数组老出现初始化错误的问题么

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

239

主题

370

帖子

2

粉丝