新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > XS128單片機實驗:B口燈循環點亮

        XS128單片機實驗:B口燈循環點亮

        作者: 時間:2016-12-01 來源:網絡 收藏
        /****************************頭文件WQ.h部分***************************/
        #include /* common defines and macros */
        #include "derivative.h" /* derivative-specific definitions */
        /**********************************************************
        //功能:完成一個短時間的延時
        //入口參數:無
        //出口參數:無
        ***********************************************************/
        void delay(void) {
        unsigned int loop_i,loop_j;
        for(loop_i=0;loop_i<500;loop_i++) {
        for(loop_j=0;loop_j<500;loop_j++){
        ;
        }
        }
        }
        /***************************主函數部分*************************/
        #include /* common defines and macros */
        #include "derivative.h" /* derivative-specific definitions */
        #include "WQ.h"
        /******************************************************
        //功能: 完成8只LED的明燈循環流動
        //主函數
        //This is the secondprogramof mine;
        //we use it drive the led
        ******************************************************/
        void main(void) {
        unsigned char loop_index; //定義變量 標記亮燈LED序號
        DDRB = 0XFF; //定義portb端口為輸出口
        loop_index=0;
        while(1){
        switch(loop_index ) {
        case 0:PORTB = 0XFE;break;
        case 1:PORTB = 0XFD;break;
        case 2:PORTB = 0XFB;break;
        case 3:PORTB = 0XF7;break;
        case 4:PORTB = 0XEF;break;
        case 5:PORTB = 0XDF;break;
        case 6:PORTB = 0XBF;break;
        case 7:PORTB = 0X7F;
        }
        loop_index++;
        if(loop_index==8) {
        loop_index=0;
        }
        delay();
        }
        }


        評論


        技術專區

        關閉
        主站蜘蛛池模板: 乐昌市| 汾西县| 阳山县| 乌鲁木齐县| 敖汉旗| 吴旗县| 进贤县| 封丘县| 新田县| 新乡县| 汉中市| 安多县| 靖安县| 东丰县| 宜章县| 澳门| 拉萨市| 呼和浩特市| 周宁县| 丹凤县| 大庆市| 西峡县| 乌兰县| 沿河| 太仓市| 全南县| 青田县| 芜湖市| 改则县| 亚东县| 宁远县| 彰化市| 历史| 稻城县| 扬州市| 汶上县| 利辛县| 屏东市| 嵊泗县| 濉溪县| 玛沁县|