GPIO_Configuration();
NVIC_Configuration4();
TIM4_Configuration();
TIM_ClearFlag(TIM4, TIM_FLAG_Update);
TIM_ARRPreloadConfig(TIM4, DISABLE);
TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
TIM_SelectOutputTrigger(TIM4,TIM_TRGOSource_Update);
TIM_Cmd(TIM4, ENABLE);
main(1)
{
}
void NVIC_Configuration4(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM4_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
TIM_DeInit(TIM4);
TIM_TimeBaseStructure.TIM_Period = (10-1); //100K
TIM_TimeBaseStructure.TIM_Prescaler = (60-1);
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* Output Compare Active Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle; //PWM??2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //??????
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;//??????
TIM_OCInitStructure.TIM_Pulse = 5; //????
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //????
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; //??????
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;TIM_OC1Init(TIM2,&TIM_OCInitStructure); //??1
TIM_OC3Init(TIM4, &TIM_OCInitStructure); //??TIM_OCInitStruct???????????TIMx
TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable); //??TIMx?CCR3????????
TIM_ARRPreloadConfig(TIM4, ENABLE); //??TIMx?ARR????????
/* TIM4 enable counter */
TIM_Cmd(TIM4, ENABLE); //??TIMx??
TIM_CtrlPWMOutputs(TIM4, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC, ENABLE);
//PB
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; //
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//GPIO_Mode_Out_PP;//;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
//GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void TIM4_IRQHandler(void)
{
/*if (TIM_GetITStatus(TIM4, TIM_IT_CC2) != RESET)
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC2);
TIM_SetCompare2(TIM4, TIM_GetCapture2(TIM4) + 5);
}*/
if(TIM_GetITStatus(TIM4, TIM_IT_Update)) //????update????
{
TIM_ClearITPendingBit(TIM4, TIM_IT_Update); //??update??????
test_TIM4++;
}
flag_time=1;}
这是原程序,怎么波形就出不来呢? |