Added central hardware info and functions
This commit is contained in:
parent
d863aaad39
commit
38b63ddbdd
6
Hardware.h
Normal file
6
Hardware.h
Normal 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
34
hardware.cpp
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user