git-svn-id: http://moon:8086/svn/projects/HendiControl@21 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
2019-02-20 20:01:04 +00:00
parent 21dacf4be6
commit a794460fdc
14 changed files with 446 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
/*
* uart.c
*
* Created: 20.02.2019 20:50:13
* Author: jens
*/
#include <avr/io.h>
#include <stdio.h>
#include "uart.h"
void uart_init(uint16_t BAUD_PRESCALE)
{
// Set baud rate
UBRR0L = (uint8_t)BAUD_PRESCALE;
UBRR0H = (uint8_t)(BAUD_PRESCALE >> 8);
// Enable receiver and transmitter
UCSR0B = (1<<TXEN0)|(1<<RXEN0);
// Enable RX interrupt
UCSR0B |= (1<<RXCIE0);
}
void uart_putc(char c)
{
while((UCSR0A & (1<<UDRE0)) == 0)
{
}
UDR0 = c;
}
int uart_putchar(char c, FILE *stream)
{
uart_putc(c);
if (c == 0x0A)
{
uart_putc(0x0D);
}
return 0;
}
void uart_puts(char const *str)
{
while(*str)
{
char c = *(str++);
uart_putc(c);
if (c == 0x0A)
{
uart_putc(0x0D);
}
}
}