#include
#define uchar unsigned char
#define uint unsigned int
sbit we1=P2^7; //数码管位
sbit s1=P2^6; //轻触开关
sbit s2=P2^5;
uint a=0; //显示数值
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8, //共阳数码管数值0-9
0x80,0x90
/*0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07, //共阴数码管数值0-9
0x7f,0x6f*/
};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void xianshi() //数码管显示
{
we1=1; //共阴为0 共阳为1
P0=table[a];
delay(8);
}
void key()
{
if(s1==0)
{
delay(5);
if(s1==0)
{
a++;
if(a==10)
a=0;
while(!s1); //等待松开
}
}
if(s2==0)
{
delay(5);
if(s2==0)
{
a--;
if(a==-1)
a=9;
while(!s2); //等待松开
}
}
}
void main()
{
while(1)
{
xianshi();
key();
}
}