-
Notifications
You must be signed in to change notification settings - Fork 1
/
basic.c
86 lines (74 loc) · 1.46 KB
/
basic.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
void delay_1us(void) //1us延时函数,不能连续调用,
{
asm("nop"); //1时钟周期
asm("nop");
asm("nop");
asm("nop");
asm("nop"); //1T
asm("nop");
}
void delay_3us(void) //3us延时函数,,可重复调用不影响精度
{
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
}
void delay_10us(void) //10us延时函数,,可重复调用不影响精度
{
delay_3us();
delay_3us();
delay_3us();
}
void delay_50us(void) //48us延时函数,,可重复调用不影响精度
{
delay_10us();
delay_10us();
delay_10us();
delay_10us();
}
void delay_100us(void) //exactly 98us延时函数,,可重复调用不影响精度
{
delay_50us();
delay_50us();
}
void delay_n100us(unsigned char n100us)
{
while(n100us--)
delay_100us();
}
void delay_1ms(void)
{
delay_100us();
delay_100us();
delay_100us();
delay_100us();
delay_100us();
delay_100us();
delay_100us();
delay_100us();
delay_100us();
delay_100us();
}
void delay_nms(unsigned int nms)
{
while(nms--)
delay_1ms();
}