我在Atmel Studio中有此代码错误
错误是:expected ')' before numeric
这是我的代码(我将其用作atmega32a的键盘代码):
#include <util/delay.h>
#define c1 PINB 4
#define c2 PINB 5
#define c3 PINB 6
#define c4 PINB 7
unsigned char scan[4]={0XFE,0XFD,0XFB,0XF7};
unsigned char arrkey[16]={1,2,3,20,4,5,6,30,7,8,9,40,10,0,11,50};
unsigned char keypad() {
unsigned char r,c,k;
DDRB=0X0F;
PORTB=0XFF;
while(1) {
for (r=0; r<4; r++) {
c=4;
PORTB=scan[r];
_delay_us(10);
if(c1 == 0) c=0;
if(c2 == 0) c=1;
if(c3 == 0) c=2;
if(c4 == 0) c=3;
if (!(c==4)) {
k=arrkey[(r*4)+c];
while(c1==0);
while(c2==0);
while(c3==0);
while(c4==0);
_delay_ms(50);
return k;
}
}
}
}
最佳答案
问题出在您的#define
语句中,因为宏扩展按如下方式影响代码:
if(PINB 4 == 0) c = 0;
这是语法错误,因为PINB在m32定义文件中定义为寄存器。
也许您是说
#define c1 PINB4
吗?关于c - Atmel Studio中的AVR编程,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27765677/