#include "stm32f10x.h" void EnableTimer(TIM_TypeDef *Timer){ if(Timer == TIM2){ RCC -> APB1ENR |= RCC_APB1ENR_TIM2EN; } else if(Timer == TIM3){ RCC -> APB1ENR |= RCC_APB1ENR_TIM3EN; } else if(Timer == TIM4){ RCC -> APB1ENR |= RCC_APB1ENR_TIM4EN; } else if(Timer == TIM1){ RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; } else{ } } void MyTimer_Base_Init(TIM_TypeDef *Timer, unsigned short Autoreload, unsigned short Prescaler){ if (Timer == TIM1) { RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; //L'horloge est enabléd } else if (Timer == TIM2) { TIM2->CR1 |= TIM_CR1_CEN; //On enable l'horloge interne RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; } else if (Timer == TIM3) { RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; } else if (Timer == TIM4) { RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; } Timer->ARR = Autoreload; Timer->PSC = Prescaler; }; void (*pFnc) (void); void MyTimer_ActiveIT (TIM_TypeDef * Timer , char prio, void (*IT_function)(void)){ Timer->DIER |= TIM_DIER_UIE; IRQn_Type IRQn; if (Timer == TIM2) IRQn = TIM2_IRQn; else if (Timer == TIM3) IRQn = TIM3_IRQn; else IRQn = TIM4_IRQn; NVIC_EnableIRQ(IRQn); NVIC_SetPriority(IRQn, prio); pFnc = IT_function; }; void TIM2_IRQHandler(void){ if (pFnc != 0){ (*pFnc) (); /* appel indirect de la fonction */ } TIM2->SR &= ~TIM_SR_UIF; }; void TIM3_IRQHandler(void){ TIM3->SR &= ~TIM_SR_UIF; }; void TIM4_IRQHandler(void){ TIM4->SR &= ~TIM_SR_UIF; };