標題: 基于51單片機的交通燈程序+Proteus仿真 [打印本頁]

作者: 愛他AT89C51    時間: 2019-12-2 10:18
標題: 基于51單片機的交通燈程序+Proteus仿真



#include<reg51.h>
unsigned char code a[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit w1=P3^6;
sbit w2=P3^7;
void delay(unsigned int xms);
void light(unsigned int t);
int main()
{          
       
        while(1){
           P1=0x1e;                 
           light(8);         
           P1=0x1f;               
           delay(500);
           P1=0x1e;               
           delay(500);
           P1=0x1f;               
           delay(500);
           P1=0x1e;               
           delay(500);
           P1=0x1f;               
           delay(500);
           P1=0x1e;               
           delay(500);

          
           P1=0x1d;                 
           delay(3000);         
          

          
           P1=0x33;                 
           light(8);
           P1=0x3b;                 
           delay(500);
           P1=0x33;                 
           delay(500);
           P1=0x3b;                 
           delay(500);
           P1=0x33;                 
           delay(500);
           P1=0x3b;                 
           delay(500);
           P1=0x33;               
           delay(500);
          
           P1=0x2b;                 
           delay(3000);
          
        }
        return 0;
}
void delay(unsigned int xms)
{        unsigned int k;
        unsigned char i,j;
        for(k=xms;k>0;k--)
                for(i=0;i<10;i++)
                        for(j=0;j<33;j++);
}
void light(unsigned int t)
{       
        unsigned int j;
        unsigned int x;
        unsigned int y;
        while(t!=-1)
        {
        x=t/10;
        y=t%10;
        for(j=50000;j>0;j--)
         {
          P2=a[x];
          w1=0;w2=1;
          w1=1;w2=1;

          P2=a[y];
          w1=1;w2=0;
          w1=1;w2=1;
         
          }
          t--;
    }
       
}

2019-12-02_101559.png (26.34 KB, 下載次數(shù): 65)

2019-12-02_101559.png

交通燈.zip

19.8 KB, 下載次數(shù): 46, 下載積分: 黑幣 -5


作者: 愛他AT89C51    時間: 2019-12-2 10:22
C語言編程哦
作者: hjhi    時間: 2019-12-9 09:38
謝謝分享
作者: zxasqw0577    時間: 2019-12-9 13:48
謝謝分享
作者: CFZhi    時間: 2019-12-21 12:04
大佬,怎么讓黃燈閃三下的時候,數(shù)碼管也會顯示三秒倒計時嘞

作者: 小小怪大獎    時間: 2020-9-22 17:41
CFZhi 發(fā)表于 2019-12-21 12:04
大佬,怎么讓黃燈閃三下的時候,數(shù)碼管也會顯示三秒倒計時嘞

黃燈閃三下,剛好三秒




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1