导购个人网站怎么做的,免费模板网站word,node.js 做网站,网站开发入门需要学什么程序特点#xff1a;
1、模块化#xff0c;可快速移植#xff0c;5分钟便可完成移植。
2、通过GPIO普通定时器#xff0c;实现呼吸灯功能。
3、PWM周期为5ms#xff0c;占空比调节时间为20ms#xff0c;占空比为100等份#xff0c;即呼吸灯从暗到亮需要20ms*1002s。 …程序特点
1、模块化可快速移植5分钟便可完成移植。
2、通过GPIO普通定时器实现呼吸灯功能。
3、PWM周期为5ms占空比调节时间为20ms占空比为100等份即呼吸灯从暗到亮需要20ms*1002s。
4、可以通过更改参数来更改占空比等份数和呼吸灯周期。
BreathLed.c
#include Breathled.hBreath_LED Breathled;void Breath_Led_Init()
{Breathled.EN0;Breathled.DIR1;Breathled.pwm_cnt0;Breathled.stall0;Breathled.pwm_period100;Breathled.pwm_duty0;Breathled.cnt0;
}void Breath_Led_Driver()//放在50us中断
{if(!Breathled.EN)return;if(Breathled.pwm_cntBreathled.pwm_period)//50*1005msBreathled.pwm_cnt;else{Breathled.pwm_cnt0;if(Breathled.stall4)//5ms*420msBreathled.stall;else{Breathled.stall0;if(Breathled.DIR){if(Breathled.pwm_dutyBreathled.pwm_period)//20ms*1002sBreathled.pwm_duty;else{Breathled.EN0;Breathled.DIR0;}}else{if(Breathled.pwm_duty)Breathled.pwm_duty--;else{Breathled.EN0;Breathled.DIR1;}}}} if(Breathled.pwm_cntBreathled.pwm_duty)Set_ALL_LED_ON();elseSet_ALL_LED_OFF();
}
BreathLed.h
#ifndef BREATHLED_H
#define BREATHLED_H
struct Breath_LED
{byte EN :1;byte DIR:1;byte pwm_cnt;byte pwm_duty;byte pwm_period;byte stall;byte cnt;
};extern Breath_LED Breathled;#endif
tim.c
#include tim.hvoid TIM2_Init()
{tm2ct 0; tm2b 200; $ TM2C SYSCLK,Disable,Period; $ TM2S 8BIT,/1,/1;INTEN.TM2 1;INTRQ.TM2 0;
}
main.c
#include tim.h
#include Breathled.hint main(void)
{TIM2_Init();Breath_Led_Init();Breathled.EN1;//呼吸灯从暗到亮然后全亮并停止呼吸。while(){}
}void Interrupt (void)
{pushaf;if(Intrq.TM2)//50us{Intrq.TM20;Breath_Led_Driver(); }popaf;
}