RefKEIL/ProjetsKEIL/Drivers/Source/Driver_MyTimer.c
2023-03-21 16:49:07 +01:00

64 lines
1.1 KiB
C

#include "Driver_MyTimer.h"
#include "stm32f10x.h"
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer)
{
if (Timer->Timer==TIM1)
{
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
TIM1->PSC = Timer->PSC;
TIM1->ARR = Timer->ARR;
}
if (Timer->Timer==TIM2)
{
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
TIM2->PSC = Timer->PSC;
TIM2->ARR = Timer->ARR;
}
if (Timer->Timer==TIM3)
{
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
TIM3->PSC = Timer->PSC;
TIM3->ARR = Timer->ARR;
}
if (Timer->Timer==TIM4)
{
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
TIM4->PSC = Timer->PSC;
TIM4->ARR = Timer->ARR;
}
}
void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio)
{
char num ;
Timer->DIER |= 1<< 0 ;
//Timer->DIER |= TIM_DIER_UIE ;
if (Timer==TIM1)
{
NVIC->ISER[0] |=1<< TIM1_UP_IRQn ;
NVIC->IP[TIM1_UP_IRQn] = Prio << 4 ;
}
if (Timer==TIM2)
{
NVIC->ISER[0] |=1<< TIM2_IRQn ;
NVIC->IP[TIM2_IRQn] = Prio << 4 ;
}
if (Timer==TIM3)
{
NVIC->ISER[0] |=1<< TIM3_IRQn ;
NVIC->IP[TIM3_IRQn] = Prio << 4 ;
}
if (Timer==TIM4)
{
NVIC->ISER[0] |=1<< TIM4_IRQn ;
NVIC->IP[TIM4_IRQn] = Prio << 4 ;
}
}