新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > XS128單片機(jī)實驗:B口燈循環(huán)點亮

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

作者: 時間:2016-12-01 來源:網(wǎng)絡(luò) 收藏
/****************************頭文件WQ.h部分***************************/
#include /* 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 /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include "WQ.h"
/******************************************************
//功能: 完成8只LED的明燈循環(huán)流動
//主函數(shù)
//This is the secondprogramof mine;
//we use it drive the led
******************************************************/
void main(void) {
unsigned char loop_index; //定義變量 標(biāo)記亮燈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();
}
}


評論


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

關(guān)閉