标题:
单片机矩阵键盘扫描程序怎么返回值?
[打印本页]
作者:
rocky0521
时间:
2018-5-1 16:48
标题:
单片机矩阵键盘扫描程序怎么返回值?
我的矩阵键盘扫描程序想按键然后将按键值返回,存到数组中,再把数组串口通讯到另一个单片机上,请大神们看看我的程序,我通过检测得出我的键盘返回值不对。。。怎么破。。
uchar matrixkeyscan() //键盘扫描程序,使用P1口
{
uchar temp,key;
uchar i=0,k=0;
P1=0xfe;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xee:
key=0+0x30;
break;
case 0xde:
key=1+0x30;
break;
case 0xbe:
key=2+0x30;
break;
case 0x7e:
key=3+0x30;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
lcd_wdat(key);
return key;
}
}
P1=0xfd;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xed:
key=4+0x30;
break;
case 0xdd:
key=5+0x30;
break;
case 0xbd:
key=6+0x30;
break;
case 0x7d:
key=7+0x30;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
lcd_wdat(key);
return key;
}
}
P1=0xfb;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xeb:
key=8+0x30;
delay(50);
lcd_wdat(key);
return key;
break;
case 0xdb:
key=9+0x30;
delay(50);
lcd_wdat(key);
return key;
break;
case 0xbb:
lcd_wcmd(0x01);
delay(5);
lcd_pos(1,0);
while(dis3[i]!='\0')
{
lcd_wdat(dis3[i]);
i++;
}
i=0;
return 10+0x30; //此键位为数字确认按键
break;
case 0x7b:
lcd_init();
lcd_pos(0,4);
return 11+0x30; //此键位为数字修改按键
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xf7;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xe7:
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
for(k=0;k<5;k++)
{
send(keynum[k]);
delay(50);
}
k=0;
lcd_wcmd(0x01);
delay(5);
lcd_pos(1,0);
while(dis4[i]!='\0')
{
lcd_wdat(dis4[i]);
i++;
}
i=0;
return 12+0x30;
}
}
}
复制代码
作者:
wenluquan
时间:
2018-5-2 10:35
将扫描的状态放在定义的位上,通道8位或16位数据类型返回值
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1