Rev 7 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /***************************************************************************** |
2 | |||
3 | *****************************************************************************/ |
||
4 | #include "main.h" |
||
5 | volatile unsigned int CountMilliseconds = 0; |
||
6 | volatile unsigned char Timer0Overflow; |
||
7 | unsigned int I2C_Timeout = 0; |
||
8 | unsigned int SIO_Timeout = 0; |
||
9 | |||
10 | |||
11 | enum { |
||
12 | STOP = 0, |
||
13 | CK = 1, |
||
14 | CK8 = 2, |
||
15 | CK64 = 3, |
||
16 | CK256 = 4, |
||
17 | CK1024 = 5, |
||
18 | T0_FALLING_EDGE = 6, |
||
19 | T0_RISING_EDGE = 7 |
||
20 | }; |
||
21 | |||
22 | |||
23 | SIGNAL(SIG_OVERFLOW0) |
||
24 | { |
||
25 | static unsigned char cnt; |
||
26 | static unsigned int cmps_cnt; |
||
27 | TCNT0 -= 97; // reload |
||
28 | Timer0Overflow++; |
||
29 | |||
30 | if(++cmps_cnt == 380) |
||
31 | { |
||
32 | PORTB |= 0x04; |
||
33 | cmps_cnt = 0; |
||
34 | } |
||
35 | else |
||
36 | if(cmps_cnt == PwmHeading) |
||
37 | { |
||
38 | PORTB &= ~0x04; |
||
39 | } |
||
40 | |||
41 | if(!--cnt) |
||
42 | { |
||
43 | cnt = 10; |
||
44 | CountMilliseconds += 1; |
||
45 | if(I2C_Timeout) I2C_Timeout--; |
||
46 | if(SIO_Timeout) SIO_Timeout--; |
||
47 | } |
||
48 | } |
||
49 | |||
50 | |||
51 | void Timer0_Init(void) |
||
52 | { |
||
53 | TCCR0B = TIMER_TEILER; // Starten des Timers |
||
54 | // TCNT0 = 100; // reload |
||
55 | TIM0_START; |
||
56 | TIMER2_INT_ENABLE; |
||
57 | } |
||
58 | |||
59 | |||
60 | unsigned int SetDelay(unsigned int t) |
||
61 | { |
||
62 | return(CountMilliseconds + t - 1); |
||
63 | } |
||
64 | |||
65 | char CheckDelay (unsigned int t) |
||
66 | { |
||
67 | return(((t - CountMilliseconds) & 0x8000) >> 8); |
||
68 | } |
||
69 | |||
70 | void Delay_ms(unsigned int w) |
||
71 | { |
||
72 | unsigned int akt; |
||
73 | akt = SetDelay(w); |
||
74 | while (!CheckDelay(akt)); |
||
75 | } |