#include<reg51.h>
void delay(unsigned int i)
{
unsigned char j,k;
for(j=0;j<i;j++)
for(k=0;k<255;k++);
}
void main()
{
unsigned int h,l;
P2=0X00;
P3=0X00;
while(1)
{
P1=0XF0;
h=P1;
if(h!=0xf0)
{
delay(1000);
h=P1;
if(h!=0xf0)
{
h=h&0xf0; /*1110 0000*/
P1=0X0F; /*11101111*/
delay(1);
l=P1;
l=P1;
if(l!=0x0f)
{
delay(1000);
if(l!=0x0f)
{
l=l&0x0f;
h=h+l;
}
}
}
}
if(h==0x11)
{
P2=0XC0;
P3=0XFF;
delay(255);
}
}
}
-
void main()
{
unsigned int h,a;
P2=0X00;
P3=0X00;
while(1)
{
P1=0xf0;
h=P1;
h=h&0xf0;
if(h!=0xf0)
{
delay(5);//按键按下去抖
h=P1;
h=h&0xf0;
if(h!=0xf0)
{ h=P1;//若是第一个键按下h=1110 0000
P1=0X0F;
delay(5);
a=P1;
//a=P1;
a=a&0x0f;//若是第一个键按下a=00001110
if(a!=0x0f)
{
delay(5);
a=P1;
a=a&0x0f;
if(a!=0x0f)
{
a=P1;//a=00001110
h=h+a;//h+a=11101110
}
}
while(h!=0xf0)//松手检测
{
h=P1;
h=h&0xf0;
}
}
}
if(h==0xee)
{
P2=0XC0;//共阳极0
P3=0XFF;
delay(255);
}
}
}
一周热门 更多>