新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)程序-利用C52庫函數(shù)實(shí)現(xiàn)左右流水燈

        單片機(jī)程序-利用C52庫函數(shù)實(shí)現(xiàn)左右流水燈

        作者: 時(shí)間:2016-12-02 來源:網(wǎng)絡(luò) 收藏
        本程序所用的原理圖下載:點(diǎn)這里,單片機(jī)芯片使用的stc89c52;找到流水燈部分的原理圖即可.這是一整個(gè)單片機(jī)開發(fā)板的電路圖其他的忽略

        下面是程序源代碼:
        /***********左右流水燈**************/
        /**
        *功能:利用C52庫函數(shù)實(shí)現(xiàn)左右流水燈
        * 方法一:goto 語句實(shí)現(xiàn)之
        * 方法二: 順序?qū)崿F(xiàn)之
        * 方法三: 順序和goto語句實(shí)現(xiàn)之
        *日期:2013-06-16-09:00-09:40
        *備注:程序已通過調(diào)試
        **/
        /*********AT89C52-RC MCU*************/
        /***********HL-1 開發(fā)板***********/
        #include
        #include
        typedef unsigned int uint;
        typedef unsigned char uchar;
        void delay(uint xms)
        {
        uint x, y;
        for(x = xms; x > 0; x--)
        for(y = 110; y > 0; y--);
        }
        /**********方法1************/
        /*
        void main(void)
        {

        uchar temp, temp1, i;
        /******流水燈向左流動(dòng)********/
        /*
        loop1: while(1)
        {
        P1 = 0xfe;
        for(i = 0; i < 7; i++)
        {
        temp = P1;
        temp = _crol_(temp, 1);
        P1 = temp;
        delay(200);
        }
        goto loop;
        }
        /******流水燈向右流動(dòng)********/
        /*
        loop: while(1)
        {
        P1 = 0x7f;
        for(i = 0; i < 7; i++)
        {
        temp1 = P1;
        temp1 = cror_(temp1, 1);
        P1 = temp1;
        delay(200);
        }
        goto loop1;
        }
        }
        */
        /**********方法2************/
        /*
        void main(void)
        {
        uchar temp, i;
        P1 = 0xfe;
        while(1)
        {
        P1 = 0xfe;
        temp = P1;
        /******流水燈向左流動(dòng)********/
        /*
        for(i = 0; i < 7; i++)
        {
        temp = _crol_(temp, 1);
        P1 = temp;
        delay(200);
        }
        /******流水燈向右流動(dòng)********/
        /*
        P1 = 0x7f;
        temp = P1;
        for(i = 0; i < 7; i++)
        {
        temp = _cror_(temp, 1);
        P1 = temp;
        delay(200);
        }
        }
        }
        */
        /**********方法3***********/
        void main(void)
        {
        uchar temp, i;
        while(1)
        {
        P1 = 0xfe;
        temp = P1;
        /******流水燈向左流動(dòng)********/
        for(i = 0; i < 7; i++)
        {
        temp = _crol_(temp, 1);
        P1 = temp;
        delay(200);
        if(i >= 7)
        goto loop;
        }
        /******流水燈向右流動(dòng)********/
        loop: P1 = 0x7f;
        temp = P1;
        for(i = 0; i < 7; i++)
        {
        temp = _cror_(temp, 1);
        P1 = temp;
        delay(200);
        }
        }
        }


        評(píng)論


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

        關(guān)閉
        主站蜘蛛池模板: 北海市| 介休市| 沧州市| 洛阳市| 洮南市| 察隅县| 肥乡县| 德州市| 潜江市| 精河县| 格尔木市| 新疆| 西丰县| 潢川县| 龙海市| 枞阳县| 南康市| 文水县| 青铜峡市| 图木舒克市| 桦南县| 馆陶县| 宝兴县| 光山县| 元氏县| 铜鼓县| 克拉玛依市| 巧家县| 南投县| 嵊泗县| 华蓥市| 闻喜县| 县级市| 灵寿县| 泰顺县| 耒阳市| 天全县| 中山市| 绵竹市| 阳新县| 韶关市|