在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,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>

            新聞中心

            單片機中斷實驗4

            作者: 時間:2016-11-21 來源:網(wǎng)絡 收藏
            電路圖:

            程序代碼如下:
            //交通燈控制程序
            #include
            unsigned char t0, t1; //定義全局變量,用來保存延時時間循環(huán)次數(shù)
            //delay0_5s1
            //功能:用T1的工作方式1編制0.5s延時程序,假定系統(tǒng)采用12Mhz晶振,定時器1,工作方式1定時50ms,再循環(huán)10次即可定時到0.5s
            void delay0_5s1 () {
            for (t0=0; t0<0x0a; t0++) {
            TH1 = 0x3c;
            TL1 = 0xb0;
            TR1 = 1;
            while (!TF1);
            TF1=0;
            }
            }
            //delay_t1
            //功能:實現(xiàn)0.5s * 延時
            //形參:unsigned char t;
            // 延時時間為0.5s*t;
            void delay_t1 (unsigned char t) {
            for (t1=0; t1
            delay0_5s1();
            }
            //int_0
            //外部中斷0中斷函數(shù),緊急情況處理,當cpu響應外部中斷0的中斷請求時,自動執(zhí)行該函數(shù),實現(xiàn)兩個方向的紅燈同時亮10s
            void int_0 () interrupt 0 {
            unsigned char i,j,k,l,m;
            i = P1; //保護現(xiàn)場,暫存P1, t0, t1, TH1, TL0;
            j = t0;
            k = t1;
            l = TH1;
            m = TL1;
            P2 = 0xdb; //兩個方向都是紅燈
            delay_t1 (20); //延時10s
            P2 = i;
            t0 = j;
            t1 = k;
            TH1 = 1;
            TL1 = m;
            }
            //int_1
            //功能:外部中斷1中斷函數(shù), 特殊情況處理,當cpu,當cpu響應外部中斷1的中斷請求時, 自動執(zhí)行該函數(shù),實現(xiàn)a到放行5s
            void int_1 () interrupt 2 {
            unsigned char i,j,k,l,m;
            EA = 0;
            i = P1;
            j = t0;
            k = t1;
            l = TH1;
            m = TL1;
            EA = 1;
            P2 = 0xf3;
            delay_t1 (10);
            EA = 0;
            P2 = i;
            t0 = j;
            t1 = k;
            TH1 = l;
            TL1 = m;
            EA = 1;
            }
            void main () {
            unsigned char k;
            TMOD = 0x10; //T1在工作方式1
            EA = 1; //開總中斷
            EX0 = 1;
            IT0 = 1;
            EX1 = 1;
            IT1 = 1;
            while (1) {
            P2 = 0xf3;
            delay0_5s1();
            P2 = 0xfb;
            delay0_5s1();
            }
            P2 = 0xeb;
            delay_t1(4);
            P2 = 0xde;
            delay_t1(110);
            for (k=0; k<3; k++) {
            P2 = 0xde;
            delay0_5s1();
            P2 = 0xdf;
            delay0_5s1();
            }
            P2 = 0xdd;
            delay_t1(4);
            }



            關(guān)鍵詞: 單片機中斷實

            評論


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

            關(guān)閉