XS128單片機(jī)實(shí)驗(yàn):B口燈循環(huán)點(diǎn)亮
#include
#include "derivative.h" /* derivative-specific definitions */
/**********************************************************
//功能:完成一個(gè)短時(shí)間的延時(shí)
//入口參數(shù):無(wú)
//出口參數(shù):無(wú)
***********************************************************/
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
#include "derivative.h" /* derivative-specific definitions */
#include "WQ.h"
/******************************************************
//功能: 完成8只LED的明燈循環(huán)流動(dòng)
//主函數(shù)
//This is the secondprogramof mine;
//we use it drive the led
******************************************************/
void main(void) {
unsigned char loop_index; //定義變量 標(biāo)記亮燈LED序號(hào)
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();
}
}
評(píng)論