Subversion Repositories BL-Ctrl

Rev

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