好了我们就接下来完成始终的基本初始化的功能。
- #include "DRV_TIM.h"
- void TIM_Init(void)
- {
- TIM_TimeBaseInitType TIM_TimeBaseStructure;
- NVIC_InitType NVIC_InitStructure;
- RCC_APB2_Peripheral_Clock_Enable(RCC_APB2_PERIPH_TIM1);
-
- TIM_Base_Struct_Initialize(&TIM_TimeBaseStructure);
- TIM_TimeBaseStructure.Period = 63;
- TIM_TimeBaseStructure.Prescaler = 1000;
- TIM_TimeBaseStructure.ClkDiv = 0;
- TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP;
- TIM_Base_Initialize(TIM1, &TIM_TimeBaseStructure);
- NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Initializes(&NVIC_InitStructure);
-
- TIM_Interrupt_Enable(TIM1, TIM_INT_UPDATE);
- TIM_On(TIM1);
- }
- unsigned int Timcnt=0;
- void TIM1_UP_IRQHandler(void)
- {
- if (TIM_Interrupt_Status_Get(TIM1, TIM_INT_UPDATE) != RESET)
- {
- TIM_Interrupt_Status_Clear(TIM1, TIM_INT_UPDATE);
- Timcnt++;
- if(Timcnt==500)
- {
- Timcnt=0;
- GPIO_Pin_Toggle(GPIOA,GPIO_PIN_1|GPIO_PIN_7);
- }
- }
- }
- int main(void)
- {
- LED_Init();
- UART_Init();
- TIM_Init();
- while(1)
- {
- // LED_Test();
- // printf("LED_Blink!\r\n");
- }
- }
好了,定时器就分享到这里,下次移植CoreMark来和大家聊聊跑分。