Chinaunix首页 | 论坛 | 博客
  • 博客访问: 172994
  • 博文数量: 40
  • 博客积分: 1573
  • 博客等级: 上尉
  • 技术积分: 385
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-09 22:50
个人简介

忙得不会思考了!!!!!!

文章分类

全部博文(40)

文章存档

2015年(2)

2014年(1)

2011年(15)

2010年(3)

2009年(19)

我的朋友

分类: 嵌入式

2011-03-22 11:33:46

链接脚本的使用极大方便了开发人员控制代码的存储位置和存储空间,以下是从文档中摘取的链接脚本典型案例,供参考。

MPLAB-C18-Getting-Started_51295f.pdf

6.5 SECTIONS

As described above, sections are the various areas in PIC18XXXX memory, including program memory, file register (data) memory, EEDATA nonvolatile memory and data stack memory, among others.

Usually sections are needed for program memory and data memory. As the design becomes more sophisticated, other section types may be required.

Sections are defined in the linker scripts. Here is the linker script for the PIC18F452:

EXAMPLE 6-1: PIC18F452 SAMPLE LINKER SCRIPT

This linker script defines the main program memory with the name page extending from address 0x002A to 0x7FFF. When a #pragma code directive is encountered, the compiler will generate machine code instructions to be placed in this area.

在代码中使用了# pragma code segm1c = 0xXXXX,即指定了这个位置之后的代码在代码段中的位置,同时注意在链接脚本中给这段代码分配合适的空间。

Data memory is defined for the six file register banks (gpr = General Purpose Register bank) of the PIC18F452. Due to the nature of banked memory on the PIC18XXXX, these six regions are defined as separate sections. When #pragma udata and

#pragma idata directives are encountered, the compiler will reserve areas in these file register banks for storage of the variables subsequently defined.

The accessram and accesssfr sections define the Access RAM areas in data memory.

Note that some areas are marked “PROTECTED”. This means that the linker will not put code or data into those areas unless specifically directed. To put code or data into a protected area, use the #pragma directive as shown here:

链接脚本中的"protected"意味着如果你要在这个区域放置代码,你必须先在要放置的代码前面添加#pragma这个预处理指令。

#pragma code page

This will cause the subsequent instructions to be compiled in the page section, usually the main program memory area as defined in the linker script.

// Sample linker script for the PIC18F452 processor

LIBPATH .

FILES c018i.o

FILES clib.lib

FILES p18f452.lib // 不同型号的MCU这里更换为相应的库。

CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED

CODEPAGE NAME=page START=0x2A END=0x7FFF

CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED

CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED

CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED

CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED

ACCESSBANK NAME=accessram START=0x0 END=0x7F

DATABANK NAME=gpr0 START=0x80 END=0xFF

DATABANK NAME=gpr1 START=0x100 END=0x1FF

DATABANK NAME=gpr2 START=0x200 END=0x2FF

DATABANK NAME=gpr3 START=0x300 END=0x3FF

DATABANK NAME=gpr4 START=0x400 END=0x4FF

DATABANK NAME=gpr5 START=0x500 END=0x5FF

ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED

SECTION NAME=CONFIG ROM=config

阅读(2427) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~