1

我是atmega8的新手。我将一些旧的 freesacle 代码转换为 atmega8。但似乎我的芯片不能容纳超过 2400 字节的代码?下面是结果,当代码为 2412 字节时……一切都变得一团糟。

avrdude 下面的代码来自“cat /dev/ttyUSB0”。我的调试信息。

avrdude: verifying ...
avrdude: 2412 bytes of flash verified
avrdude: safemode: Fuses OK
avrdude done.  Thank you.

55432111001-0000 6Gn�H(�h�X0443234554321190 6Gn�H        (�h�X0443234554321100-FD-90-6F55432111001-0000 6Gn�H    (�h�X0443234554321190 6Gn�H(�h�X0443234554321100-FD-90-6F^C

但是如果我减少了代码(只有音频数据),我得到了正确的结果。

avrdude: verifying ...
avrdude: 2312 bytes of flash verified
avrdude: safemode: Fuses OK
avrdude done.  Thank you.

AVR-IrDA-Tone-Audio start.
version 1.2
--IrDA--    Bin: 1001-0000      Hex: 90     Complete Hex: 00-FD-90-6F

所有 hfuse、lfuse、lock 位都是原始值。我的代码可能是 6k,带有一些音频数据。

如果是由于引导闪存部分?

补充:------------------------------------------------ --------------------------------------------------

我现在把水晶换成8M。

● ll h8-*
-rw-rw-r-- 1 eexp eexp 933  9月 22 00:27 h8-reduce.c
-rw-rw-r-- 1 eexp eexp 14K  9月 22 00:26 h8-org.c

● cp h8-org.c h8.c

● avr.sh main.c
......
avrdude: 5272 bytes of flash verified

现在一切都变得一团糟。

● cp h8-reduce.c h8.c

● avr.sh main.c
.....
avrdude: 1872 bytes of flash verified

现在一切正常,但我几乎丢失了所有音频数据。

下面是h8.c。

● head h8.c
const unsigned char h8[] =
{
    36,14,0,0,129,129,128,129,130,127,126,128,128,127,128,130,131,128,127,127,127,126,127,129,130,130,129,129,128,128,128,128,128,126,126,129,128,127,127,130,133,130,126,126,129,128,125,127,128,129,128,127,129,128,127,127,127,128,128,129,127,127,129,128,130,130,128,128,127,126,128,128,128,130,129,128,129,126,126,125,127,132,130,127,126,129,131,127,127,133,133,127,122,125,129,130,127,127,130,129,
    126,125,127,128,129,128,128,128,128,127,127,129,128,129,129,128,126,127,129,127,128,127,128,130,129,129,128,128,127,127,129,130,128,128,129,129,127,127,128,128,128,128,128,128,126,126,129,129,127,129,130,130,126,126,128,128,127,128,131,130,127,126,126,128,129,125,128,130,131,128,126,129,128,129,125,126,130,129,131,130,131,129,125,128,129,131,130,127,130,129,127,128,127,129,128,126,126,127,128,126,
    127,127,128,128,128,127,127,127,127,127,129,128,129,128,128,129,129,128,128,129,128,128,128,129,0xff,
};
4

1 回答 1

1

我猜你正在将音频数据加载到内存中。变量声明,如

  char* data = "somerandomdata"; 

将所有数据放入 SRAM 中,而 mega8 中只有 1kbyte 的 SRAM(其中还包含堆栈等)。

如果锁定位处于其原始状态,则引导加载程序机制不应导致此错误。

您应该将音频数据指定为程序空间,以下是说明如何:

Avr LibC PGM 空间

这是您的代码的外观:h4.c

       #include <avr/pgmspace.h>

       const unsigned char h4[] PROGMEM = { 18,7,0,0,128,128,128,127,127,129,129,127,126,128,130,129,128,129,127,127,128,12‌​8,132,127,129,126,128,128,127,127,127,129,127,127,130,129,127,127,129,130,129,125‌​,

您需要调整您的 set_audio 函数,每次读取指针 h4 都应以这种方式完成:例如更改

  value = *h4_copy++;

  value = pgm_read_byte(h4_copy); h4_copy++;    
于 2012-09-21T07:10:34.670 回答