#include "PWM.h"
int main()
{
u16 led0pwmval = 0;
u8 dir = 1;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //NVIC初始化分组
LED_Init(); //LED初始化
delay_init(); //延时初始化
TIM_PWM_Init(899,0); //不分频。PWM频率=72000000/900=80Khz
while(1)
{
delay_ms(10);
if(dir)
{
led0pwmval++;
}
else
{
led0pwmval--;
}
if(led0pwmval > 300){dir = 0;}
if(led0pwmval == 0){dir = 1;}
//往CCR2寄存器写入不断变化的led0pwmval值,调整比较值,就能输出不断变化的占空比了
TIM_SetCompare2(TIM2,led0pwmval);
}
}
|