hello: use serial
authorTero Marttila <terom@paivola.fi>
Wed, 24 Sep 2014 22:54:26 +0300
changeset 1 dc293f9aa873
parent 0 cae83b7bfcf4
child 2 2687fbd14fd9
hello: use serial
Makefile
src/hello.c
--- a/Makefile	Wed Sep 24 22:41:46 2014 +0300
+++ b/Makefile	Wed Sep 24 22:54:26 2014 +0300
@@ -6,6 +6,7 @@
 HEX = build/src/$(PROG).hex
 
 build/src/hello.elf: build/src/hello.o \
+	build/qmsk/src/serial.o \
 	build/qmsk/src/timer.o
 
 ##
--- a/src/hello.c	Wed Sep 24 22:41:46 2014 +0300
+++ b/src/hello.c	Wed Sep 24 22:54:26 2014 +0300
@@ -6,22 +6,36 @@
 #define DEBUG_PORT PORTB
 
 #include "debug.h"
+#include "serial.h"
 #include "timer.h"
 
 int main (void)
 {
     debug_init();
+    serial_init(SERIAL_BAUD_9600, SERIAL_PARITY_N, SERIAL_STOPBITS_1);
     timer_init();
 
     // init
+    char c = '.';
+    unsigned short timeout = 8000;
+
     debug_set();
     sei();
 
-    unsigned short timeout = 8000;
 
     // start
     while (true) {
-        timer_sleep(timeout);
+        if (timer_sleep(timeout)) {
+            c = '.';
+        } else if ((c = serial_read())) {
+
+        } else {
+            c = '?';
+        }
+
         debug_toggle();
+
+        // out
+        serial_write(c);
     }
 }