Rev 1 |
Rev 12 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + MK3Mag 3D-Compass
// + ATMEGA168 mit 8MHz
// + (c) 05.2008 Holger Buss
// + Nur für den privaten Gebrauch
// + Keine Garantie auf Fehlerfreiheit
// + Kommerzielle Nutzung nur mit meiner Zustimmung
// + Der Code ist für die Hardware MK3Mag entwickelt worden
// + www.mikrokopter.com
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include "main.h"
volatile unsigned int CountMilliseconds = 0;
volatile unsigned char Timer0Overflow;
unsigned int I2C_Timeout = 0;
unsigned int SIO_Timeout = 0;
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;
static unsigned int cmps_cnt;
TCNT0 -= 101; // reload
Timer0Overflow++;
if(++cmps_cnt == 380)
{
PORTB |= 0x04;
cmps_cnt = 0;
}
else
if(cmps_cnt == PwmHeading)
{
PORTB &= ~0x04;
}
if(!--cnt)
{
cnt = 10;
CountMilliseconds += 1;
if(I2C_Timeout) I2C_Timeout--;
if(SIO_Timeout) SIO_Timeout--;
}
}
void Timer0_Init(void)
{
TCCR0B = TIMER_TEILER; // Starten des Timers
// TCNT0 = 100; // reload
TIM0_START;
TIMER2_INT_ENABLE;
}
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));
}