我正在尝试运行 ac 程序,该程序将等待我在 4x4 键盘上按下一个键,然后显示我按下的数字。我有一点运行的程序,但我一启动它就结束了,我找不到我的错误。
#include <wiringPi.h>
#include <stdio.h>
#define COL1 11
#define COL2 10
#define COL3 6
#define COL4 5
#define ROW1 4
#define ROW2 3
#define ROW3 2
#define ROW4 1
#define DET 0
int colnum;
int rownum;
int keyinterrupt (void)
{
int col[] = {COL1, COL2, COL3, COL4};
int row[] = {ROW1, ROW2, ROW3, ROW4};
int reset;
for(colnum = 0; colnum++; colnum < 4)
{
for(reset = 0; reset++; reset < 4)
{
digitalWrite(col[reset], 0);
}
digitalWrite(col[colnum], 1);
for(rownum = 0; rownum++; rownum < 4)
{
if(digitalRead(row[rownum]))
{return 0;}
}
}
}
int main (void)
{
pinMode(COL1, OUTPUT);
pinMode(COL2, OUTPUT);
pinMode(COL3, OUTPUT);
pinMode(COL4, OUTPUT);
pinMode(ROW1, INPUT);
pinMode(ROW2, INPUT);
pinMode(ROW3, INPUT);
pinMode(ROW4, INPUT);
if(wiringPiISR (DET, INT_EDGE_RISING, &keyinterrupt) < 0)
{
printf("Unable to setup ISR");
return 1;
}
while(1)
{
while(!DET)
{
delay(1);
}
printf("The key pressed was at Col:%i Row:%i", colnum, rownum);
}
return 0;
}