]> git.zerfleddert.de Git - rsbs2/commitdiff
serial support
authorMichael Gernoth <michael@gernoth.net>
Sun, 22 Aug 2010 14:16:14 +0000 (16:16 +0200)
committerMichael Gernoth <michael@gernoth.net>
Sun, 22 Aug 2010 14:16:14 +0000 (16:16 +0200)
bmc/.gitignore [new file with mode: 0644]
bmc/Makefile
bmc/bmc.c
bmc/usart.c [new file with mode: 0644]
bmc/usart.h [new file with mode: 0644]

diff --git a/bmc/.gitignore b/bmc/.gitignore
new file mode 100644 (file)
index 0000000..1fcc48e
--- /dev/null
@@ -0,0 +1,3 @@
+bmc
+bmc.bin
+*.o
index 2e566d010a9bc26de5b40e399168471b0376c75c..7915e96f99e531b36d9b55b2513dae1b78d6cc92 100644 (file)
@@ -1,5 +1,5 @@
 CC=avr-gcc
 CC=avr-gcc
-CFLAGS=-mmcu=atmega16 -g
+CFLAGS=-mmcu=atmega16 -DF_CPU=8000000UL -Wall -g
 OBJCOPY=avr-objcopy
 PROG=dragon_jtag
 PORT=usb
 OBJCOPY=avr-objcopy
 PROG=dragon_jtag
 PORT=usb
@@ -7,7 +7,7 @@ PMCU=m16
 
 all: bmc.bin
 
 
 all: bmc.bin
 
-bmc: bmc.o
+bmc: bmc.o usart.o
 
 bmc.bin: bmc
        $(OBJCOPY) -j .text -j .data -O binary $^ $@
 
 bmc.bin: bmc
        $(OBJCOPY) -j .text -j .data -O binary $^ $@
index 06a38290da134ec7f51e1ff00f3ec14a090f1a2d..a0387b339721c1b68f5fd6c907598afd617d5006 100644 (file)
--- a/bmc/bmc.c
+++ b/bmc/bmc.c
@@ -1,24 +1,28 @@
-#define F_CPU 1000000UL\r
-\r
-#include <avr/io.h>\r
-\r
-int main(void)\r
-{\r
-       uint8_t pb = 0x00;\r
-       int8_t dir = 1;\r
-       volatile uint16_t i;\r
-\r
-       DDRB = 0xff;\r
-\r
-       while(1) {\r
-               pb += dir;\r
-               PORTB = pb;\r
-\r
-               for (i = 0; i < (pb<<5); i++) {}\r
-\r
-               if ((pb == 0) || (pb == 0xff))\r
-                       dir = -dir;\r
-       }\r
-\r
-       return 0;\r
-}\r
+#include <avr/io.h>
+#include <stdio.h>
+#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 (file)
index 0000000..36ba83c
--- /dev/null
@@ -0,0 +1,35 @@
+#include <avr/io.h>
+#include <stdio.h>
+
+#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<<UDRE))) {}
+       UDR = c;
+       return 0;
+}
+
+static FILE usart_stdout = FDEV_SETUP_STREAM(usart_put, NULL, _FDEV_SETUP_WRITE);
+
+void usart_init()
+{
+       UCSRB |= (1<<TXEN);
+       UCSRC |= (1<<URSEL)|(1 << UCSZ1)|(1 << UCSZ0);
+
+       UBRRH = UBRR_VAL >> 8;
+       UBRRL = UBRR_VAL & 0xFF;
+
+       stdout = &usart_stdout;
+}
diff --git a/bmc/usart.h b/bmc/usart.h
new file mode 100644 (file)
index 0000000..d0ce4a5
--- /dev/null
@@ -0,0 +1,3 @@
+#define BAUD 9600UL
+
+void usart_init();
Impressum, Datenschutz