找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3593|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

keil 4*4鍵盤(P0接鍵盤P2輸出)怎么無法保留原狀態(tài) ,在按鍵送開后P2為全低

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:46670 發(fā)表于 2012-11-22 09:08 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include<reg51.h>
#include<intrins.h>
#define unchar unsigned char
#define unint unsigned int
void main()
{ unint key();
void ms_delay(unint delaytime);
P2=0x20;
a:P1=0xff;
P2=key();
ms_delay(500);
goto a;
}
unint key()
{unint mask=0xfe,temp,k=P2;
unint row=0,line=0;
const unint code numb[4][4]={0xee,0xde,0xbe,0x7e,
0xed,0xdd,0xbd,0x7d,0xeb,0xdb,0xbb,0x7b,0xe7,
0xd7,0xb7,0x77};

for(line=0;line<4;line++)
{P1=mask;
mask=mask*1;
temp=P1;
if(temp != mask) /*key pushed in the line ?*/
{ms_delay(300); /*to confirm a key pushed*/
if((temp&0xf0)==temp) return 0x20;
for(row=0;row<4;row++) /*抓到了行,尋列。并且P口已可讀出*/
{if(P1==numb[line][row]) /*反查表,讀出行列*/
return line*4+row+1;
}}
else mask=_crol_(mask,1); /*查表*/
}
P1=0x0f; /*no key*/
temp=P1;
while(temp&0x0f==0x0f)
{P1=0xf0;
return p2;}/*保留原狀態(tài)*/
}

void ms_delay(unint delaytime)
{unint i=0;
for(;delaytime>0;delaytime--)
{for(i=0;i<124;i++); }}
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:46452 發(fā)表于 2012-11-22 20:17 | 只看該作者
我也搞不懂啊  那里出差了呢
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表