Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
310 | pangu | 1 | /***************************************************************************** |
2 | |||
3 | *****************************************************************************/ |
||
4 | #include "main.h" |
||
5 | |||
6 | volatile unsigned int CountMilliseconds = 0; |
||
7 | volatile unsigned char Timer0Overflow; |
||
8 | volatile unsigned int flag10ms; |
||
9 | |||
10 | enum { |
||
11 | STOP = 0, |
||
12 | CK = 1, |
||
13 | CK8 = 2, |
||
14 | CK64 = 3, |
||
15 | CK256 = 4, |
||
16 | CK1024 = 5, |
||
17 | T0_FALLING_EDGE = 6, |
||
18 | T0_RISING_EDGE = 7 |
||
19 | }; |
||
20 | |||
21 | |||
22 | SIGNAL(SIG_OVERFLOW0) |
||
23 | { |
||
24 | static unsigned char cnt=0; |
||
25 | |||
26 | Timer0Overflow++; |
||
27 | if(!cnt--) |
||
28 | { |
||
29 | cnt = 3; |
||
30 | CountMilliseconds += 1; |
||
31 | if(!(CountMilliseconds % 10)) { |
||
32 | flag10ms = 1; |
||
33 | } |
||
34 | } |
||
35 | } |
||
36 | |||
37 | |||
38 | void Timer_Init(void) |
||
39 | { |
||
40 | TCCR0 = CK8; |
||
41 | TIM0_START; |
||
42 | } |
||
43 | |||
44 | |||
45 | unsigned int SetDelay(unsigned int t) |
||
46 | { |
||
47 | return(CountMilliseconds + t - 1); |
||
48 | } |
||
49 | |||
50 | char CheckDelay (unsigned int t) |
||
51 | { |
||
52 | return(((t - CountMilliseconds) & 0x8000) >> 8); |
||
53 | } |
||
54 | |||
55 | void Delay_ms(unsigned int w) |
||
56 | { |
||
57 | unsigned int akt; |
||
58 | akt = SetDelay(w); |
||
59 | while (!CheckDelay(akt)); |
||
60 | } |