如何增加 MPLAB 中存储块的大小?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
粘贴答案:
http://forum.microchip.com/printable.aspx?m= 39357
以防万一它消失。
注意:我相信您仍然可以直接引用数组,而不是使用指针。 似乎对我有用。
您可以在以下文档中找到相同的信息:
MPLAB C18 C 编译器入门指南
第 104 页。
Pasting answer from:
http://forum.microchip.com/printable.aspx?m=39357
Just in case it goes away.
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.
也许有更多知识的人会证明我错了,但我认为不可能做你想做的事。 如果你的设备中的内存被分成 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.
我有一个类似的问题!我打算使用这种方法: 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 处理器的示例链接器脚本
错误:
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
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