中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 各種花樣的流水燈c51程序

        各種花樣的流水燈c51程序

        作者: 時(shí)間:2012-09-08 來源:網(wǎng)絡(luò) 收藏
        /*-----------------------------------------------
        功能:對稱移動閃爍(雙閃爍)

        作者:fei yu

        日期:2010-6-14

        ------------------------------------------------*/

        #includeREG52.H>
        #define uint unsigned int
        void delay(uint);
        main()
        {
        uint comp1=0xfe;
        uint comp2=0x80;
        P1=0x7e;
        delay(30000);
        while(1)
        {
        P1=0xff;
        comp1=1;
        comp1|=0x01;
        comp2>>=1;
        P1=comp1;
        P1^=comp2;
        delay(30000);
        if(P1==0xe7)
        {
        comp1=1;
        comp1|=0x01;
        comp2>>=1;
        }

        if(comp1==0x7f)
        {
        comp1=0xfe;
        comp2=0x80;
        }
        }
        }
        void delay(uint cnt)
        {
        while(cnt--);
        }


        /*-----------------------------------------------------------------

        只循環(huán)一次,而沒有一直循環(huán)下去,出錯(cuò)地方在:

        通過添加一條測試語句:

        if(comp1==0x7f)
        {
        comp1=0xfe; comp2=0x80;
        P1=0x00; delay(30000);

        }

        發(fā)現(xiàn)if語句沒有被執(zhí)行,自然繼續(xù)左右移動:

        1111 11111111 1111^0000 0000==11111 1111

        所以看起來是執(zhí)行了一次while中的代碼。



        具體為什么不行,還不清楚……

        更正下列代碼后,能夠?qū)崿F(xiàn)功能。

        if(P1==0x7e)
        {
        comp1=0xfe;
        comp2=0x80;
        }

        或者:

        if(comp2==0x01)
        {
        comp1=0xfe;
        comp2=0x80;
        }

        --------------------------------------------------------------*/



        *********************************************

        /*-----------------------------------------------
        功能:(單向單閃爍)

        作者:fei yu

        日期:2010-6-14

        ------------------------------------------------*/

        #includereg52.h>
        #define uint unsigned int
        void delay(uint);
        main()
        {
        //uint fre=0x03;
        //uint comp1=0xfe,comp2=0x80;
        P1=0xfe;
        while(1)
        {
        /*------------------------------------------------------------------

        模塊1:循環(huán)單向閃爍,只有一個(gè)燈亮滅
        執(zhí)行3次,轉(zhuǎn)入下一種閃爍

        --------------------------------------------------------------------*/
        while(1)
        {
        delay(30000);
        P1=1;
        P1|=0x01;
        if(P1=0x7f)
        {
        delay(30000);
        P1=0xfe;

        }
        }

        }
        }
        void delay(uint cnt){while(cnt--);}



        /*-----------------------------------------

        程序運(yùn)行結(jié)果左右兩端跳動,原因是:

        if(P1=0x7f);中的等號也成了賦值號,更正為if(P1==0x7f);

        特別注意,不要把判斷語句種的等號誤寫為賦值號。

        -----------------------------------------*/



        **************************************



        /*-----------------------------------------------
        功能:花樣燈(單向單閃爍+單向雙閃爍)

        作者:fei yu

        日期:2010-6-14

        ------------------------------------------------*/

        #includereg52.h>
        #define uint unsigned int
        void delay(uint);
        main()
        {
        uint fre=0x04;
        uint comp1=0xfe,comp2=0x80;
        while(1)
        {
        /*-------------------------------------------------------------------

        模塊1:循環(huán)單向閃爍,只有一個(gè)燈亮滅
        執(zhí)行3次,轉(zhuǎn)入下一種閃爍

        --------------------------------------------------------------------*/
        P1=0xfe;
        while(1!=fre--)
        {
        delay(30000);
        P1=1;
        P1|=0x01;
        if(P1==0x7f)
        {
        delay(30000);
        P1=0xfe;

        }
        }
        /*-------------------------------------------------------------------

        模塊2:循環(huán)單向閃爍,只有兩個(gè)燈亮或者滅
        執(zhí)行3次,轉(zhuǎn)入下一種閃爍

        --------------------------------------------------------------------*/
        P1=0xfc;
        while(3!=fre++)
        {
        delay(30000);
        P1=2;
        P1|=0x03;
        if(P1==0x3f)
        {
        delay(30000);
        P1=0xfc;
        }
        }
        }
        }
        void delay(uint cnt)
        {
        while(cnt--);
        }



        /*----------------------------------------------------

        兩個(gè)模塊均沒有問題,但是放在一起,并沒有得到想要的結(jié)果,

        第一個(gè)循環(huán)沒有進(jìn)行完全,且兩個(gè)循環(huán)的循環(huán)的次數(shù)與要求的不符。

        錯(cuò)誤地方在于:模塊1和模塊2的循環(huán)控制的只是一次亮滅,更正為:



        #includereg52.h>
        #define uint unsigned int
        void delay(uint);
        main()
        {
        uint fre=0x04;
        uint fre1,fre2;
        uint comp1=0xfe,comp2=0x80;
        while(1)
        {
        /*--------------------------------------------------------------------

        模塊1:循環(huán)單向閃爍,只有一個(gè)燈亮滅
        執(zhí)行3次,轉(zhuǎn)入下一種閃爍

        --------------------------------------------------------------------------*/
        P1=0xfe;
        while(1!=fre--)
        {
        fre1=0x08;
        while(1!=fre1--)
        {
        delay(3000000);
        P1=1;
        P1|=0x01;
        if(P1==0x7f)
        {
        delay(3000000);
        P1=0xfe;
        }
        }
        }
        /*-------------------------------------------------------------------

        模塊2:循環(huán)單向閃爍,只有兩個(gè)燈亮或者滅
        執(zhí)行3次,轉(zhuǎn)入下一種閃爍

        --------------------------------------------------------------------*/
        P1=0xfc;
        while(3!=fre++)
        {
        fre2=0x04;
        while(1!=fre2--)
        {
        delay(3000000);
        P1=2;
        P1|=0x03;
        if(P1==0x3f)
        {
        delay(3000000);
        P1=0xfc;
        }
        }
        }
        }
        }
        void delay(uint cnt)
        {
        while(cnt--);
        }

        注意控制語句中fre++和fre--;并且fre1和fre2的初始化不能出錯(cuò),

        由于if()語句的出現(xiàn),fre1和fre2的取值要比預(yù)想的減一。

        ----------------------------------------------------------*/


        關(guān)鍵詞: 流水燈 c51程序

        評論


        相關(guān)推薦

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

        關(guān)閉