int main(void)
{
u16 led0pwmval=0;
u8 dir=1;
uart_init(9600); //?®??????????9600
delay_init(); //???±??????????
LED_Init(); //????????LED??????????????
LCD_Init();
TIM1_PWM_Init(899,0);//??·?????PWM????=72000/(899+1)=80Khz
LCD_ShowString(30,70,200,16,16,"TFTLCD TEST");
LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
while(1)
{
delay_ms(10);
if(dir)led0pwmval++;
else led0pwmval--;
if(led0pwmval>300)dir=0;
if(led0pwmval==0)dir=1;
LCD_ShowxNum(30,110,led0pwmval,16,16,0);
TIM_SetCompare1(TIM1,300);
}
}
//PWM??????????
//arr??×?????×°??
//psc???±???¤·?????
void TIM1_PWM_Init(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);//
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE); //????GPIO???è?±??????
//?è??????????????????????,????TIM1 CH1??PWM?????¨??
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //TIM_CH1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //???????ì????
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_Period = arr; //?è???????????ü??????×°????????×?????×°???????÷???????? 80K
TIM_TimeBaseStructure.TIM_Prescaler =psc; //?è??????×÷??TIMx?±?????????????¤·????? ??·???
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //?è???±??·???:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM?ò??????????
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); //?ù??TIM_TimeBaseInitStruct?????¨????????????TIMx???±???ù??????
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //?????¨?±?÷????:TIM?????í???÷??????2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±???????????
TIM_OCInitStructure.TIM_Pulse = 0; //?è????×°??????±????????÷????????
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //????????:TIM????±?????????
TIM_OC1Init(TIM1, &TIM_OCInitStructure); //?ù??TIM_OCInitStruct?????¨???????????????èTIMx
TIM_CtrlPWMOutputs(TIM1,ENABLE); //MOE ?÷????????
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable); //CH1?¤×°??????
TIM_ARRPreloadConfig(TIM1, ENABLE); //????TIMx??ARR?????¤×°???????÷
TIM_Cmd(TIM1, ENABLE); //????TIM1
}
两个历程的内容都没有改,只是单纯的放在一起啊,为什么就不能输出pwm了呢
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>