延迟函数实现ZigBee & CC2530呼吸灯

#define LED1 P1_0
#define LED2 P1_1

Void delay(int time){
  while(time--);
}
Void breath(){
  for(int i = 0; i<100; i++){
   LED1 = 0;
   LED2 = 0;
   delay(100*i);
   LED1 = 1;
   LED2 = 1;
   delay(100*(100-i));
  }
  for(int i = 0; i<100; i++){
   LED1 = 0;
   LED2 = 0;
   delay(100*(100-i));
   LED1 = 1;
   LED2 = 1;
   delay(100*i);
  }
}
void main(void){
   P1DIR = 0x1b;
   P1 = 0;
   while(1)
   {
     breath()
   }
}

 

 

你可能感兴趣的:(单片机,嵌入式硬件)