From: Michael Gernoth Date: Sun, 22 Aug 2010 14:16:14 +0000 (+0200) Subject: serial support X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/rsbs2/commitdiff_plain/d6f38d0dfc4f602a6c790fd470deb2b2fd23da77?hp=0ed4de5ebd3591b7a8fa527a0c41a2d1a349fef3 serial support --- diff --git a/bmc/.gitignore b/bmc/.gitignore new file mode 100644 index 0000000..1fcc48e --- /dev/null +++ b/bmc/.gitignore @@ -0,0 +1,3 @@ +bmc +bmc.bin +*.o diff --git a/bmc/Makefile b/bmc/Makefile index 2e566d0..7915e96 100644 --- a/bmc/Makefile +++ b/bmc/Makefile @@ -1,5 +1,5 @@ CC=avr-gcc -CFLAGS=-mmcu=atmega16 -g +CFLAGS=-mmcu=atmega16 -DF_CPU=8000000UL -Wall -g OBJCOPY=avr-objcopy PROG=dragon_jtag PORT=usb @@ -7,7 +7,7 @@ PMCU=m16 all: bmc.bin -bmc: bmc.o +bmc: bmc.o usart.o bmc.bin: bmc $(OBJCOPY) -j .text -j .data -O binary $^ $@ diff --git a/bmc/bmc.c b/bmc/bmc.c index 06a3829..a0387b3 100644 --- a/bmc/bmc.c +++ b/bmc/bmc.c @@ -1,24 +1,28 @@ -#define F_CPU 1000000UL - -#include - -int main(void) -{ - uint8_t pb = 0x00; - int8_t dir = 1; - volatile uint16_t i; - - DDRB = 0xff; - - while(1) { - pb += dir; - PORTB = pb; - - for (i = 0; i < (pb<<5); i++) {} - - if ((pb == 0) || (pb == 0xff)) - dir = -dir; - } - - return 0; -} +#include +#include +#include "usart.h" + +int main(void) +{ + uint8_t pb = 0x00; + int8_t dir = 1; + volatile uint16_t i; + + DDRB = 0xff; + + usart_init(); + + printf("Hallo!\n"); + + while(1) { + pb += dir; + PORTB = pb; + + for (i = 0; i < (pb<<5); i++) {} + + if ((pb == 0) || (pb == 0xff)) + dir = -dir; + } + + return 0; +} 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; +} diff --git a/bmc/usart.h b/bmc/usart.h new file mode 100644 index 0000000..d0ce4a5 --- /dev/null +++ b/bmc/usart.h @@ -0,0 +1,3 @@ +#define BAUD 9600UL + +void usart_init();