-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtim.c
51 lines (38 loc) · 1.05 KB
/
tim.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "tim.h"
#include <stm32f10x_rcc.h>
#include <stm32f10x_tim.h>
void
Delay_us (uint16_t nTime)
{
DELAY_US_TIM->CNT = 0;
while (DELAY_US_TIM->CNT < nTime)
;
}
void
Delay_ms (uint16_t nTime)
{
DELAY_MS_TIM->CNT = 0;
while (DELAY_MS_TIM->CNT < nTime)
;
}
void
DTIM_Initialize ()
{
RCC_APB1PeriphClockCmd (DELAY_US_TIM_APB, ENABLE);
TIM_TimeBaseInitTypeDef TIM;
TIM_TimeBaseStructInit (&TIM);
TIM.TIM_Prescaler = (uint16_t) (SystemCoreClock / 1000000) - 1;
TIM.TIM_Period = UINT16_MAX;
TIM.TIM_ClockDivision = TIM_CKD_DIV1;
TIM.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit (DELAY_US_TIM, &TIM);
TIM_Cmd (DELAY_US_TIM, ENABLE);
RCC_APB1PeriphClockCmd (DELAY_MS_TIM_APB, ENABLE);
TIM_TimeBaseStructInit (&TIM);
TIM.TIM_Prescaler = (uint16_t) (SystemCoreClock / 1000) - 1;
TIM.TIM_Period = UINT16_MAX;
TIM.TIM_ClockDivision = TIM_CKD_DIV1;
TIM.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit (DELAY_MS_TIM, &TIM);
TIM_Cmd (DELAY_MS_TIM, ENABLE);
}