怎么调试都是闪烁 而且闪烁的越快秒走的也越快 求高手指点
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
void display(uchar hh,uchar hl,uchar mh,uchar ml,uchar sh,uchar sl);
uchar a1,a2,a3,a4,a5,a6;
uchar hl,hh,ml,mh,sh,sl,aa,s,m,h,i;
uchar code DSY_CODE[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
uchar code seg[]={0,4,8,12,16,20,24,28,32};//由2.4 2.3 2.2 138译码器导出位选
uchar LedOut[]={0,0,0x40,0,0,0x40,0,0};
void DelayMs(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void delay_us(unsigned int n)
{
if (n == 0)
{
return ;
}
while (--n);
}
uchar trans(uchar h,uchar m,uchar s)//时间转换
{
hh=h/10;
hl=h%10;
mh=m/10;
ml=m%10;
sh=s/10;
sl=s%10;
return (hh,hl,mh,ml,sh,sl) ;
}
void T0_INT()
{
TH0=0x3c;
TL0=0xb0;
EA=1;
ET0=1;
TR0=1;
}
void time()
{
if(aa==20)
{
aa=0;
s++;
if(s==60)
{
s=0;
m++;
if(m==60)
{
m=0;
h++;
if(h==24)
h=0;
}
}
trans(h,m,s);
display(hh,hl,mh,ml,sh,sl);
}
}
void display(uchar hh,uchar hl,uchar mh,uchar ml,uchar sh,uchar sl)//显示函数
{
LedOut[0]=DSY_CODE[hh];
LedOut[1]=DSY_CODE[hl];
LedOut[3]=DSY_CODE[mh];
LedOut[4]=DSY_CODE[ml];
LedOut[6]=DSY_CODE[sh];
LedOut[7]=DSY_CODE[sl];
for(i=0;i<8;i++)
{
P0=LedOut[i];
P2=seg[i];
DelayMs(15);
}
}
/*主函数*/
void main()
{
T0_INT();
while(1)
{
time();
}
}
void time0() interrupt 1 //T1中断控制时钟运行
{
TH0=0x3c;
TL0=0xb0;
aa++;
}
一周热门 更多>