Subversion Repositories BL-Ctrl

Rev

Rev 29 | 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;
31 Nick666 23
 TCNT0 = 0x7F;
1 ingob 24
 Timer0Overflow++;
25
 if(!cnt--)
26
  {
27
   cnt = 3;
28
   CountMilliseconds += 1;
29
   if(I2C_Timeout) I2C_Timeout--;
30
   if(PPM_Timeout) PPM_Timeout--;
31
   if(SIO_Timeout) SIO_Timeout--;
32
  }
33
}
34
 
35
 
36
void Timer0_Init(void)
37
{
38
 TCCR0  = TIMER_TEILER;
39
// TCNT0 = -TIMER_RELOAD_VALUE;  // reload
40
 TIM0_START;
41
 TIMER2_INT_ENABLE;
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
}