• 求助啊,单片机交通灯问题


    //以下程序只能完成一个周期,不能连续执行


    #include<reg52.h>     //包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义

    #include<math.h>  
    #define uchar unsigned char
    #define uint  unsigned int
    #define ulang unsigned lang
    static unsigned char count;
    code unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; 
            //共阴数码管 0-9
    uchar smg[8];                 //定义缓冲区


    uint  we,ns,h,j; 
     
       
    int aaa(); 
    int bbb(); 
    void delay(unsigned int cnt)
    {
     while(--cnt);
    }
     
    void display( )
    {


               smg[0]=tab[we/10];     
          smg[1]=tab[we%10];
     smg[2]=0x00;             
               smg[3]=0x00;   
                smg[4]=0x00;
          smg[5]=0x00;            
                     smg[6]=tab[ns/10];  
     smg[7]=tab[ns%10];

    }


    void main()
    {
         uchar i;
         TMOD |=0x01;  //定时器0 10ms in 12M crystal 用于计时
    TH0=0xd8;     //初值
    TL0=0xf0;
    ET0=1;
    TR0=1;
         EA =1;     


     display();


     while(1)
     {
       
    for(i=0;i<8;i++)   //显示函数
      {
         P0=smg[i];
    P2=i;
    delay(100);
      }
              ccc();
    display( );
          }  
     
    }
    void timer() interrupt 1  
    {
       
       TH0=0xd8;                  //重新赋值
       TL0=0xf0;
       count++;


    }


    int aaa()
    {


              if(j<25)
         {
         if(j==1) { we=30,ns=25; }
    ns--;
         we--;
         P1=0xde;
    return 0; } 
     
       if(25<=j<30)
     {       
         if(j==26)  {  ns=5; } 
        P1=0xee;    
    ns--; 
    we--;  
    return 0;   }
    }
    int bbb()
    {
                if(h<25)
         {
         if(h==1) { we=25,ns=30; }
    ns--;
         we--;
          P1=0xf3;
    return 0; } 
     
       if(25<=h<30)
     {       
         if(h==26)  {  we=5; } 
        P1=0xf5;    
    ns--; 
    we--;  
    return 0;   }
     
        
     }
     int ccc()
     {
         
     if (count==25)
       {
               count=0;
       j++;
    if (j>30)  { h++;      bbb(); return 0;   }
     if(j>60) {  j=1;   h=0;    return 0; }  //问题就在这里,不能重新赋值
                  aaa();       return 0;   
      } 
     }
     

  • 相关阅读:
    博客园cnblogs for win8 托管到GitHub开源
    html5 canvas 画图表
    回文数
    SpringBoot+logback实现按业务输出日志到不同的文件
    Class.forName() 与 ClassLoader.loadClass()的区别
    Easypoi实现单模板生成多页word文档
    普通Java项目中使用Sl4j+Log4j2打印日志
    SpringBoot集成JWT
    Java8_Lambda表达式
    SpringBoot自定义Condition注解
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3000817.html
Copyright © 2020-2023  润新知