该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#define uint unsigned int
#define uchar unsigned char
uint temp;
sbit smg0=P1^0;
sbit smg1=P1^1;
sbit smg2=P1^2;
sbit smg3=P1^3;
uchar qian,bai,shi,ge,tt;
uchar code smg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void init();
void display(uchar qian,uchar bai,uchar shi,uchar ge);
void delay(uchar z);
void main()
{
init();
while(1)
{
if(tt==20)
{
tt=0;
temp++;
if(temp==9999)
{
temp=0;
}
qian=temp/1000;
bai=temp/100%10;
shi=temp/10%10;
ge=temp%10;
}
display(qian,bai,shi,ge);
}
}
void display(uchar qian,uchar bai,uchar shi,uchar ge)
{
smg0=0;
P0=smg[qian];
delay(5);
smg0=1;
smg1=0;
P0=smg[bai];
delay(5);
smg1=1;
smg2=0;
P0=smg[shi];
delay(5);
smg2=1;
smg3=0;
P0=smg[ge];
delay(5);
P1=0xff;
smg3=1;
}
void init()
{
temp=0;
tt=0;
TMOD=0x01;
TH0=-(50000/256);
TL0=-(50000%256);
EA=1;
ET0=1;
TR0=1;
}
void delay(uchar z)
{
uchar i,j;
for (i=z;i>0;i--)
for (j=110;j>0;j--);
}
void timet0() interrupt 1
{
TH0=-(50000/256);
TL0=-(50000%256);
tt++;
}