CC=avr-gcc
-CFLAGS=-mmcu=atmega16 -g
+CFLAGS=-mmcu=atmega16 -DF_CPU=8000000UL -Wall -g
OBJCOPY=avr-objcopy
PROG=dragon_jtag
PORT=usb
all: bmc.bin
-bmc: bmc.o
+bmc: bmc.o usart.o
bmc.bin: bmc
$(OBJCOPY) -j .text -j .data -O binary $^ $@
-#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;
+}
--- /dev/null
+#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;
+}