Added central hardware info and functions

This commit is contained in:
Michael Mandl 2017-02-24 21:46:29 +01:00
parent d863aaad39
commit 38b63ddbdd
2 changed files with 40 additions and 0 deletions

6
Hardware.h Normal file
View file

@ -0,0 +1,6 @@
#pragma once
#define F_CPU 1000000
void delay_ms(double delay);
void delay_us(double delay);

34
hardware.cpp Normal file
View file

@ -0,0 +1,34 @@
#include "hardware.h"
#include "avr/io.h"
void delay_ms(double delay)
{
// prescaler: 1024
TCCR0B = (1 << CS02) | (1 << CS00);
TCNT0 = 0;
while (TCNT0 <= delay)
{
if (TCNT0 >= 49)
{
delay -= 50;
TCNT0 = 0;
}
}
}
void delay_us(double delay)
{
// prescaler: 1
TCCR0B = (1 << CS00);
TCNT0 = 0;
while (TCNT0 <= delay)
{
if (TCNT0 >= 50)
{
delay -= 50;
TCNT0 = 0;
}
}
}