我正在尝试在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.
答案 0 :(得分:0)
弄清楚了-这是因为我只在编译器阶段而不是在链接器阶段传递了MCU类型。