/[H7]/trunk/PIC/delay.h
ViewVC logotype

Contents of /trunk/PIC/delay.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Mon Jan 29 09:45:25 2007 UTC (17 years, 3 months ago) by torben
File MIME type: text/plain
File size: 1557 byte(s)
Initial import of PIC module
1 /*
2 * Delay functions for HI-TECH C on the PIC18
3 *
4 * Functions available:
5 * DelayUs(x) Delay specified number of microseconds
6 * DelayMs(x) Delay specified number of milliseconds
7 *
8 * Note that there are range limits:
9 * - on small values of x (i.e. x<10), the delay becomes less
10 * accurate. DelayUs is accurate with xtal frequencies in the
11 * range of 4-16MHZ, where x must not exceed 255.
12 * For xtal frequencies > 16MHz the valid range for DelayUs
13 * is even smaller - hence affecting DelayMs.
14 * To use DelayUs it is only necessary to include this file.
15 * To use DelayMs you must include delay.c in your project.
16 *
17 * Set the crystal frequency in the CPP predefined symbols list in
18 * HPDPIC, or on the PICC commmand line, e.g.
19 * picc -DXTAL_FREQ=4MHZ
20 *
21 * or
22 * picc -DXTAL_FREQ=100KHZ
23 *
24 * Note that this is the crystal frequency, the CPU clock is
25 * divided by 4.
26 *
27 * MAKE SURE this code is compiled with full optimization!!!
28 */
29
30 #define MHZ *1
31
32 #ifndef XTAL_FREQ
33 #define XTAL_FREQ 4MHZ /* Crystal frequency in MHz */
34 #endif
35
36 #if XTAL_FREQ < 8MHZ
37 #define uS_CNT 238 /* 4x to make 1 mSec */
38 #endif
39 #if XTAL_FREQ == 8MHZ
40 #ifndef uS_CNT
41 #define uS_CNT 244
42 #else
43 #define uS_CNT 246
44 #endif
45 #endif
46
47 #define FREQ_MULT (XTAL_FREQ)/(4MHZ)
48
49 #define DelayUs(x) { unsigned char _dcnt; \
50 if(x>=4) _dcnt=(x*(FREQ_MULT)/2); \
51 else _dcnt=1; \
52 while(--_dcnt > 0) \
53 {\
54 asm("nop");\
55 asm("nop");\
56 continue; }\
57 }
58
59 extern void DelayMs(unsigned char);
60
61

  ViewVC Help
Powered by ViewVC 1.1.20