標題:
單片機矩陣鍵盤掃描程序怎么返回值?
[打印本頁]
作者:
rocky0521
時間:
2018-5-1 16:48
標題:
單片機矩陣鍵盤掃描程序怎么返回值?
我的矩陣鍵盤掃描程序想按鍵然后將按鍵值返回,存到數(shù)組中,再把數(shù)組串口通訊到另一個單片機上,請大神們看看我的程序,我通過檢測得出我的鍵盤返回值不對。。。怎么破。。
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; //此鍵位為數(shù)字確認按鍵
break;
case 0x7b:
lcd_init();
lcd_pos(0,4);
return 11+0x30; //此鍵位為數(shù)字修改按鍵
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
將掃描的狀態(tài)放在定義的位上,通道8位或16位數(shù)據(jù)類型返回值
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1