Rev 29 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 29 | Rev 31 | ||
---|---|---|---|
1 | /***************************************************************************** |
1 | /***************************************************************************** |
2 | |
2 | |
3 | *****************************************************************************/ |
3 | *****************************************************************************/ |
4 | #include "main.h" |
4 | #include "main.h" |
5 | volatile unsigned int CountMilliseconds = 0; |
5 | volatile unsigned int CountMilliseconds = 0; |
6 | volatile unsigned char Timer0Overflow; |
6 | volatile unsigned char Timer0Overflow; |
7 | 7 | ||
8 | enum { |
8 | enum { |
9 | STOP = 0, |
9 | STOP = 0, |
10 | CK = 1, |
10 | CK = 1, |
11 | CK8 = 2, |
11 | CK8 = 2, |
12 | CK64 = 3, |
12 | CK64 = 3, |
13 | CK256 = 4, |
13 | CK256 = 4, |
14 | CK1024 = 5, |
14 | CK1024 = 5, |
15 | T0_FALLING_EDGE = 6, |
15 | T0_FALLING_EDGE = 6, |
16 | T0_RISING_EDGE = 7 |
16 | T0_RISING_EDGE = 7 |
17 | }; |
17 | }; |
18 | 18 | ||
19 | 19 | ||
20 | SIGNAL(SIG_OVERFLOW0) |
20 | SIGNAL(SIG_OVERFLOW0) |
21 | { |
21 | { |
22 | static unsigned char cnt; |
22 | static unsigned char cnt; |
- | 23 | TCNT0 = 0x7F; |
|
23 | Timer0Overflow++; |
24 | Timer0Overflow++; |
24 | if(!cnt--) |
25 | if(!cnt--) |
25 | { |
26 | { |
26 | cnt = 3; |
27 | cnt = 3; |
27 | CountMilliseconds += 1; |
28 | CountMilliseconds += 1; |
28 | if(I2C_Timeout) I2C_Timeout--; |
29 | if(I2C_Timeout) I2C_Timeout--; |
29 | if(PPM_Timeout) PPM_Timeout--; |
30 | if(PPM_Timeout) PPM_Timeout--; |
30 | if(SIO_Timeout) SIO_Timeout--; |
31 | if(SIO_Timeout) SIO_Timeout--; |
31 | } |
32 | } |
32 | } |
33 | } |
33 | 34 | ||
34 | 35 | ||
35 | void Timer0_Init(void) |
36 | void Timer0_Init(void) |
36 | { |
37 | { |
37 | TCCR0 = TIMER_TEILER; |
38 | TCCR0 = TIMER_TEILER; |
38 | // TCNT0 = -TIMER_RELOAD_VALUE; // reload |
39 | // TCNT0 = -TIMER_RELOAD_VALUE; // reload |
39 | TIM0_START; |
40 | TIM0_START; |
40 | TIMER2_INT_ENABLE; |
41 | TIMER2_INT_ENABLE; |
41 | } |
42 | } |
42 | 43 | ||
43 | 44 | ||
44 | unsigned int SetDelay(unsigned int t) |
45 | unsigned int SetDelay(unsigned int t) |
45 | { |
46 | { |
46 | return(CountMilliseconds + t - 1); |
47 | return(CountMilliseconds + t - 1); |
47 | } |
48 | } |
48 | 49 | ||
49 | char CheckDelay (unsigned int t) |
50 | char CheckDelay (unsigned int t) |
50 | { |
51 | { |
51 | return(((t - CountMilliseconds) & 0x8000) >> 8); |
52 | return(((t - CountMilliseconds) & 0x8000) >> 8); |
52 | } |
53 | } |
53 | 54 | ||
54 | void Delay_ms(unsigned int w) |
55 | void Delay_ms(unsigned int w) |
55 | { |
56 | { |
56 | unsigned int akt; |
57 | unsigned int akt; |
57 | akt = SetDelay(w); |
58 | akt = SetDelay(w); |
58 | while (!CheckDelay(akt)); |
59 | while (!CheckDelay(akt)); |
59 | } |
60 | } |
60 | 61 |