void TIM3_UPCount_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
// NVIC_InitTypeDef NVIC_StructInit;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 50;
TIM_TimeBaseStructure.TIM_Prescaler = 36000-1;
//Sampling frequency of digital filter does not affect timer clock
//Sampling Frequency Dividing Value
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
// interrupt priority configuration
//NVIC_StructInit.NVIC_IRQChannel = TIM3_IRQn;
//NVIC_StructInit.NVIC_IRQChannelPriority = 1;
//NVIC_StructInit.NVIC_IRQChannelCmd = ENABLE;
//NVIC_Init(&NVIC_StructInit);
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
TIM_ClearFlag(TIM3, TIM_FLAG_Update);
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
TIM_ARRPreloadConfig(TIM3, ENABLE);
TIM_Cmd(TIM3, ENABLE);
}
void NVIC_Configure(u8 ch, u8 pri, u8 sub)
{
exNVIC_Init_TypeDef NVIC_InitStruct;
NVIC_InitStruct.NVIC_IRQChannel = ch;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = pri;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = sub;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
exNVIC_Init(&NVIC_InitStruct);
}
s32 main(void)
{
SystemInit();//36M
LED_Init();
DELAY_Init();
NVIC_Configure(TIM3_IRQn, 0, 1);
TIM3_UPCount_Init();
while(1)
{
if(1 == j)
{
// GPIOB->BRR = 0x1000U;
GPIO_ResetBits(GPIOB,GPIO_Pin_12);
}
else
{
// GPIOB->BSRR = 0x1000U;
GPIO_SetBits(GPIOB,GPIO_Pin_12);
}
}
}
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
i++;
if(i>9)
{
i =0;
j = !j;
}
}
} |