Hacker-Jeopardy/Mainboard_/Mainboard/rs232.c
2013-11-04 17:45:46 +00:00

38 lines
885 B
C

/*
* rs232.c
*
* Created: 06.10.2013 16:34:27
* Author: netz
*/
#include "config.h"
#include <stdio.h>
#include <avr/io.h>
#include "rs232.h"
int uart_putchar(char c, FILE *stream);
static FILE rs232 = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
int uart_putchar(char c, FILE *stream)
{
if (c == '\n') {
uart_putchar('\r', stream); //Warten solange bis Zeichen gesendet wurde
}
loop_until_bit_is_set(UCSR1A, UDRE1); //Ausgabe des Zeichens
UDR1 = c;
return (0);
}
void init_rs232()
{
UCSR1C = (1 << UCSZ11) |(1 << UCSZ10); //8N1
UCSR1B |= /*(1<<RXEN1) | (1<<RXCIE1) | */ (1<<TXEN1); //Enable TXEN im Register UCR TX-Data Enable
UBRR1L = (F_CPU / (BAUD_RATE * 16L) - 1); //Teiler wird gesetzt
stdout = &rs232; //öffnet einen Kanal für printf (STDOUT)
}
void rs232_send(char * text) {
fprintf(&rs232, text);
}