diff options
Diffstat (limited to 'src/inc/uart')
| -rwxr-xr-x | src/inc/uart/uart.c | 47 | ||||
| -rwxr-xr-x | src/inc/uart/uart.h | 17 |
2 files changed, 64 insertions, 0 deletions
diff --git a/src/inc/uart/uart.c b/src/inc/uart/uart.c new file mode 100755 index 0000000..b2f1a59 --- /dev/null +++ b/src/inc/uart/uart.c | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | #include "uart.h" | ||
| 2 | |||
| 3 | /// // UART-Receiver... | ||
| 4 | /// ISR(USART_RXC_vect) | ||
| 5 | /// { | ||
| 6 | /// unsigned char buffer; | ||
| 7 | /// buffer = UDR; | ||
| 8 | /// if(uart_string.size == -1) return; | ||
| 9 | /// if(buffer == '\n') | ||
| 10 | /// { | ||
| 11 | /// uart_string.data[uart_string.size] = '\0'; | ||
| 12 | /// uart_string.size = -1; | ||
| 13 | /// } | ||
| 14 | /// else | ||
| 15 | /// { | ||
| 16 | /// uart_string.data[uart_string.size] = buffer; | ||
| 17 | /// if(++uart_string.size > STRING_SIZE) | ||
| 18 | /// { uart_string.size = 0; } | ||
| 19 | /// } | ||
| 20 | /// } | ||
| 21 | |||
| 22 | void uart_init() | ||
| 23 | { | ||
| 24 | /// uart_string.size = 0; | ||
| 25 | /// uart_string.data[0] = '\0'; | ||
| 26 | |||
| 27 | // activate UART TX // and RX... | ||
| 28 | UCSRB |= (1<<TXEN); // | (1<<RXEN) | (1<<RXCIE); | ||
| 29 | // Asynchron 8N1 ... | ||
| 30 | UCSRC |= (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0); | ||
| 31 | |||
| 32 | UBRRH = UBRRH_VALUE; | ||
| 33 | UBRRL = UBRRL_VALUE; | ||
| 34 | #if USE_2X | ||
| 35 | UCSRA |= (1 << U2X); | ||
| 36 | #else | ||
| 37 | UCSRA &= ~(1 << U2X); | ||
| 38 | #endif | ||
| 39 | } | ||
| 40 | |||
| 41 | void uart_putc(char c) | ||
| 42 | { | ||
| 43 | UDR = c; /* schreibt das Zeichen x auf die Schnittstelle */ | ||
| 44 | loop_until_bit_is_set(UCSRA, UDRE); | ||
| 45 | } | ||
| 46 | |||
| 47 | |||
diff --git a/src/inc/uart/uart.h b/src/inc/uart/uart.h new file mode 100755 index 0000000..6e24df5 --- /dev/null +++ b/src/inc/uart/uart.h | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | #ifndef UART_H | ||
| 2 | #define UART_H | ||
| 3 | #include <util/setbaud.h> | ||
| 4 | #include <avr/interrupt.h> | ||
| 5 | |||
| 6 | /// #define STRING_SIZE 32 | ||
| 7 | /// typedef struct | ||
| 8 | /// { | ||
| 9 | /// char data[STRING_SIZE]; | ||
| 10 | /// int8_t size; | ||
| 11 | /// } string; | ||
| 12 | /// volatile string uart_string; | ||
| 13 | |||
| 14 | void uart_init(); | ||
| 15 | void uart_putc(char c); | ||
| 16 | |||
| 17 | #endif | ||
