求问单片机编程高手,下面这段4X4键盘的程序哪里出错了???不需要别的,只需要修正~~谢谢~~~
unsignedintb,t,i;unsignedcharkey_scan(){Set_IOA_Dir(0xfff0);Set_IOA_Attrib(0xfff0);//...
unsigned int b,t,i;
unsigned char key_scan()
{
Set_IOA_Dir(0xfff0);
Set_IOA_Attrib(0xfff0); //对A口的初始化;
Set_IOA_Data(0xffef); //对第一行进行赋值检测;
b=Get_IOA_Data(); //获得A口值;
b&=0x000f;
if(b!=0x000f)
{
for(i=0;i<100;i++); //防抖;
b=Get_IOA_Data();
b&=0x000f;
if(b!=0x000f)
{
b=Get_IOA_Data(); //检测获得列值;
switch (b)
{
case 0xffee:t=0;break;
case 0xffed:t=1;break;
case 0xffeb:t=2;break;
case 0xffe7:t=3;break;
}
while(b!=0x000f) //检测释放按键;
{
b=Get_IOA_Data();
b&=0x000f;
}
Watchdog_Clear();
return t; //返回值;
}
}
Set_IOA_Data(0xffdf);
b=Get_IOA_Data();
b&=0x000f;
if(b!=0x000f)
{
for(i=0;i<100;i++);
b=Get_IOA_Data();
b&=0x000f;
if(b!=0x000f)
{
b=Get_IOA_Data();
switch (b)
{
case 0xffde:t=4;break;
case 0xffdd:t=5;break;
case 0xffdb:t=6;break;
case 0xffd7:t=7;break;
}
while(b!=0x000f)
{
b=Get_IOA_Data();
b&=0x000f;
}
Watchdog_Clear();
return t;
}
}
Set_IOA_Data(0xffbf);
b=Get_IOA_Data();
b&=0x000f;
if(b!=0x000f)
{
for(i=0;i<100;i++);
b=Get_IOA_Data();
b&=0x000f;
if(b!=0x000f)
{
b=Get_IOA_Data();
switch (b)
{
case 0xffbe:t=8;break;
case 0xffbb:t=9;break;
case 0xffbd:t=10;break;
case 0xffb7:t=11;break;
}
while(b!=0x000f)
{
b=Get_IOA_Data();
b&=0x000f;
}
Watchdog_Clear();
return t;
}
}
Set_IOA_Data(0xff7f);
b=Get_IOA_Data();
b&=0x000f;
if(b!=0x000f)
{
for(i=0;i<100;i++);
b=Get_IOA_Data();
b&=0x000f;
if(b!=0x000f)
{
b=Get_IOA_Data();
switch (b)
{
case 0xff7e:t=12;break;
case 0xff7d:t=13;break;
case 0xff7b:t=14;break;
case 0xff77:t=15;break;
}
while(b!=0x000f)
{
b=Get_IOA_Data();
b&=0x000f;
}
Watchdog_Clear();
return t;
}
}
} 展开
unsigned char key_scan()
{
Set_IOA_Dir(0xfff0);
Set_IOA_Attrib(0xfff0); //对A口的初始化;
Set_IOA_Data(0xffef); //对第一行进行赋值检测;
b=Get_IOA_Data(); //获得A口值;
b&=0x000f;
if(b!=0x000f)
{
for(i=0;i<100;i++); //防抖;
b=Get_IOA_Data();
b&=0x000f;
if(b!=0x000f)
{
b=Get_IOA_Data(); //检测获得列值;
switch (b)
{
case 0xffee:t=0;break;
case 0xffed:t=1;break;
case 0xffeb:t=2;break;
case 0xffe7:t=3;break;
}
while(b!=0x000f) //检测释放按键;
{
b=Get_IOA_Data();
b&=0x000f;
}
Watchdog_Clear();
return t; //返回值;
}
}
Set_IOA_Data(0xffdf);
b=Get_IOA_Data();
b&=0x000f;
if(b!=0x000f)
{
for(i=0;i<100;i++);
b=Get_IOA_Data();
b&=0x000f;
if(b!=0x000f)
{
b=Get_IOA_Data();
switch (b)
{
case 0xffde:t=4;break;
case 0xffdd:t=5;break;
case 0xffdb:t=6;break;
case 0xffd7:t=7;break;
}
while(b!=0x000f)
{
b=Get_IOA_Data();
b&=0x000f;
}
Watchdog_Clear();
return t;
}
}
Set_IOA_Data(0xffbf);
b=Get_IOA_Data();
b&=0x000f;
if(b!=0x000f)
{
for(i=0;i<100;i++);
b=Get_IOA_Data();
b&=0x000f;
if(b!=0x000f)
{
b=Get_IOA_Data();
switch (b)
{
case 0xffbe:t=8;break;
case 0xffbb:t=9;break;
case 0xffbd:t=10;break;
case 0xffb7:t=11;break;
}
while(b!=0x000f)
{
b=Get_IOA_Data();
b&=0x000f;
}
Watchdog_Clear();
return t;
}
}
Set_IOA_Data(0xff7f);
b=Get_IOA_Data();
b&=0x000f;
if(b!=0x000f)
{
for(i=0;i<100;i++);
b=Get_IOA_Data();
b&=0x000f;
if(b!=0x000f)
{
b=Get_IOA_Data();
switch (b)
{
case 0xff7e:t=12;break;
case 0xff7d:t=13;break;
case 0xff7b:t=14;break;
case 0xff77:t=15;break;
}
while(b!=0x000f)
{
b=Get_IOA_Data();
b&=0x000f;
}
Watchdog_Clear();
return t;
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询