Zeitschaltung/V6/Program/rfm12_rs232/Zeitschaltung_V6/io/uart.hpp
2014-05-21 16:10:07 +00:00

47 lines
860 B
C++

/*
* 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();
send("Uart done!\r\n");
}
void send(const char *text) {
while (*text)
{
uart_putchar(*text);
text++;
}
}
void send(uint8_t wert) {
uart_putchar(wert);
}
private:
void init() {
UBRRL = (F_CPU / (baudrate * 16L) - 1); //Teiler wird gesetzt
UCSRB = /*(1<<RXEN1) | (1<<RXCIE1) | */ (1<<TXEN); //Enable TXEN im Register UCR TX-Data Enable
UCSRC = (1<<URSEL) | (3<<UCSZ0); //8N1
}
uint8_t uart_putchar(uint8_t c) {
loop_until_bit_is_set(UCSRA, UDRE); //Ausgabe des Zeichens
UDR = c;
return 0;
}
};
#endif /* RS232_H_ */