57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
/*
|
|
* Usart.hpp
|
|
*
|
|
* Created: 16.07.2016 12:58:49
|
|
* Author: netz
|
|
*/
|
|
|
|
|
|
#ifndef USART_H_
|
|
#define USART_H_
|
|
|
|
template <uint32_t baudrate, typename RSPort, int pin_rts, int pin_cts, int pin_pwren>
|
|
class Usart {
|
|
public:
|
|
Usart(ledclass l) {
|
|
init();
|
|
this->led = l;
|
|
send("Uart done!\n");
|
|
}
|
|
void send(const char *text) {
|
|
while (*text)
|
|
{
|
|
uart_putchar(*text);
|
|
text++;
|
|
}
|
|
}
|
|
void send(uint8_t wert) {
|
|
uart_putchar(wert);
|
|
}
|
|
int16_t readTemp() {
|
|
int16_t t = this->temp;
|
|
this->temp = -1;
|
|
return t;
|
|
}
|
|
private:
|
|
void init() {
|
|
UCSRA = 0;
|
|
UCSRB = (1<<TXEN);
|
|
UCSRC = (1<<URSEL) | (1<<UPM1) | (1<<UCSZ1) | (1<<UCSZ0); //8E1
|
|
UBRRH = 0;
|
|
UBRRL = (F_CPU / (baudrate * 16L) - 1);
|
|
}
|
|
uint8_t uart_putchar(uint8_t c) {
|
|
led.on(led.YELLOW);
|
|
loop_until_bit_is_set(UCSRA, UDRE); //Ausgabe des Zeichens
|
|
UDR = c;
|
|
led.off(led.YELLOW);
|
|
return 0;
|
|
}
|
|
ledclass led;
|
|
const typedef avrlib::pin<RSPort, pin_rts> rts;
|
|
const typedef avrlib::pin<RSPort, pin_cts> cts;
|
|
const typedef avrlib::pin<RSPort, pin_pwren> pwren;
|
|
int16_t temp = -1;
|
|
};
|
|
|
|
#endif /* USART_H_ */ |