按下独立按键k1数码管左移,按下独立按键k2数码管数值加1。
typedef unsigned char u8;
u8 code smgwei[]={0x00,0x04,0x08,0x0c,0x10,0x14,0x18,0x1c};
u8 code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit key1=P3^1;
sbit key2=P3^0;
u8 wei,shu;
void delay(u16 i)
{
while(i--);
}
void button()
{
if(key1==0)
{
delay(1000);
if(key1==0)
{
wei++;
if(wei>=8)
{
wei=0;
}
while(!key1);
}
}
if(key2==0)
{
delay(1000);
if(key2==0)
{
shu++;
if(shu>=10)
{
shu=0;
}
while(!key2);
}
}
}
void main()
{
while(1)
{
button();
P0=smgduan[shu];
P2=smgwei[wei];
}
}