? ? /* 配置TIM4 */
? ? TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure={0};
? ? TIM_TimeBaseInitStructure.TIM_Period = 1000;
? ? TIM_TimeBaseInitStructure.TIM_Prescaler = 1000;
? ? TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
? ? TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
? ? TIM_DeInit(TIM4);
? ? RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4, ENABLE);
? ? /* 初始化TIM4 */
? ? TIM_TimeBaseInit(TIM4, &TIM_TimeBaseInitStructure);
? ? TIM_ClearFlag( TIM4, TIM_FLAG_Update );
? ? TIM_ARRPreloadConfig( TIM4, ENABLE );
? ? TIM_Cmd( TIM4, ENABLE );
USART_Printf_Init(9600);
while(1){
? ? printf("Timer4 CNT:0x%06\r\n",TIM_GetCounter(TIM4));
? ? Delay_Ms(200);
}
打印結果:
Timer4 CNT:0x00000
Timer4 CNT:0x00000
Timer4 CNT:0x00000
Timer4 CNT:0x00000
Timer4 CNT:0x00000
Timer4 CNT:0x00000
Timer4 CNT:0x00000
Timer4 CNT:0x00000
Timer4 CNT:0x00000
Timer4 CNT:0x00000
Timer4 CNT:0x00000
Timer4 CNT:0x00000
Timer4 CNT:0x00000