X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/rsbs2/blobdiff_plain/0ed4de5ebd3591b7a8fa527a0c41a2d1a349fef3..d6f38d0dfc4f602a6c790fd470deb2b2fd23da77:/bmc/usart.c diff --git a/bmc/usart.c b/bmc/usart.c new file mode 100644 index 0000000..36ba83c --- /dev/null +++ b/bmc/usart.c @@ -0,0 +1,35 @@ +#include +#include + +#include "usart.h" + +#define UBRR_VAL ((F_CPU+BAUD*8)/(BAUD*16)-1) +#define BAUD_REAL (F_CPU/(16*(UBRR_VAL+1))) +#define BAUD_ERROR ((BAUD_REAL*1000)/BAUD) + +#if ((BAUD_ERROR<990) || (BAUD_ERROR>1010)) +#error Systematischer Fehler der Baudrate grösser 1% und damit zu hoch! +#endif + +int usart_put(char c, FILE *stream) +{ + if (c == '\n') + usart_put('\r', stream); + + while(!(UCSRA & (1<> 8; + UBRRL = UBRR_VAL & 0xFF; + + stdout = &usart_stdout; +}