如何增加 MPLAB 中存储块的大小?

发布于 2024-07-13 19:09:18 字数 321 浏览 5 评论 0原文

Microchip PIC MPLAB (MCC18) 编译器将其内存分段为 256 个块 (0x100)。

如何创建大于 256 字节的数组?

char buffer[256];

为了达到 256,我需要使用 #pragma 创建一个单独的段。

#pragma udata segment_name
char buffer[256];
#pragma udata

所以我可以强制 MCC18 让分配更大的缓冲区吗? 或者组合两个内存段?

The Microchip PIC MPLAB (MCC18) compiler segments its memory into 256 chunks ( 0x100 ).

How can I create an array larger than 256 bytes?

char buffer[256];

Just to get to 256 I needed to make a seperate segment with a #pragma

#pragma udata segment_name
char buffer[256];
#pragma udata

So I can either force MCC18 to let allocate a larger buffer? or combine two memory segments?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡看悲欢离合 2024-07-20 19:09:18

粘贴答案:

http://forum.microchip.com/printable.aspx?m= 39357

以防万一它消失。

三个简单步骤第 1 步:分配
变量到命名部分
源代码:

<前><代码>#pragma udata big_scn
字符大数组[0x180];
#pragma udata

第 2 步:在中创建更大的区域
链接描述文件:之前:

数据库名称=gpr3 开始=0x300 结束=0x3FF 
  数据库名称=gpr4 开始=0x400 结束=0x4FF 
  

之后:

数据库名称=big_scn START=0x300 END=0x47F 受保护 
  数据库名称=gpr4 开始=0x480 结束=0x4FF 
  节名称=big_scn RAM=big_scn 
  

第 3 步:仅通过
指针:

char *big_array_ptr = &big_array[0]; 
  big_array_ptr[0x100] = 5; 
  while( big_array_ptr[x] != 20 ) 
  

注意:我相信您仍然可以直接引用数组,而不是使用指针。 似乎对我有用。

您可以在以下文档中找到相同的信息:

MPLAB C18 C 编译器入门指南

第 104 页。

Pasting answer from:

http://forum.microchip.com/printable.aspx?m=39357

Just in case it goes away.

In Three Easy Steps Step 1: Assign the
variable into a named section in
source code:

#pragma udata big_scn
char big_array[0x180];
#pragma udata

Step 2: Create the larger region in
the linker script: Before:

DATABANK NAME=gpr3 START=0x300 END=0x3FF
DATABANK NAME=gpr4 START=0x400 END=0x4FF

After:

DATABANK NAME=big_scn START=0x300 END=0x47F PROTECTED
DATABANK NAME=gpr4    START=0x480 END=0x4FF
SECTION  NAME=big_scn RAM=big_scn

Step 3: Reference only through a
pointer:

char *big_array_ptr = &big_array[0];
big_array_ptr[0x100] = 5;
while( big_array_ptr[x] != 20 )

NOTE: I believe you can still reference the array directly instead of using a pointer. Seems to work for me.

The same information can be found in the following document:

MPLAB C18 C Compiler Getting Started Guide

Page 104.

無處可尋 2024-07-20 19:09:18

也许有更多知识的人会证明我错了,但我认为不可能做你想做的事。 如果你的设备中的内存被分成 256 字节的段,那么你就不能有一个跨越它们的数组,AFAIK。 如果你这样做,它必须跳过各种麻烦才能让你将数组视为连续内存 - 它必须检查你使用的每个索引以确定它应该位于哪个段,然后计算偏移量和访问或者如果您使用指针算术访问数组,它必须弄清楚您正在尝试访问的内容,这在编译时可能是不明显的甚至是未知的。 我不认为它有一个可以用于所有情况的单一内存模型,因为某些内存位置在银行之间是常见的(我认为程序计数器就是这样的位置之一),等等。了解典型的 PIC 架构以及使用第三方 C 编译器的一些经验。 我对 MPLAB 本身没有太多经验,所以对我的回答持保留态度。

您可以通过分配一个指针数组,然后将每个指针初始化为您想要存储在其中的任何数据类型的新实例来绕过限制(我假设是一个结构体或比指针更大的东西) ,因为这不需要内存是连续的。 然而,PIC 上的动态内存分配成本很高,因此这对您来说可能不是一个好的选择。

