標(biāo)題: keil 4*4鍵盤(P0接鍵盤P2輸出)怎么無法保留原狀態(tài) ,在按鍵送開后P2為全低 [打印本頁(yè)]

作者: hary    時(shí)間: 2012-11-22 09:08
標(biāo)題: keil 4*4鍵盤(P0接鍵盤P2輸出)怎么無法保留原狀態(tài) ,在按鍵送開后P2為全低
#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++); }}
作者: handsonman    時(shí)間: 2012-11-22 20:17
我也搞不懂啊  那里出差了呢




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1