标题: 51单片机简易电子时钟,写的代码运行不出来 [打印本页]

作者: aaaa199    时间: 2023-4-16 00:01
标题: 51单片机简易电子时钟,写的代码运行不出来


#include <reg51.h>
unsigned char code LED[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char s=55,m=59,h=23;
unsigned char i1,j1,i2,j2,i3,j3,t;
void delay(unsigned int time)
{
    unsigned int j=0;
        for(;time>0;time--)
          for(j=0;j<125;j++);
}
void main()
{
  TMOD=0x01;
        TH0=0x3c;
        TL0=0xb0;
        TR0=1;
        ET0=1;
        EA=1;
        while(1);
        {
                        if (s==60)
                          { s=0;m++;}
                          i1=s/10;
                          j1=s%10;
                        if (m==60)
                          { m=0;h++;}
                          i2=m/10;
                          j2=m%10;
                        if (h==24)
                           h=0;
                          i3=h/10;
                          j3=h%10;
                  P2=0xfe;P0=LED[j1];delay(1);
                        P2=0xfd;P0=LED[i1];delay(1);
                        P2=0xfb;P0=LED[j2];delay(1);
                        P2=0xf7;P0=LED[i2];delay(1);
                        P2=0xef;P0=LED[j3];delay(1);
                        P2=0xdf;P0=LED[i3];delay(1);   
        }
}
void timer0() interrupt 1 {
   t++;
   if (t==20)
   {   t=0;
             s++;
   }
   TH0=0x3c;
   TL0=0xb0;
}


作者: wulin    时间: 2023-4-16 06:46
while(1); 多了个分号
作者: csmyldl    时间: 2023-4-16 08:41
while(1);此句后的轰号应去掉
作者: Muii    时间: 2023-4-17 00:51
while(1)即可 多了分号
作者: man1234567    时间: 2023-4-17 11:23
while(1); 编译不会通过;
delay(1); 可能结果会有。
理论上以上和运行不起来都没关系。




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1