wangfriend 发表于 2012-11-10 20:57:54

请教:WinAVR怎么把使用的内存释放掉?

大家好,我在用M32驱动一块RA8835的屏,M32内存2K.屏在启动时输出的静态图形占了大部分的单片机内存,这些显示内容在启动一次后,不再更改。我想这里的内存应该可以释放掉干其它用了。
我原来基本用汇编语言写程序,C不态精通。 请大家指点一下。谢谢。

hell-prototypes 发表于 2012-11-10 21:11:49

本帖最后由 hell-prototypes 于 2012-11-10 23:07 编辑

是不是没有把图形数据定义到FLASH里去:

How do I put an array of strings completely in ROM?

There are times when you may need an array of strings which will never be modified.
In this case, you don't want to waste ram storing the constant strings.

The most obvious (and incorrect) thing to do is this:

//改贴正确的:
#include <avr/pgmspace.h>

const char foo[] PROGMEM = "Foo";
const char bar[] PROGMEM = "Bar";

PGM_P array PROGMEM = {
    foo,
    bar
};

int main (void)
{
    char buf;
    PGM_P p;
    int i;

    memcpy_P(&p, &array, sizeof(PGM_P));
    strcpy_P(buf, p);
    return 0;
}

多谢楼下指正,没认真看清楚就给贴出来了,误人子弟啊。。。不好意思。。改过来了

jimmy_xt 发表于 2012-11-10 21:15:29

hell-prototypes 发表于 2012-11-10 21:11 static/image/common/back.gif
是不是没有把图形数据定义到FLASH里去:

How do I put an array of strings completely in ROM?


哥们,你把错误的例子贴上来干嘛……
仔细看看这个例子下面的一行字
The result is not what you want though. What you end up with is the array stored in ROM, while the individual strings end up in RAM (in the .data section).

jimmy_xt 发表于 2012-11-10 21:16:01

#include <avr/pgmspace.h>

const char foo[] PROGMEM = "Foo";
const char bar[] PROGMEM = "Bar";

PGM_P array PROGMEM = {
    foo,
    bar
};

int main (void)
{
    char buf;
    PGM_P p;
    int i;

    memcpy_P(&p, &array, sizeof(PGM_P));
    strcpy_P(buf, p);
    return 0;
}

jimmy_xt 发表于 2012-11-10 21:18:17

另,这段代码的来源是avr-libc-user-manual

hell-prototypes 发表于 2012-11-10 23:09:31

可以在:x:/WinAVR-20100110/doc/avr-libc/avr-libc-user-manual/FAQ.html#faq_rom_array
里找到全部的FAQ内容

wangfriend 发表于 2012-11-12 11:46:38

我试试。 maga16 满了,再成mega32又折腾的了几天又快满了。看要按楼上介绍的办法处理一下了。
记得四年前用maga88驱动3310的屏 图片直接从flash读出来的。只用到一些暂存器,不需要分配固定的SRAM。
页: [1]
查看完整版本: 请教:WinAVR怎么把使用的内存释放掉?