Subversion Repositories Projects

Rev

Blame | Last modification | View Log | RSS feed

/*****************************************************************************
 
*****************************************************************************/

#include "main.h"

volatile unsigned int CountMilliseconds = 0;
volatile unsigned char Timer0Overflow;
volatile unsigned int flag10ms;
 
enum {
  STOP             = 0,
  CK               = 1,
  CK8              = 2,
  CK64             = 3,
  CK256            = 4,
  CK1024           = 5,
  T0_FALLING_EDGE  = 6,
  T0_RISING_EDGE   = 7
};


SIGNAL(SIG_OVERFLOW0)
{
 static unsigned char cnt=0;
 
 Timer0Overflow++;
 if(!cnt--)
  {
   cnt = 3;
   CountMilliseconds += 1;
   if(!(CountMilliseconds % 10)) {
                flag10ms = 1;
   }
  }
}


void Timer_Init(void)
{
 TCCR0  = CK8;
 TIM0_START;
}


unsigned int SetDelay(unsigned int t)
{
  return(CountMilliseconds + t - 1);                                            
}

char CheckDelay (unsigned int t)
{
  return(((t - CountMilliseconds) & 0x8000) >> 8);
}

void Delay_ms(unsigned int w)
{
 unsigned int akt;
 akt = SetDelay(w);
 while (!CheckDelay(akt));
}