新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 51單片機的七彩LED燈漸變調光調色程序

        51單片機的七彩LED燈漸變調光調色程序

        作者: 時間:2016-12-01 來源:網絡 收藏

        //***********************************************************************
        //Pattern4() 花樣函數4-------------7彩漸變
        //***********************************************************************
        void Pattern34()
        {
        Gra = 1; //漸變位 = 1
        }
        /*********************************************************/
        // 定時器0中斷服務程序
        /*********************************************************/
        void time0(void) interrupt 1
        {
        TR1 =0;
        TF0 =0;
        TH0=0xdb; //重新寫入初值
        TL0=0xff;
        if(!Gra) //執行跳變程序
        {
        count ++;
        if(count > Speed)
        {
        LEDdelay = 1;
        count = 0;
        }
        }
        if(Gra)
        {
        TR1 = 1; //開啟TR1;
        if(!BP) //
        {
        if(Gra7)
        {
        P1 = led1[ledcount1]; //10ms到,亮相應的LED
        }
        if(Gra3)
        {
        P1 = led3[ledcount1]; //10ms到,亮相應的LED
        }
        Pulse++;
        value();
        if(Pulse >= Period)
        {
        Pulse = Period;
        BP = 1; //一個周期完成轉換模式
        }
        }
        if(BP)
        {
        if(Gra7)
        {
        P1 = led1[ledcount1]; //10ms到,亮相應的LED
        }
        if(Gra3)
        {
        P1 = led3[ledcount1]; //10ms到,亮相應的LED
        }
        value();
        Pulse--; //脈沖個數
        if(Pulse == 0)
        {
        Pulse = 0;
        BP = 0; //一個周期完成轉換模式
        ledcount1++;
        if(Gra7)
        {
        if(ledcount1 > 11)
        {
        ledcount1 = 0;
        }
        Gra7 = 0;
        }
        if(Gra3)
        {
        if(ledcount1 > 2)
        {
        ledcount1 = 0;
        }
        Gra3 = 0;
        }
        }
        }
        }
        }
        /*********************************************************/
        // 定時器1中斷服務程序
        /*********************************************************/
        void timer1() interrupt 3
        {
        PWM --;
        TH1 = 0xff; //0.05ms(20000分之一秒)
        TL1 = 0xD1;
        if(PWM == 0)
        {
        P1 = 0;
        TR1 = 0;
        }
        }
        /*********************************************************/
        // 外部中斷0中斷服務程序 下降沿觸發
        /*********************************************************/
        void extern0(void) interrupt 0
        {
        IE0 = 0; // 清標志位
        excount++;
        if(excount>50) // 50大約3秒
        {
        EA = 0;
        //P1_5 = 1;
        excount = 0;
        Reset();
        }
        }

        上一頁 1 2 下一頁

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 马鞍山市| 罗城| 墨竹工卡县| 福州市| 汶上县| 平泉县| 湖北省| 麻阳| 星子县| 筠连县| 高雄市| 南投市| 天镇县| 淳安县| 清苑县| 乾安县| 石柱| 深州市| 白山市| 湘西| 永仁县| 三明市| 桃园县| 花垣县| 河曲县| 疏附县| 浏阳市| 顺平县| 眉山市| 抚松县| 蕲春县| 景东| 白城市| 中江县| 平罗县| 霸州市| 上栗县| 井冈山市| 勐海县| 昌吉市| 彭水|