-
Notifications
You must be signed in to change notification settings - Fork 0
/
delay.c
83 lines (75 loc) · 1.7 KB
/
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
Hurricane driverboard
delay.c:
Simple delay functions
copyright:
Copyright (c) 2006-2007 Bastiaan van Kesteren <[email protected]>
This program comes with ABSOLUTELY NO WARRANTY; for details see the file LICENSE.
This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
remarks:
-
*/
/*!
\file
Simple delay functions
*/
#include "delay.h"
#include <pic16/delay.h>
void delay_us(volatile unsigned int time)
/*!
1us delay @ 12MHz (0.33uS/instruction)
*/
{
while(time>0) {
#if WATCHDOG != 0
__asm clrwdt __endasm;
#else
__asm nop __endasm;
#endif
__asm nop __endasm;
__asm nop __endasm;
time--;
}
}
void delay_ms(volatile unsigned int time)
/*!
1ms delay @ 12MHz (0.33uS/instruction)
*/
{
while(time>0) {
delay1ktcy(1);
#if WATCHDOG != 0
__asm clrwdt __endasm;
#else
__asm nop __endasm;
#endif
delay1ktcy(1);
#if WATCHDOG != 0
__asm clrwdt __endasm;
#else
__asm nop __endasm;
#endif
delay1ktcy(1);
#if WATCHDOG != 0
__asm clrwdt __endasm;
#else
__asm nop __endasm;
#endif
time--;
}
}
void delay_s(volatile unsigned int time)
/*!
1s delay @ 12MHz (0.33uS/instruction)
*/
{
while(time>0) {
delay_ms(250);
delay_ms(250);
delay_ms(250);
delay_ms(250);
time--;
}
}