#include "reg51.h"
sbit led1=P2^4;
sbit led2=P2^5;
sbit led3=P2^6;
sbit led4=P2^7;
sbit k1=P2^0;
sbit k2=P2^1;
sbit k4=P3^3;
unsigned char presskeynum=0;
void delay(unsigned int i)
{
unsigned int j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void key()
{
if(presskeynum==1)
{
if(k1==0)
{
delay(30);
led1=0;
}
if(k2==0)
{
delay(30);
led2=0;
}
}
if(presskeynum==2)
{
if(k1==0)
{
delay(10);
led3=0;
}
if(k2==0)
{
delay(10);
led4=0;
}
}
}
void Int0INit()
{
IT0=1;
EX0=1;
EA=1;
}
void main()
{
led1=1;
led2=1;
led3=1;
led4=1;
Int0INit();
while(1);
}
void Int0() interrupt 0
{
delay(10);
if(k4==0)
{
presskeynum++;
if(presskeynum==3)
presskeynum=0;
else key();
}
}
|