#include
#define uint unsigned int
#define uchar unsigned char
#define dula P0
#define wela P1
sbit key=P3^2;
unsigned char code DuanMa[]={0xff,0xc0,0xf9,0xa4,0xb0,
uchar num;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x–)
for(y=110;y>0;y–);
}
void main()
{
while(1)
{
if(key==0) //推迟再判别,保证按键的确被按下
{
delay(5);
if(key==0)
{
num++;
if(num==17)
num=0;
}
while(!key); //同理,判别键盘的确现已松开
delay(5);
}
wela=0xff; //位选都翻开,8位数码管都显现
dula=DuanMa[num]; //送段码
}
}