宏定义
#include<iocc2530.h> #define uchar unsigned char #define uint unsigned int #define LED1 P1_0
初始化
void Initial(void) { P1DIR|=0X01; P1&=~0X01; }
延迟
void Delay(uint time) { while(time--); }
呼吸灯
void ON_OFF_LED(uint CYCLE , uint PWM_LOW) { LED1=1; Delay(CYCLE); Delay(PWM_LOW); LED1=0; }
主函数
main() { uint CYCLE=600,PWM_LOW=0; Initial(); while(1) { //明到暗 for(PWM_LOW=0;PWM_LOW<CYCLE;PWM_LOW++) { ON_OFF_LED(CYCLE-PWM_LOW , PWM_LOW); } //暗到明 for(PWM_LOW=CYCLE;PWM_LOW>0;PWM_LOW--) { ON_OFF_LED(CYCLE-PWM_LOW , PWM_LOW); } } }