0

我正在尝试在 Atmega328p 上创建一个简单的程序。当我只包含主要功能时,它可以正常工作,但是添加另一个功能(即使没有调用它)会导致微控制器冻结(灯根本不闪烁)。

我已将其缩小为仅添加一个空函数。下面冻结 - 通过简单地注释掉它工作正常的功能(灯闪烁)。

#include <util/delay.h>
#include <avr/io.h>

int main(void){
    DDRB |= (1 << 5);
    PORTB |= (1 << 5);
    while(1){
        PORTB ^= (1 << 5);
        _delay_ms(500);
    }

return 0;
}

void Somerandomcrap(char data){

}

$ avr-gcc -mmcu=atmega328p -Os -Wall -DF_CPU=16000000 -I inc/   -c -o src/main.o src/main.c
$ avr-gcc -o main.elf src/main.o
$ avr-objcopy -O ihex main.elf main.hex
$ avrdude -c usbtiny -p atmega328p -U flash:w:main.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "main.hex"
avrdude: input file main.hex auto detected as Intel Hex
avrdude: writing flash (80 bytes):

Writing | ################################################## | 100% 0.16s

avrdude: 80 bytes of flash written
avrdude: verifying flash memory against main.hex:
avrdude: load data flash data from input file main.hex:
avrdude: input file main.hex auto detected as Intel Hex
avrdude: input file main.hex contains 80 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.09s

avrdude: verifying ...
avrdude: 80 bytes of flash verified

avrdude: safemode: Fuses OK (E:FD, H:DE, L:FF)

avrdude done.  Thank you.

4

1 回答 1

0

想通了 - 这是因为我只在编译器阶段传递了 MCU 类型,而不是在链接器阶段。

于 2019-03-26T04:09:10.537 回答