2015-05-29 81 views
0

當編譯如下代碼:AVR-GCC atmega164pa錯誤端口未申報

#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 

error: DDRC undeclared (first use in this function)

DDRC=255;

^

error: PORTC undeclared (first use in this function)

PORTC=255;

^

它甚至與atmega164p但不是atmega164pa

+0

純粹看起來像一個AVR-libc的問題(在我的副本中,m164pa從其他164S不同,但是聲明瞭這些端口)。檢查你的是最新的,如果它仍然失敗,報告錯誤http://www.nongnu.org/avr-libc/ - 或者只是使用工作頭,愛特梅爾甚至沒有列出A和PA模型。 –

回答

0

此問題似乎是由於在文件io.h內部沒有針對MCU類型__AVR_ATmega164PA__的特定文件包含的事實;只有:__AVR_ATmega164P____AVR_ATmega164A__。我認爲164PA的代碼必須編譯爲164P。

這是文件中的代碼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 

所發出的警告表明您可能有是指定的目標沒有任何庫(我調試的目的和「幸運」表示也關注區段的結束)。

如果你試圖編譯SW沒有管理PORTCDDRC(評論自己使用),你應該有這樣的結果:

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(海灣合作委員會)4.8.2