-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_systick.c
61 lines (54 loc) · 1.14 KB
/
my_systick.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
52
53
54
55
56
57
58
59
60
61
#include "my_systick.h"
#include "stm32f10x.h"
#include <stdint.h>
uint32_t loader;
void systickCONFIG(const uint8_t ahbclk) //ahbclk in Mhz
{
SysTick->CTRL&=(0x0);
//loader=(ahbclk*1000)-1; //Default counter for 1 millisecond
loader=ahbclk-1;
SysTick->LOAD=loader;
SysTick->VAL=(0x0);
SysTick->CTRL|=(0x4); //Set processor clock(AHB)
}
void systickINT(const uint8_t ahbclk)
{
systickCONFIG(ahbclk);
__disable_irq();
SysTick->CTRL|=(0x2);
NVIC_EnableIRQ(SysTick_IRQn);
__enable_irq();
}
void startTICK(void)
{
SysTick->CTRL|=(0x01); //Enable counter
}
void stopTICK(void)
{
SysTick->CTRL&=~(0x01); //Disable counter
}
void delayUS(uint16_t us)
{
while(us)
{
//SysTick->LOAD=loader;
SysTick->VAL=(0x0);
while((SysTick->CTRL&(0x01<<16))==0);
us--;
}
}
void delayMS(uint16_t ms)
{
/*while(ms)
{
//SysTick->LOAD=loader;
SysTick->VAL=(0x0);
while((SysTick->CTRL&(0x01<<16))==0);
ms--;
}*/
while(ms)
{
delayUS(1000);
ms--;
}
}