小弟做了一个时钟,望高手指教

[复制链接]
2294|4
 楼主| 649258182 发表于 2010-10-19 10:47 | 显示全部楼层 |阅读模式
小弟用C语言和C54做了一个时钟,但是出了点问题,望高手指教
程序贴在下面,就是程序开始时,会在00-00-00延时2-3S才会跳到00-00-01。还有就是每当在00-01-00这种秒满60后分进1时,也会停留2S左右才跳到00-01-01。请高手指教。
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit latch1=P2^2;
sbit latch2=P2^3;
uchar tt,shi,fen,flag1,flag2,a,b,c,d,e,f,i,s;
char miao;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};
void delay()
{
uint x,y;
for(x=1;x>0;x--)
  for(y=0;y<100;y++);
}
void init();
void display(uchar ,uchar ,uchar ,uchar ,uchar,uchar,uchar,uchar);
void main()
{
init();
while(1)
{
if(tt==20)
{
tt=0;
e=miao/10;
f=miao%10;
miao++;
if(miao==61)
{
miao=0;
e=0;
f=0;
flag1=1;
}
}
if(flag1==1)
{
flag1=0;
fen++;
c=fen/10;
d=fen%10;

if(fen==60)
{
fen=0;
c=0;
d=0;
flag2=1;
}
}
if(flag2==1)
{
flag2=0;
shi++;
a=shi/10;
b=shi%10;
if(shi==25)
shi=0;
}
display(a,b,16,c,d,16,e,f);
}
}
void enter0 () interrupt 1
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
tt++;
}
void init()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
latch2=1;
P1=0x3f;
latch2=0;
P1=0xff;
latch1=1;
P1=0xdb;
latch1=0;
}
void display(uchar a,uchar b,uchar i,uchar c,uchar d,uchar s,uchar e,uchar f)
{
latch2=1;
P1=table[a];
latch2=0;
P1=0xff;
latch1=1;
P1=0xfe;
latch1=0;
delay();

latch2=1;
P1=table[b];
latch2=0;
P1=0xff;
latch1=1;
P1=0xfd;
latch1=0;
delay();

latch2=1;
P1=table[i];
latch2=0;
P1=0xff;
latch1=1;
P1=0xfb;
latch1=0;
delay();

latch2=1;
P1=table[c];
latch2=0;
P1=0xff;
latch1=1;
P1=0xf7;
latch1=0;
delay();

latch2=1;
P1=table[d];
latch2=0;
P1=0xff;
latch1=1;
P1=0xef;
latch1=0;
delay();

latch2=1;
P1=table[s];
latch2=0;
P1=0xff;
latch1=1;
P1=0xdf;
latch1=0;
delay();

latch2=1;
P1=table[e];
latch2=0;
P1=0xff;
latch1=1;
P1=0xfbf;
latch1=0;
delay();

latch2=1;
P1=table[f];
latch2=0;
P1=0xff;
latch1=1;
P1=0x7f;
latch1=0;
delay();
}
救火车 发表于 2010-10-19 15:57 | 显示全部楼层
好多人看了没说话。。。这样的程序看起来实在费劲
liuyuxiier 发表于 2010-10-19 16:20 | 显示全部楼层
不经意看到有这么一句代码
if(miao==61)
。。。
。。。
是在没有勇气把你的程序完全读完,可能是这里除了问题

评分

参与人数 1威望 +1 收起 理由
649258182 + 1

查看全部评分

 楼主| 649258182 发表于 2010-10-21 10:34 | 显示全部楼层
嘿嘿 是挺长的。我后来发现了,是我给了2次miao=0;
e=0;
f=0;
这边的问题,我改了一下就好了呵呵
Galway-Zhang 发表于 2010-10-27 13:17 | 显示全部楼层
MCU版块.
能否做成如下:?
1.内容为程序时:自动与KEIL里面显示的格一致.以方便高手们阅读.最好颜色也能有区分更佳
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

2

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部