2014-11-04 55 views
0

我有folloving代码:AVR PINx.n不工作

#define F_CPU 8000000UL 
#include <avr/io.h> 
#include <util/delay.h> 

int main(void) { 
    DDRB = 0xFF;//B output 
    DDRD = 0x00;//D input 
    PORTB = 0x00;//LED off 
    PORTD = 0xFF;//Pull-ups activated 
    while(1) { 
    if(PIND.4==0) { 
     PORTB &= ~(1<<PB0); /* LED on */ 
     _delay_ms(100); 
     PORTB |= 1<<PB0; /* LED off */ 
     _delay_ms(100); 
    }} 
    return 0; 
} 

然而,试图建立它在爱特梅尔Studio时,它给出了一个错误:

Error 1 expected ')' before numeric constant 

行号指if(PIND.4==0) { 如果我删除'PIND'和'4'之间的点,它会生成但程序不起作用。 我在做什么错?

回答

1

PIND.4寄存器访问风格可能没有在您的特定ioXXXX.h文件中定义。

一个简单的替换是

if(PIND & (1<<4) == 0) { 
+1

我不认为它是在*的AVR头的任何*定义。 – 2014-11-04 20:57:03

+0

这种风格在许多来源中都有描述。喜欢那里:https://docs.google.com/presentation/d/1rmB6VRZoC46RKIF8Wp4n4IfMHdYZIkggmYX1fjA0IBY/preview?slide=id.p26 – Kestis 2014-11-04 21:06:12

+1

“特色编码与CodeVision AVR C编译器” – 2014-11-04 21:30:46