#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P1^4;
uchar i=0;uchar j;
bit flag;
uchar num;
uchar getdata[];
uchar code mima[]={0,7,3,5};
void delay(uint xms)
{
uint m,n;
for(m=xms;m>0;m--)
for(n=110;n>0;n--);
}
uchar keyscan()
{
uchar key,temp;
P2=0xfe;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case 0xee:key=12;break;
case 0xde:key=13;break;
case 0xbe:key=14;break;
case 0x7e:key=15;break;
}
while(temp!=0xf0)
{
temp=P2;
temp=temp&0xf0;
}
return key;
}
}
P2=0xfd;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case 0xed:key=8;break;
case 0xdd:key=9;break;
case 0xbd:key=10;break;
case 0x7d:key=11;break;
}
while(temp!=0xf0)
{
temp=P2;
temp=temp&0xf0;
}
return key;
}
}
P2=0xfb;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case 0xeb:key=4;break;
case 0xdb:key=5;break;
case 0xbb:key=6;break;
case 0x7b:key=7;break;
}
while(temp!=0xf0)
{
temp=P2;
temp=temp&0xf0;
}
return key;
}
}
P2= 0xf7;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case 0xe7:key=0;break;
case 0xd7:key=1;break;
case 0xb7:key=2;break;
case 0x77:key=3;break;
}
while(temp!=0xf0)
{
temp=P2;
temp=temp&0xf0;
}
return key;
}
}
return 0xff;
}
void main()
{
while(1){
num=keyscan();
if(num!=0xff)
{
if(i<4)
{
getdata[i]=num;
}
i++;
if(i==4)
{ flag=1;
for(j=0;j<4;j++)
{
flag=flag&&(mima[j]==getdata[j]);
}
if(flag==1)
{
dula=1;
P0=0x60;
dula=0;
P1=0xff;
}
else
{
dula=1;
P0=0xfc;
dula=0;
P1=0xff;
}
}
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>