#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar num;
sbit key18=P1^4;
sbit D1=P2^0;
uchar code shu[]={ 0xc0,0xf9,0xa4,0xb0, //共陽數(shù)碼管段碼 0,1,2,3
0x99,0x92,0x82,0xf8, //共陽數(shù)碼管段碼 4,5,6,7
0x80,0x90 //共陽數(shù)碼管段碼 8,9,全滅,橫杠
};
void delay(char z)
{
char x,y;
for(x=100;x>0;x--)
for(y=z;y>0;y--);
}
void main()
{
while(1)
{
P2=0x7f;
P0=0xff;
P1=0xff;
if(key18==0)
{
delay(5);
if(key18==0)
{
D1=0;
num++;
if(num==10)
{
num=0;
}
P2=0x7f;
P0=shu[num];
}
while(key18!=1);
delay(5);
while(key18!=1);
}
else
{
D1=1;
}
}
}
|