仿真图
代码:#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
uchar temp,aa,m1,m2,m3,shi,ge;
uchar code table[]={
0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delay(uint z);
void display(uchar m1,uchar m2,uchar m3,uchar shi,uchar ge);
void initial();
void main()
{
initial();
while(1)
{
if(key1==0)
{
delay(10);
if(key1==0)
{
while(!key1);
TR0=1;
}
}
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
TR0=0;
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
temp=0;
m1=0;
m2=0;
m3=0;
shi=0;
ge=0;
TR0=0;
}
}
display(m1,m2,m3,shi,ge);
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(uchar m1,uchar m2,uchar m3,uchar shi,uchar ge)
{
P2=0xfe;
P0=table[m1];
delay(10);
P2=0xfd;
P0=table[m2];
delay(10);
P2=0xfc;
P0=table[m3];
delay(10);
P2=0xfb;
P0=table[ge];
delay(10);
P2=0xfa;
P0=table[shi];
delay(10);
}
void initial()
{
temp=0;
TMOD=0x01;
TH0=(65536-500)/256;
TL0=(65536-500)%256;
EA=1;
ET0=1;
}
timer0() interrupt 1
{
TH0=(65536-500)/256;
TL0=(65536-500)%256;
aa++;
m3=aa/100;
m2=aa%100/10;
m1=aa%100%10;
if(aa==1000)
{
aa=0;
temp++;
if(temp==99)
{
temp=0;
}
shi=temp/10;
ge=temp%10;
}
}
|