新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > PIC16F917 LED游俠燈程序

        PIC16F917 LED游俠燈程序

        作者: 時間:2016-11-18 來源:網(wǎng)絡(luò) 收藏
        /*************PIC16F917單片機(jī)程序******************************/

        /*************************************************************/
        /*****File Function : LED游俠燈程序 *****/
        /*****Program Author : ZhengWen(ClimberWin) *****/
        /*****MCU : PIC16F917 內(nèi)部晶振 *****/
        /*****Compile Date : 2010/08/16 *****/
        /*****Edition Info : V1.0 *****/
        /*************************************************************/
        //引腳定義:PORTD=8LED,KEY=RB0
        /*修改日期: */

        本文引用地址:http://www.104case.com/article/201611/316053.htm

        /************************************/
        #include
        #define uchar unsigned char
        #define uint unsigned int
        void speakertest(void);//蜂鳴器測試子程序
        void keytest(void); //按鍵測試程序
        void delayms(unsigned int count);
        void PortInit(void);
        void led_display(void);//LED顯示子程序
        #define KEY RB0
        uchar led_num;//定義LED計數(shù)值存儲地址


        //數(shù)據(jù)模式 LED_DATA[0]顯示次數(shù) LED_DATA[1]顯示速度 LED_DATA[2]-[18]顯示數(shù)據(jù)
        const uchar LED_DATA1[0x12]={0x03,0x32,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x00};//彈跳燈
        const uchar LED_DATA2[0x12]={0x05,0x78,0xC3,0x66,0x3C,0x18,0x18,0x3C,0x66,0xC3,0xC3,0x66,0x3C,0x18,0x18,0x3C,0x66,0xC3};//雙燈對撞模式
        const uchar LED_DATA3[0x12]={0x05,0x50,0x00,0x81,0xc3,0xe7,0xff,0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7,0xff,0xe7,0xc3,0x81};//拉鏈模式
        const uchar LED_DATA4[0x12]={0x03,0x32,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF,0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00};//LED燈柱
        const uchar LED_DATA5[0x12]={0x03,0x64,0x55,0xaa,0x55,0xaa,0x155,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa};//動感燈
        const uchar LED_DATA6[0x12]={0x0A,0x28,0xFF,0x00,0xFF,0x00,0xAA,0x00,0x55,0x00,0x2A,0x00,0x54,0x28,0x00,0x28,0x00,0x10};//特殊爆閃
        const uchar LED_DATA7[0x12]={0x0A,0x32,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00};//爆閃

        void led_display(void)
        {
        uchar i,j;

        for(i=0;i {
        for(j=2;j<18;j++)
        {
        PORTD=~LED_DATA1[j];
        delayms(LED_DATA1[1]);
        }
        }

        for(i=0;i { for(j=2;j<18;j++)
        {PORTD=~LED_DATA2[j];delayms(LED_DATA2[1]);}
        }

        for(i=0;i { for(j=2;j<18;j++)
        {PORTD=~LED_DATA3[j];delayms(LED_DATA3[1]);}
        }

        for(i=0;i { for(j=2;j<18;j++)
        {PORTD=~LED_DATA4[j];delayms(LED_DATA4[1]);}
        }

        for(i=0;i { for(j=2;j<18;j++)
        {PORTD=~LED_DATA5[j];delayms(LED_DATA5[1]);}
        }

        for(i=0;i { for(j=2;j<18;j++)
        {PORTD=~LED_DATA6[j];delayms(LED_DATA6[1]);}
        }

        for(i=0;i { for(j=2;j<18;j++)
        {PORTD=~LED_DATA7[j];delayms(LED_DATA7[1]);}
        }

        }

        void Init(void)
        {
        PORTB = 0B00000000;
        PORTD = 0B00000000;
        TRISB = 0B00100001;//設(shè)置RB0為輸入,作為按鍵口
        TRISD = 0B00000000;//設(shè)置PORTD口為輸出,作為LED顯示口
        led_num=EEPROM_READ(0); //從EEPROM中讀取數(shù)據(jù)
        PORTD=~led_num;
        }

        void keytest(void) //按鍵測試程序
        {

        /*********************************************/
        if(KEY==0)
        {
        led_num++;
        EEPROM_WRITE(0, led_num);//保存EEPROM數(shù)據(jù)
        PORTD=~led_num;
        //////////////////
        while(KEY==0) //按鍵去抖
        { delayms(100);}
        }
        }
        /*********************************************/
        void delayms(unsigned int count)
        {
        uint i,j;
        for(i=0;ifor(j=0;j<120;j++);
        }
        /*********************************************/

        ////////////主程序/////////////////////////
        int main (void)
        {
        Init();

        while(1)
        {
        //keytest();
        led_display();//調(diào)用LED顯示子程序
        }
        }



        關(guān)鍵詞: PIC16F917LED游俠

        評論


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

        關(guān)閉
        主站蜘蛛池模板: 澄城县| 灌云县| 噶尔县| 灵石县| 轮台县| 洛隆县| 河北区| 汉源县| 溧阳市| 定陶县| 布拖县| 柳州市| 毕节市| 内江市| 饶平县| 邓州市| 临朐县| 湖南省| 海伦市| 万荣县| 安塞县| 广昌县| 依兰县| 冕宁县| 泰宁县| 东城区| 防城港市| 辉南县| 丹巴县| 靖江市| 罗平县| 西城区| 湖口县| 泸州市| 天津市| 南京市| 大竹县| 宣汉县| 万源市| 临高县| 孟州市|