#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long int
uchar aa;
long int temp;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
void display(long int i);
void delay(uint z);
void init();
void main()
{
init();
while(1)
{
if(TF0==1)
{
TF0=0;
TH0=0x4c;
TL0=0x00;
aa++;
}
if(aa==1)
{
aa=0;
temp++;
}
if(temp==86400)
temp=0;
display(temp);
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=80;y>0;y--);
}
void display(long int i)
{
long int shi1,shi0,fen1,fen0,miao1,miao0;
shi1=i/3600/10;
shi0=i/3600-(shi1*10);
fen1=i%3600/60/10;
fen0=i%3600/60-(fen1*10);
miao1=i%3600%60/10;
miao0=i%3600%60-(miao1*10);
dula=1;
P0=table[shi1];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(3);
dula=1;
P0=table[shi0];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(3);
dula=1;
P0=0x40;
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(3);
dula=1;
P0=table[fen1];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(3);
dula=1;
P0=table[fen0];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(3);
dula=1;
P0=0x40;
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(3);
dula=1;
P0=table[miao1];
dula=0;
P0=0xff;
wela=1;
P0=0xbf;
wela=0;
delay(3);
dula=1;
P0=table[miao0];
dula=0;
P0=0xff;
wela=1;
P0=0x7f;
wela=0;
delay(1);
}
void init()
{
TMOD=0x01;
TH0=0x4c;
TL0=0x00;
TR0=1;
temp=65520;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
你好,我没用EA我用TF检测的我这是完整的程序,我用的是清翔51单片机其他写法我写了,但我故意用这种写法的,老师说要举一反三。
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar aa;
sbit k1=P3^0;
sbit k2=P3^1;
sbit k3=P3^2;
sbit k4=P3^3;
long int temp;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
void display(long int i);
void delay(uint z);
void init();
void main()
{
init();
while(1)
{
if(TF0==1)
{
TF0=0;
TH0=0x4c;
TL0=0x00;
aa++;
}
if(aa==20)
{
aa=0;
temp++;
}
if(temp==86400)
temp=0;
display(temp);
if(k1==0)
{
delay(5);
if(k1==0)
{
temp=temp+60;
if(temp>=86400)
{
temp=0;
}
while(!k1)
{
if(TF0==1)
{
TF0=0;
TH0=0x4c;
TL0=0x00;
aa++;
}
if(aa==20)
{
aa=0;
temp++;
}
if(temp==86400)
temp=0;
display(temp);
}
}
}
if(k2==0)
{
delay(5);
if(k2==0)
{
temp=temp-60;
if(temp<0)
{
temp=0;
}
while(!k2)
{
if(TF0==1)
{
TF0=0;
TH0=0x4c;
TL0=0x00;
aa++;
}
if(aa==20)
{
aa=0;
temp++;
}
if(temp==86400)
temp=0;
display(temp);
}
}
}
if(k3==0)
{
delay(5);
if(k3==0)
{
temp=temp+3600;
if(temp>=86400)
{
temp=0;
}
while(!k3)
{
if(TF0==1)
{
TF0=0;
TH0=0x4c;
TL0=0x00;
aa++;
}
if(aa==20)
{
aa=0;
temp++;
}
if(temp==86400)
temp=0;
display(temp);
}
}
}
if(k4==0)
{
delay(5);
if(k4==0)
{
temp=temp-3600;
if(temp<0)
{
temp=0;
}
while(!k4)
{
if(TF0==1)
{
TF0=0;
TH0=0x4c;
TL0=0x00;
aa++;
}
if(aa==20)
{
aa=0;
temp++;
}
if(temp==86400)
temp=0;
display(temp);
}
}
}
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=114;y>0;y--);
}
void display(long int i)
{
long int shi1,shi0,fen1,fen0,miao1,miao0;
shi1=i/3600/10;
shi0=i/3600-(shi1*10);
fen1=i%3600/60/10;
fen0=i%3600/60-(fen1*10);
miao1=i%3600%60/10;
miao0=i%3600%60-(miao1*10);
P0=0xfe;
wela=1;
wela=0;
P0=table[shi1];
dula=1;
dula=0;
delay(2);
P0=0x00;
dula=1;
dula=0;
P0=0xfd;
wela=1;
wela=0;
P0=table[shi0];
dula=1;
dula=0;
delay(2);
P0=0x00;
dula=1;
dula=0;
P0=0xfb;
wela=1;
wela=0;
P0=0x40;
dula=1;
dula=0;
delay(2);
P0=0x00;
dula=1;
dula=0;
P0=0xf7;
wela=1;
wela=0;
P0=table[fen1];
dula=1;
dula=0;
delay(2);
P0=0x00;
dula=1;
dula=0;
P0=0xef;
wela=1;
wela=0;
P0=table[fen0];
dula=1;
dula=0;
delay(2);
P0=0x00;
dula=1;
dula=0;
P0=0xdf;
wela=1;
wela=0;
P0=0x40;
dula=1;
dula=0;
delay(2);
P0=0x00;
dula=1;
dula=0;
P0=0xbf;
wela=1;
wela=0;
P0=table[miao1];
dula=1;
dula=0;
delay(2);
P0=0x00;
dula=1;
dula=0;
P0=0x7f;
wela=1;
wela=0;
P0=table[miao0];
dula=1;
dula=0;
delay(2);
P0=0x00;
dula=1;
dula=0;
}
void init()
{
TMOD=0x01;
TH0=0x4c;
TL0=0x00;
TR0=1;
temp=43200;
}
一周热门 更多>