求助,我设计的时钟出了什么问题

2019-07-16 05:20发布

  就是一个24小时的时钟,我编的代码
#include<reg52.h>
#include<intrins.h>
unsigned char code smg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void delay();
//int zhongduan() interrupt 1;
int a=0,b=0,c=0,d=0,e=0,f=0,t=0        ;
void delay()
{
        int g,h;
        for(g=100;g>0;g--)
                for(h=110;h>0;h--);
}
void main()
{
       
        TMOD=0X01;
        TR0=1;
        TH0=0X3C;
        TL0=0XB0;
        EA=1;
        ET0=1;

   while(1)
   {P2=0x01;
        P1=smg[a];
        delay();
        P1=0;

        P2=0x02;
        P1=smg[b];
        delay();
        P1=0;

        P2=0x04;
        P1=smg[c];
        delay();
        P1=0;

        P2=0x08;
        P1=smg[d];
        delay();
        P1=0;

        P2=0x10;
        P1=smg[e];
        delay();
        P1=0;  

        P2=0x20;
        P1=smg[e];
        delay();
        P1=0;
        }
}
void zhongduan() interrupt 1
{
        TH0=0X3C;
        TL0=0XB0;
        t=t+1;
        if(t>21)
        {f=f+1;
        if(f>9)
          {f=0;
          e=e+1;
          {if(e>5)
                  e=0;
                d=d+1;
                {if(d>9)
                        d=0;
                        c=c+1;
                        {if(c>5)
                                c=0;
                                b=b+1;
                                {if(b>4)
                                        b=0;
                                        a=a+1;
                                        {if(a>2)
                                                a=0;}}}}}}}}

还有电路图,就是P1脚控制数字,P2脚控制用哪个数码管,P2引脚连着数码管的共阳,通过控制共阳达到目的,

不过用KEIL仿真的时候,数字钟的数字乱跳,加快数码管切换的速度就不亮了。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
10条回答
A670521546
1楼-- · 2019-07-16 22:57
能不能加个注释啊,你这代码怎么看啊

一位位的来调代码,比如,秒ok了,再调分,分ok,再调时
草根白骨精
2楼-- · 2019-07-17 01:09
 精彩回答 2  元偷偷看……
qazxxcccc
3楼-- · 2019-07-17 02:51
好像是廷时问题,不知道你解决了没有,其实可以用时钟芯片DS1302
lovezjf234
4楼-- · 2019-07-17 05:36
P2=0x01;
        P1=smg[a];
        delay();
        P1=0;
把P1=0;改成P2=0;要求段位全灭

一周热门 更多>