tdh03z的笔记 https://passport2.21ic.com/?301579 [收藏] [复制] [RSS]

日志

PIC18定义大数组的方法

热度 1已有 807 次阅读2015-2-27 20:58 |个人分类:PIC单片机|系统分类:单片机| PIC, MC18

 MCC18完全可以定义大数组,方法见 MCC18安装目录下的DOC目录下 MPLAB-C18-Getting-Started_51295f.PDF文件 第108页:

FAQ-10 How do I create a large object in data memory (> 256 bytes)?

By default, MPLAB C18 assumes that an object will not cross a bank boundary. The
following steps are required to safely use an object that is larger than 256 bytes:

1. The object must be allocated into its own section using the #pragma idata or
#pragma udata directive:
#pragma udata buffer_scn
static char buffer[0x180];
#pragma udata

2. Accesses to the object must be done via a pointer:
char * buf_ptr = &buffer[0];
...
// examples of use
buf_ptr[5] = 10;
if (buf_ptr[275] > 127)
...

3. A region that spans multiple banks must be created in the linker script:
- Linker script before modification:
DATABANK NAME=gpr2 START=0x200 END=0x2FF
DATABANK NAME=gpr3 START=0x300 END=0x3FF
- Linker script after modification:
DATABANK NAME=big START=0x200 END=0x37F PROTECTED
DATABANK NAME=gpr3 START=0x380 END=0x3FF

4. The object’s section (created in Step 1) must be assigned into the new region
(created in Step 3) by adding a SECTION directive to the linker script:
SECTION NAME=buffer_scn RAM=big


我测试成功,定义一个:
/*
 * Step #1  The data is allocated into its own section.
 */
#pragma udata bigdata
     char    rLcdBuffer[32][20];  //液晶显示缓冲区 32*160
#pragma udata

修改LKR文件:
// Step #3  Create a new region in the linker script
// This is the databank that will contain the large memory object
DATABANK   NAME=largebank  START=0x300             END=0x5FF          PROTECTED
//DATABANK   NAME=gpr3       START=0x300             END=0x3FF
//DATABANK   NAME=gpr4       START=0x400             END=0x4FF
//DATABANK   NAME=gpr5       START=0x500             END=0x5FF

DATABANK   NAME=gpr6       START=0x600             END=0x6FF


// Step #4 - Assign the large memory object's section into the new region
SECTION    NAME=bigdata    RAM=largebank

//===============================================================================================================
默认情况下, MPLAB C18 假设对象不超过存储区边界。要安全使用大于256 字节的

对象,需要执行下列步骤:

1. 必须使用#pragma idata 或#pragma udata 伪指令将对象分配到恰当的段中:

#pragma udata buffer_scn

static char buffer[0x180];

#pragma udata

2. 必须通过指针访问对象:

char * buf_ptr = &buffer[0];

...

// examples of use

buf_ptr[5] = 10;

if (buf_ptr[275] > 127)

...

3. 必须在链接描述文件中创建一个跨越多个存储区的区域:

- 修改前的链接描述文件:

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

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

- 修改后的链接描述文件:

DATABANK NAME=big START=0x200 END=0x37F PROTECTED

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

4. 必须通过在链接描述文件中添加SECTION 伪指令,将对象所在的段(在第1 步中创建)分配到新的区域(在第3 步中创建):

SECTION NAME=buffer_scn RAM=big

路过

鸡蛋
1

鲜花

握手

雷人

刚表态过的朋友 (1 人)

评论 (0 个评论)