#include "reg52.h"
typedef unsigned char u8;
typedef unsigned int u16;
#define SMGUAN P0
sbit k1=P2^2;
u8 i;
u8 code smgduan[16]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,
0x88,0x83,0xc6,0xa1,0x86,
0x8e};
void DelayMS(u16 x)//延時函數(shù)
{
u16 i;
while(x--)
{
for(i=120;i>0;i--);
}
}
void keyplay()//按鍵程序
{
if(k1==0)//判斷是否按下
{
DelayMS(15);//消抖
if(k1==0)//再次判斷,如果按下
{
i++;
if(i>15)
{
i=0;
}
SMGUAN=smgduan[i];//數(shù)碼管顯示
while(!k1);
}
}
}
void main()
{
SMGUAN=smgduan[0];
while(1)
{
keyplay();
}
}
|