#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define show P2
code table[16]=
{
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
code tuble[9]=
{
0x00,0x7f,0xbf,
0xdf,0xef,0xf7,
0xfb,0xfd,0xfe
};
uchar t_h,t_m,t_s;
bit KEY=1;
sbit wela=P0^1;
sbit dula=P0^0;
char ge,shi,time0,led;
void play_h(uchar t_h);
void play_m(uchar t_m);
void play_s(uchar t_s);
void display_();
void delay(uint );
void inti();
//void display(uchar t_h,uchar t_m,uchar t_s);
void main()
{
inti();
t_h=setup_h();
t_m=setup_m();
t_s=setup_s();
while(1)
{
if (KEY)
{
KEY=0;
t_s+=1;
if(t_s==60)
{t_m++;t_s=0;}
if(t_m==60)
{t_h++;t_m=0;}
if(t_h==24)
{t_h=0;}
}
delay(3);
display_();
delay(3);
play_s(t_s);
delay(3);
play_m(t_m);
delay(3);
play_h(t_h);
delay(3);
// display(t_h,t_m,t_s);
}
}
//初始化函数
void inti()
{
TMOD=0x01;
IE=0x82;
SP=0x60;
TH0=15536/256;
TL0=15536%256;
P1=0xfe;
time0=0;
t_h=0;
t_m=0;
t_s=0;
led=P1;
ge=0;
shi=0;
TR0=1;
wela=0;
dula=0;
}
//中断函数
void timer0() interrupt 1 using 1
{
TR0=0;
TH0=15536/256;
TL0=15536%256;
TR0=1;
time0++;
if(time0==20)
{
time0=0;
KEY=1;
led=_crol_(led,1);
P1=led;
if (KEY)
{
KEY=0;
t_s+=1;
if(t_s==60)
{t_m++;t_s=0;}
if(t_m==60)
{t_h++;t_m=0;}
if(t_h==24)
{t_h=0;}
}
}
}
//时钟小时位显示
void play_h(uchar t_h)
{
uchar th=t_h;
ge=th%10;
shi=th/10;
show=0xfd;
wela=1;
wela=0;
show=table[ge];
dula=1;
dula=0;
delay(1);
show=0xfe;
wela=1;
wela=0;
show=table[shi];
dula=1;
dula=0;
delay(1);
show=0x00;
}
//时钟分位显示
void play_m(uchar t_m)
{
uchar tm=t_m;
ge=tm%10;
shi=tm/10;
show=0xef;
wela=1;
wela=0;
show=table[ge];
dula=1;
dula=0;
delay(1);
show=0xf7;
wela=1;
wela=0;
show=table[shi];
dula=1;
dula=0;
delay(1);
show=0x00;
}
//时钟秒位显示
void play_s(uchar t_s)
{
uchar ts;
ts=t_s;
ge=ts%10;
shi=ts/10;
show=0x7f;
wela=1;
wela=0;
show=table[ge];
dula=1;
dula=0;
delay(1);
show=0xbf;
wela=1;
wela=0;
show=table[shi];
dula=1;
dula=0;
delay(1);
show=0x00;
}
//显示-连接
void display_()
{
delay(1);
show=0xdb;
wela=1;
wela=0;
show=0x40;
dula=1;
dula=0;
show=0x00;
}
//软件延时
void delay(uint aa)
{
uint x=aa,y;
for(;x>0;x--)
for (y=110;y>0;y--);
}
我这是上周没事自己写了玩的 你把t_h初值改一下就行了 你要连对了电路显示效果是
时时-分分-秒秒
嗯 你看着改改吧 能用的
到13变成1,然后继续跳