在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 二極管(STC89C52): 編寫程序?qū)崿F(xiàn)類似交通燈

            二極管(STC89C52): 編寫程序?qū)崿F(xiàn)類似交通燈

            作者: 時間:2016-11-22 來源:網(wǎng)絡(luò) 收藏
            一. 硬件設(shè)計

            二. 軟件設(shè)計
            1. 程序功能
            編寫程序?qū)崿F(xiàn)類似交通燈:東西向綠燈亮若干秒,黃燈閃爍5次后紅燈亮,紅燈亮后,南北向由紅燈變?yōu)榫G燈,若干秒后南北向黃燈閃爍5此后變紅燈,東西向變綠燈,如此重復(fù)
            2. 程序源碼
            #include
            #define uchar unsigned char
            #define uint unsigned int
            sbit red_east_west = P1 ^ 0;
            sbit yellow_east_west = P1 ^ 1;
            sbit green_east_west = P1 ^ 2;
            sbit red_south_north = P1 ^ 3;
            sbit yellow_south_north = P1 ^ 4;
            sbit green_south_north = P1 ^ 5;
            uchar flash_count = 0;
            uchar operation_type = 1;
            void delayms(uint xms);
            void traffic_light();
            void main()
            {
            while(1)
            traffic_light();
            }
            void traffic_light()
            {
            switch(operation_type)
            {
            case 1: //green between east and west, red between south and north
            red_east_west = 1; yellow_east_west = 1; green_east_west = 0;
            red_south_north = 0; yellow_south_north = 1; green_south_north = 1;
            delayms(2000);
            operation_type = 2;
            break;
            case 2: //yellow flash between east and west, green close between east and west
            delayms(300);
            yellow_east_west = ~yellow_east_west; green_east_west = 1;
            if (++flash_count != 10)
            return;
            flash_count = 0;
            operation_type = 3;
            break;
            case 3: //red between east and west, green between south and north
            red_east_west = 0; yellow_east_west = 1; green_east_west = 1;
            red_south_north = 1; yellow_south_north = 1; green_south_north = 0;
            delayms(2000);
            operation_type = 4;
            break;
            case 4: //yellow flash between south and north
            delayms(300);
            yellow_south_north = ~yellow_south_north; green_south_north = 1;
            if (++flash_count != 10)
            return;
            flash_count = 0;
            operation_type = 1;
            break;
            }
            }
            void delayms(uint xms)
            {
            uint i, j;
            for (i = xms; i > 0; i--)
            for (j = 110; j > 0; j--)
            ;
            }



            關(guān)鍵詞: 二極管STC89C52交通

            評論


            技術(shù)專區(qū)

            關(guān)閉