-
Notifications
You must be signed in to change notification settings - Fork 7
/
delay.c
64 lines (62 loc) · 1013 Bytes
/
delay.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
62
63
64
#include "Delay.H"
#include "ch554_platform.h"
void mDelayuS(uint16_t n ) {
#ifdef CLOCK_CFG
#if CLOCK_CFG <= 6000000
n >>= 2;
#endif
#if CLOCK_CFG <= 3000000
n >>= 2;
#endif
#if CLOCK_CFG <= 750000
n >>= 4;
#endif
#endif
while ( n ) {
++ SAFE_MOD;
#ifdef CLOCK_CFG
#if CLOCK_CFG >= 14000000
++ SAFE_MOD;
#endif
#if CLOCK_CFG >= 16000000
++ SAFE_MOD;
#endif
#if CLOCK_CFG >= 18000000
++ SAFE_MOD;
#endif
#if CLOCK_CFG >= 20000000
++ SAFE_MOD;
#endif
#if CLOCK_CFG >= 22000000
++ SAFE_MOD;
#endif
#if CLOCK_CFG >= 24000000
++ SAFE_MOD;
#endif
#if CLOCK_CFG >= 26000000
++ SAFE_MOD;
#endif
#if CLOCK_CFG >= 28000000
++ SAFE_MOD;
#endif
#if CLOCK_CFG >= 30000000
++ SAFE_MOD;
#endif
#if CLOCK_CFG >= 32000000
++ SAFE_MOD;
#endif
#endif
-- n;
}
}
void mDelaymS(uint16_t n ) {
while ( n ) {
#ifdef DELAY_MS_HW
while ( ( TKEY_CTRL & bTKC_IF ) == 0 );
while ( TKEY_CTRL & bTKC_IF );
#else
mDelayuS(1000);
#endif
-- n;
}
}