编译下列代码时:
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void) {
DDRC = 255;
while(1){
PORTC=255;
_delay_ms(200);
PORTC=0;
_delay_ms(200);
}
return 0;
}对于ATMega16是可以的:
avr-gcc -w -Os -DF_CPU=1000000UL -mmcu=atmega16 -c -o main.o main.c但是,对于ATMega164PA,我得到以下错误:
avr-gcc -w -Os -DF_CPU=1000000UL -mmcu=atmega164pa -c -o main.o main.c错误:
DDRC未声明(在此函数中首次使用) DDRC=255; ^ 错误:PORTC未声明(在此函数中首次使用) PORTC=255; ^
atmega164p甚至没问题,但atmega164pa不行。
发布于 2015-05-31 09:09:01
这个问题似乎是由于在文件io.h中没有针对MCU类型的__AVR_ATmega164PA__的特定文件包含;只有:__AVR_ATmega164P__和__AVR_ATmega164A__。我认为164 has的代码必须编译为164 p。
这是文件io.h中代码的一部分。
#elif defined (__AVR_ATmega163__)
# include <avr/iom163.h>
//------------------------------------------------------------ To note
#elif defined (__AVR_ATmega164P__) || defined (__AVR_ATmega164A__)
# include <avr/iom164.h>
//--------------------------------------------------------------------
#elif defined (__AVR_ATmega165__) || defined (__AVR_ATmega165A__)
# include <avr/iom165.h>如果看到编译器输出,可能会注意到更多警告:
In file included from avr164.c:3:0:
--------------------------------------------> To note
/usr/lib/avr/include/avr/io.h:428:6: warning: #warning "device type not defined" [-Wcpp]
# warning "device type not defined"
^
To note <---------------------------------------------
avr164.c: In function ‘main’:
avr164.c:8:1: error: ‘DDRC’ undeclared (first use in this function)
DDRC = 255;
^
avr164.c:8:1: note: each undeclared identifier is reported only once for each function it appears in
avr164.c:28:1: error: ‘PORTC’ undeclared (first use in this function)
PORTC=255;
^第一个警告:io.h:428:6: warning: #warning "device type not defined"表示预处理器已经解析了io.h文件,直到发出警告的行。
在文件io.h的以下行中,您可能会看到发出警告的位置。
#elif defined (__AVR_M3000__)
# include <avr/iom3000.h>
#else // <<<---------------------- To note!
// To note -------------------------------
# if !defined(__COMPILING_AVR_LIBC__)
# warning "device type not defined"
# endif
// To note -------------------------------
#endif发出的警告指示您可能没有指定目标的库(“幸运”用于调试,也表示感兴趣部分的结束)。
如果您试图在不管理PORTC和DDRC的情况下编译SW (注释它们的使用),您应该会得到如下结果:
In file included from avr164.c:3:0:
/usr/lib/avr/include/avr/io.h:428:6: warning: #warning "device type not defined" [-Wcpp]
# warning "device type not defined"
^
---------------------------> Note
/usr/lib/gcc/avr/4.8.2/../../../avr/bin/ld: cannot find crtm164pa.o: No such file or directory
collect2: error: ld returned 1 exit status
Note <---------------------------结果表明链接器环境中没有crtm164pa.o文件。(这是另一个问题!)
我用过: avr-gcc (GCC) 4.8.2
https://stackoverflow.com/questions/30525866
复制相似问题