單片機一鍵多功能按鍵識別設(shè)計
7.C語言源程序
#include AT89X51.H>
unsigned char ID;
void delay10ms(void)
{
unsigned char i,j;
for(i=20;i>0;i--)
for(j=248;j>0;j--);
}
void delay02s(void)
{
unsigned char i;
for(i=20;i>0;i--)
{delay10ms();
}
}
void main(void)
{ while(1)
{ if(P3_7==0)
{delay10ms();
if(P3_7==0)
{
ID++;
if(ID==4)
{
ID=0;
}
while(P3_7==0);
}
}
switch(ID)
{ case 0:
P1_0=~P1_0;
delay02s();
break;
case 1:
P1_1=~P1_1;
delay02s();
break;
case 2:
P1_2=~P1_2;
delay02s();
break;
case 3:
P1_3=~P1_3;
delay02s();
break;
}
}
評論