Perhaps someone with more knowledge will prove me wrong, but I don't think it's possible to do what you want. If the memory in your device is divided into segments of 256 bytes, then you can't have an array spanning them, AFAIK. If you did, it would have to jump through all sorts of hoops to let you treat the array as contiguous memory -- it would have to check each index you use to figure out which segment it should be in, then compute the offset and access it, or if you're accessing the array using pointer arithmetic, it must figure out what you're trying to access, which may be non-obvious or even unknown at compile time. I don't think it has a single memory model that it can use for all circumstances because of the way some memory locations are common across banks (I think the program counter is one such location), etc. I'm speaking largely from a knowledge of the typical PIC architecture and some experience with third-party C compilers. I don't have much experience with MPLAB itself, so take my answer with a grain of salt.

It may be possible for you to get around the restriction by allocating an array of pointers and then initializing each pointer to a new instance of whatever data type you want to store in it (I'm assuming a struct or something larger than a pointer), as this will not require the memory to be contiguous. Dynamic memory allocation on PICs is expensive, however, so this may not be a good option for you.

爱,才寂寞 2024-07-20 19:09:18

我有一个类似的问题!我打算使用这种方法: http://www .hobbytronics.co.uk/c18-large-data-arrays
但是当我添加链接器而不对项目进行任何更改并编译项目时,我收到此错误
// $Id: 18f2550.lkr,v 1.3 2005/03/24 04:17:19 craigfranklin Exp $
// 文件:18f2550.lkr
// PIC18F2550 处理器的示例链接器脚本

    LIBPATH .

    //CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
    CODEPAGE   NAME=page       START=0x0            END=0x6FFB
    CODEPAGE   NAME=boot       START=0x6FFC         END=0x7FFF         PROTECTED
    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=0x5F
    DATABANK   NAME=gpr0       START=0x60           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=usb4       START=0x400          END=0x4FF          PROTECTED
    DATABANK   NAME=usb5       START=0x500          END=0x5FF          PROTECTED
    DATABANK   NAME=usb6       START=0x600          END=0x6FF          PROTECTED
    DATABANK   NAME=usb7       START=0x700          END=0x7FF          PROTECTED
    ACCESSBANK NAME=accesssfr  START=0xF60          END=0xFFF          PROTECTED

    SECTION    NAME=CONFIG     ROM=config
    SECTION    NAME=bank1      RAM=gpr1
    SECTION    NAME=usbram4    RAM=usb4
    SECTION    NAME=usbram5    RAM=usb5
    SECTION    NAME=eeprom     ROM=eedata

错误:
18f2550.lkr:5:警告:(374)缺少基本类型; 假设整数
18f2550.lkr:5:错误:(314)“;” 预期的

什么?一切都是真的!
我正在使用 mplabx v 2.0 和 Mplab xc8 v 1.31

I have a similar problem!I was going to use this method: http://www.hobbytronics.co.uk/c18-large-data-arrays
But when I added linker without any change to the project and compile the project I got this error
// $Id: 18f2550.lkr,v 1.3 2005/03/24 04:17:19 craigfranklin Exp $
// File: 18f2550.lkr
// Sample linker script for the PIC18F2550 processor

    LIBPATH .

    //CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
    CODEPAGE   NAME=page       START=0x0            END=0x6FFB
    CODEPAGE   NAME=boot       START=0x6FFC         END=0x7FFF         PROTECTED
    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=0x5F
    DATABANK   NAME=gpr0       START=0x60           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=usb4       START=0x400          END=0x4FF          PROTECTED
    DATABANK   NAME=usb5       START=0x500          END=0x5FF          PROTECTED
    DATABANK   NAME=usb6       START=0x600          END=0x6FF          PROTECTED
    DATABANK   NAME=usb7       START=0x700          END=0x7FF          PROTECTED
    ACCESSBANK NAME=accesssfr  START=0xF60          END=0xFFF          PROTECTED

    SECTION    NAME=CONFIG     ROM=config
    SECTION    NAME=bank1      RAM=gpr1
    SECTION    NAME=usbram4    RAM=usb4
    SECTION    NAME=usbram5    RAM=usb5
    SECTION    NAME=eeprom     ROM=eedata

error:
18f2550.lkr:5: warning: (374) missing basic type; int assumed
18f2550.lkr:5: error: (314) ";" expected

whay?Everything is true!
I am using mplabx v 2.0 and Mplab xc8 v 1.31

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文