找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2743|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

求基于單片機的交通燈信號燈系統(tǒng)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:158765 發(fā)表于 2016-12-29 22:07 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
求基于單片機的交通燈信號燈系統(tǒng)
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩

相關(guān)帖子

回復(fù)

使用道具 舉報

沙發(fā)
ID:65425 發(fā)表于 2016-12-30 09:25 | 只看該作者
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit RED_A=P0^0;
sbit YELLOW_A=P0^1;
sbit GREEN_A=P0^2;
sbit RED_B=P0^3;
sbit YELLOW_B=P0^4;
sbit GREEN_B=P0^5;
uchar Flash_Count=0,Operation_Type=1;
void DelayMs(uint x)
{
uchar i;
while(x--)for(i=0;i<120;i++);
}
void Traffic_Light()
{
        switch(Operation_Type)
     {
                case 1:RED_A=1;YELLOW_A=1;GREEN_A=0;
                       RED_B=0;YELLOW_B=1;GREEN_B=1;
                       DelayMs(2000);
                       Operation_Type=2;
                       break;
                case 2:DelayMs(300);
                       YELLOW_A=~YELLOW_A;GREEN_A=1;
                       if(++Flash_Count!=10)return;
                       Flash_Count=0;
                       Operation_Type=3;
                       break;
                case 3:RED_A=0;YELLOW_A=1;GREEN_A=1;
                       RED_B=1;YELLOW_B=1;GREEN_B=0;
                        DelayMs(2000);
             Operation_Type=4;
                       break;
                case 4:DelayMs(300);
                       YELLOW_B=~YELLOW_B;GREEN_B=1;
                       if(++Flash_Count!=10)return;
                       Flash_Count=0;
                         Operation_Type=1;
           }
}
void main()
{
   while(1)Traffic_Light();
}
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表