From f3b8b2d8e923a5f450a70b6f374a92f3b7012069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Sat, 12 Oct 2013 18:19:39 +0200 Subject: [PATCH] added UART methods --- src/Makefile | 5 ++++- src/main.c | 9 +++++++-- src/main.h | 3 +++ src/uart.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/uart.h | 10 ++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 src/main.h create mode 100644 src/uart.c create mode 100644 src/uart.h diff --git a/src/Makefile b/src/Makefile index 16b8f41..3845f3e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -19,7 +19,7 @@ PROGRAMMER=usbtiny #AVRDUDE=avrdude -p $(DEVICE) -P $(PORT) -c $(PROGRAMMER) FLASHER=avrdude -p $(DEVICE) -c $(PROGRAMMER) # source files to compile -SRC = main.c +SRC = main.c uart.c # object files. OBJ = $(SRC:.c=.o) # listing files. @@ -36,6 +36,9 @@ verify: exit 1; \ fi +reset: + $(FLASHER) + read-fuse: $(FLASHER) -U lfuse:r:lfuse.raw:r -U hfuse:r:hfuse.raw:r -U efuse:r:efuse.raw:r diff --git a/src/main.c b/src/main.c index a134969..97fdebc 100644 --- a/src/main.c +++ b/src/main.c @@ -5,12 +5,15 @@ #include /* AVR device-specific IO definitions */ #include /* Convenience functions for busy-wait delay loops */ -#define LED PD6 /* LED port */ - +#include "main.h" +#include "uart.h" static void ioinit(void) { DDRD = (1< /* Standard Integer Types */ +#include /* Standard IO facilities */ +#include /* General utilities */ +#include /* AVR device-specific IO definitions */ + +#include "uart.h" +#include /* Helper macros for baud rate calculations */ + +FILE uart_output = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE); +FILE uart_input = FDEV_SETUP_STREAM(NULL, uart_getchar, _FDEV_SETUP_READ); +FILE uart_io = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW); + +/* configure serial port */ +void uart_init(void) +{ + UBRR0H = UBRRH_VALUE; + UBRR0L = UBRRL_VALUE; +#if USE_2X + UCSR0A |= (1<