20141119-235733
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Comperator.hpp
|
||||
*
|
||||
* Created: 17.11.2014 23:50:04
|
||||
* Author: netz
|
||||
*/
|
||||
|
||||
|
||||
#ifndef COMPERATOR_H_
|
||||
#define COMPERATOR_H_
|
||||
|
||||
#include "hardware/pin.hpp"
|
||||
|
||||
template <typename Port, int pin_ain0, int pin_ain1>
|
||||
class Comperator {
|
||||
public:
|
||||
Comperator() {
|
||||
init();
|
||||
}
|
||||
uint8_t is_active() {
|
||||
return ACSR & (1<<ACO);
|
||||
}
|
||||
private:
|
||||
void init() {
|
||||
comppin0::make_input();
|
||||
comppin1::make_input();
|
||||
init_comperator();
|
||||
}
|
||||
void init_comperator() {
|
||||
// Analog Comparator initialization
|
||||
// Analog Comparator: On
|
||||
// The Analog Comparator's positive input is
|
||||
// connected to the AIN0 pin
|
||||
// The Analog Comparator's negative input is
|
||||
// connected to the AIN1 pin
|
||||
// Analog Comparator Input Capture by Timer/Counter 1: Off
|
||||
ACSR=(0<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIC) | (0<<ACIS1) | (0<<ACIS0);
|
||||
ADCSRB=(0<<ACME);
|
||||
// Digital input buffer on AIN0: Off
|
||||
// Digital input buffer on AIN1: Off
|
||||
DIDR1=(1<<AIN0D) | (1<<AIN1D);
|
||||
}
|
||||
const typedef avrlib::pin<Port, pin_ain0> comppin0;
|
||||
const typedef avrlib::pin<Port, pin_ain1> comppin1;
|
||||
};
|
||||
|
||||
#endif /* COMPERATOR_H_ */
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Interrupt.hpp
|
||||
*
|
||||
* Created: 18.11.2014 00:27:52
|
||||
* Author: netz
|
||||
*/
|
||||
|
||||
|
||||
#ifndef INTERRUPT_H_
|
||||
#define INTERRUPT_H_
|
||||
|
||||
template <typename Port, int pin_int>
|
||||
class Interrupt {
|
||||
public:
|
||||
Interrupt() {
|
||||
init();
|
||||
}
|
||||
uint8_t is_active() {
|
||||
return intpin::read();
|
||||
}
|
||||
private:
|
||||
void init() {
|
||||
intpin::make_input();
|
||||
intpin::pullup();
|
||||
init_int();
|
||||
}
|
||||
void init_int() {
|
||||
// External Interrupt(s) initialization
|
||||
// INT0: On
|
||||
// INT0 Mode: Rising Edge
|
||||
// INT1: Off
|
||||
// Interrupt on any change on pins PCINT0-7: Off
|
||||
// Interrupt on any change on pins PCINT8-14: Off
|
||||
// Interrupt on any change on pins PCINT16-23: Off
|
||||
EICRA=(0<<ISC11) | (0<<ISC10) | (0<<ISC01) | (1<<ISC00);
|
||||
EIMSK=(0<<INT1) | (1<<INT0);
|
||||
EIFR=(0<<INTF1) | (1<<INTF0);
|
||||
}
|
||||
const typedef avrlib::pin<Port, pin_int> intpin;
|
||||
};
|
||||
|
||||
#endif /* INTERRUPT_H_ */
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Led.h
|
||||
*
|
||||
* Created: 03.11.2013 17:11:58
|
||||
* Author: BlubbFish
|
||||
*/
|
||||
|
||||
#ifndef LED_H_
|
||||
#define LED_H_
|
||||
|
||||
#include "hardware/pin.hpp"
|
||||
|
||||
template <typename Port, int pin_red, int pin_green>
|
||||
class Led {
|
||||
public:
|
||||
Led() {
|
||||
init();
|
||||
}
|
||||
void red(uint8_t r) {
|
||||
if(r==1) {
|
||||
ledred::set();
|
||||
} else {
|
||||
ledred::clear();
|
||||
}
|
||||
}
|
||||
void green(uint8_t g) {
|
||||
if(g==1) {
|
||||
ledgreen::set();
|
||||
} else {
|
||||
ledgreen::clear();
|
||||
}
|
||||
}
|
||||
void off() {
|
||||
ledred::clear();
|
||||
ledgreen::clear();
|
||||
}
|
||||
private:
|
||||
void init() {
|
||||
ledred::make_output();
|
||||
ledgreen::make_output();
|
||||
off();
|
||||
}
|
||||
const typedef avrlib::pin<Port, pin_red> ledred;
|
||||
const typedef avrlib::pin<Port, pin_green> ledgreen;
|
||||
};
|
||||
|
||||
#endif /* LED_H_ */
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Led.h
|
||||
*
|
||||
* Created: 03.11.2013 17:11:58
|
||||
* Author: BlubbFish
|
||||
*/
|
||||
|
||||
#ifndef STRIPE_H_
|
||||
#define STRIPE_H_
|
||||
|
||||
#include "hardware/pin.hpp"
|
||||
|
||||
template <typename PortR, int pin_red, typename PortG, int pin_green, typename PortB, int pin_blue>
|
||||
class Stripe {
|
||||
public:
|
||||
Stripe() {
|
||||
init();
|
||||
}
|
||||
void color(uint8_t r, uint8_t g, uint8_t b) {
|
||||
OCR0B=r; //ROT
|
||||
OCR2B=g; //GRÜN
|
||||
OCR2A=b; //BLAU
|
||||
}
|
||||
void setcolor(uint8_t mask) {
|
||||
(mask & (1<<0)) ? OCR2A=0xFF : OCR2A=0x00;
|
||||
(mask & (1<<1)) ? OCR2B=0xFF : OCR2B=0x00;
|
||||
(mask & (1<<2)) ? OCR0B=0xFF : OCR0B=0x00;
|
||||
}
|
||||
static const uint8_t BLACK = 0;
|
||||
static const uint8_t BLUE = 1;
|
||||
static const uint8_t GREEN = 2;
|
||||
static const uint8_t CYAN = 3;
|
||||
static const uint8_t RED = 4;
|
||||
static const uint8_t MAGENTA = 5;
|
||||
static const uint8_t YELLOW = 6;
|
||||
static const uint8_t WHITE = 7;
|
||||
private:
|
||||
void init() {
|
||||
stripered::make_output();
|
||||
stripegreen::make_output();
|
||||
stripeblue::make_output();
|
||||
initTimer();
|
||||
color(0, 0, 0);
|
||||
}
|
||||
void uninit();
|
||||
void initTimer() {
|
||||
// Timer/Counter 0 initialization
|
||||
// Clock source: System Clock
|
||||
// Clock value: 8000,000 kHz
|
||||
// Mode: Phase correct PWM top=0xFF
|
||||
// OC0A output: Disconnected
|
||||
// OC0B output: Non-Inverted PWM
|
||||
// Timer Period: 0,06375 ms
|
||||
// Output Pulse(s):
|
||||
// OC0B Period: 0,06375 ms Width: 0 us
|
||||
TCCR0A=(0<<COM0A1) | (0<<COM0A0) | (1<<COM0B1) | (0<<COM0B0) | (0<<WGM01) | (1<<WGM00);
|
||||
TCCR0B=(0<<WGM02) | (0<<CS02) | (0<<CS01) | (1<<CS00);
|
||||
TCNT0=0x00;
|
||||
// Timer/Counter 2 initialization
|
||||
// Clock source: System Clock
|
||||
// Clock value: 8000,000 kHz
|
||||
// Mode: Phase correct PWM top=0xFF
|
||||
// OC2A output: Non-Inverted PWM
|
||||
// OC2B output: Non-Inverted PWM
|
||||
// Timer Period: 0,06375 ms
|
||||
// Output Pulse(s):
|
||||
// OC2A Period: 0,06375 ms Width: 0 us
|
||||
// OC2B Period: 0,06375 ms Width: 0 us
|
||||
ASSR=(0<<EXCLK) | (0<<AS2);
|
||||
TCCR2A=(1<<COM2A1) | (0<<COM2A0) | (1<<COM2B1) | (0<<COM2B0) | (0<<WGM21) | (1<<WGM20);
|
||||
TCCR2B=(0<<WGM22) | (0<<CS22) | (0<<CS21) | (1<<CS20);
|
||||
TCNT2=0x00;
|
||||
// Timer/Counter 0 Interrupt(s) initialization
|
||||
TIMSK0=(0<<OCIE0B) | (0<<OCIE0A) | (0<<TOIE0);
|
||||
// Timer/Counter 2 Interrupt(s) initialization
|
||||
TIMSK2=(0<<OCIE2B) | (0<<OCIE2A) | (0<<TOIE2);
|
||||
}
|
||||
const typedef avrlib::pin<PortR, pin_red> stripered;
|
||||
const typedef avrlib::pin<PortG, pin_green> stripegreen;
|
||||
const typedef avrlib::pin<PortB, pin_blue> stripeblue;
|
||||
};
|
||||
#endif /* STRIPE_H_ */
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef AVRLIB_PIN_HPP
|
||||
#define AVRLIB_PIN_HPP
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
namespace avrlib {
|
||||
|
||||
template <typename Port, uint8_t Pin>
|
||||
struct pin
|
||||
{
|
||||
static void set(bool value = true)
|
||||
{
|
||||
if (value)
|
||||
Port::port(Port::port() | (1<<Pin));
|
||||
else
|
||||
Port::port(Port::port() & ~(1<<Pin));
|
||||
}
|
||||
|
||||
static void clear() { set(false); }
|
||||
|
||||
static void toggle() { Port::port(Port::port() ^ (1<<Pin)); }
|
||||
|
||||
static bool get() { return (Port::port() & (1<<Pin)) != 0; }
|
||||
|
||||
static bool value() { return (Port::pin() & (1<<Pin)) != 0; }
|
||||
|
||||
static void output(bool value)
|
||||
{
|
||||
if (value)
|
||||
Port::dir(Port::dir() | (1<<Pin));
|
||||
else
|
||||
Port::dir(Port::dir() & ~(1<<Pin));
|
||||
}
|
||||
|
||||
static bool output() { return (Port::dir() & (1<<Pin)) != 0; }
|
||||
|
||||
static void make_output() { output(true); }
|
||||
static void make_input() { output(false); clear(); }
|
||||
static void make_low() { clear(); output(true); }
|
||||
static void make_high() { set(); output(true); }
|
||||
static void set_value(bool value) { set(value); }
|
||||
static void set_high() { set(true); }
|
||||
static void set_low() { set(false); }
|
||||
static bool read() { return value(); }
|
||||
static void pullup() { set_high(); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef AVRLIB_PORTB_HPP
|
||||
#define AVRLIB_PORTB_HPP
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
namespace avrlib {
|
||||
|
||||
struct portb
|
||||
{
|
||||
static uint8_t port() { return PORTB; }
|
||||
static void port(uint8_t v) { PORTB = v; }
|
||||
|
||||
static uint8_t pin() { return PINB; }
|
||||
static void pin(uint8_t v) { PINB = v; }
|
||||
|
||||
static uint8_t dir() { return DDRB; }
|
||||
static void dir(uint8_t v) { DDRB = v; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef AVRLIB_PORTD_HPP
|
||||
#define AVRLIB_PORTD_HPP
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
namespace avrlib {
|
||||
|
||||
struct portd
|
||||
{
|
||||
static uint8_t port() { return PORTD; }
|
||||
static void port(uint8_t v) { PORTD = v; }
|
||||
|
||||
static uint8_t pin() { return PIND; }
|
||||
static void pin(uint8_t v) { PIND = v; }
|
||||
|
||||
static uint8_t dir() { return DDRD; }
|
||||
static void dir(uint8_t v) { DDRD = v; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Rs232.h
|
||||
*
|
||||
* Created: 04.11.2013 21:31:09
|
||||
* Author: netz
|
||||
*/
|
||||
|
||||
#ifndef RS232_H_
|
||||
#define RS232_H_
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
template <uint32_t baudrate>
|
||||
class Uart {
|
||||
public:
|
||||
Uart() {
|
||||
sei();
|
||||
init();
|
||||
println("Uart done!");
|
||||
}
|
||||
void print(const char *text) {
|
||||
while (*text)
|
||||
{
|
||||
uart_putchar(*text);
|
||||
text++;
|
||||
}
|
||||
}
|
||||
void printDec(uint16_t wert) {
|
||||
print((wert/10000)+'0');
|
||||
print(((wert/1000)%10)+'0');
|
||||
print(((wert/100)%10)+'0');
|
||||
print(((wert/10)%10)+'0');
|
||||
print((wert%10)+'0');
|
||||
}
|
||||
void println(const char *text) {
|
||||
print(text);
|
||||
print("\r");
|
||||
print("\n");
|
||||
}
|
||||
void print(uint8_t wert) {
|
||||
uart_putchar(wert);
|
||||
}
|
||||
private:
|
||||
void init() {
|
||||
UBRR0L = (F_CPU / (baudrate * 16L) - 1); //Teiler wird gesetzt
|
||||
UCSR0A= (0<<RXC0) | (0<<TXC0) | (0<<UDRE0) | (0<<FE0) | (0<<DOR0) | (0<<UPE0) | (0<<U2X0) | (0<<MPCM0);
|
||||
UCSR0B= (0<<RXCIE0) | (0<<TXCIE0) | (0<<UDRIE0) | (0<<RXEN0) | (1<<TXEN0) | (0<<UCSZ02) | (0<<RXB80) | (0<<TXB80); //Enable TXEN im Register UCR TX-Data Enable
|
||||
UCSR0C= (0<<UMSEL01) | (0<<UMSEL00) | (0<<UPM01) | (0<<UPM00) | (0<<USBS0) | (1<<UCSZ01) | (1<<UCSZ00) | (0<<UCPOL0); //8N1
|
||||
}
|
||||
uint8_t uart_putchar(uint8_t c) {
|
||||
loop_until_bit_is_set(UCSR0A, UDRE0); //Ausgabe des Zeichens
|
||||
UDR0 = c;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* RS232_H_ */
|
||||
Reference in New Issue
Block a user