專注電子技術(shù)學習與研究
當前位置:單片機教程網(wǎng) >> MCU設(shè)計實例 >> 瀏覽文章

XS128單片機實驗:B口燈循環(huán)點亮

作者:韓冰   來源:本站原創(chuàng)   點擊數(shù):  更新時間:2013年11月30日   【字體:

/****************************頭文件WQ.h部分***************************/
#include <hidef.h>           /* common defines and macros */
#include "derivative.h"      /* derivative-specific definitions */
/**********************************************************
//功能:完成一個短時間的延時
//入口參數(shù):無
//出口參數(shù):無
***********************************************************/
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++){
          ;
       }
   }
}
/***************************主函數(shù)部分*************************/
#include <hidef.h>      /* common defines and macros */
#include "derivative.h"      /* derivative-specific definitions */
#include "WQ.h"
/******************************************************
//功能: 完成8只LED的明燈循環(huán)流動
//主函數(shù)
//This is the second program of 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();
}
}                       
 

關(guān)閉窗口

相關(guān)文章