Commits

Trammell Hudson  committed 3e2baf8

morse works

  • Participants
  • Parent commits cd6ce7c

Comments (0)

Files changed (1)

 void morse_P(const char *s);
 const unsigned char morse_code_table[];
 
+void
+put_hexchar(
+	unsigned c
+)
+{
+	c &= 0xF;
+	pchar(c <= 9 ? c + '0' : c + 'A' - 0xA);
+}
+
 
 int main(void)
 {
-	unsigned char i;
-
 	// set for 16 MHz clock, and make sure the LED is off
 	CPU_PRESCALE(0);
 	LED_CONFIG;
 	// but we care more about blinking than debug messages!
 	usb_init();
 
-	// blink morse code messages!
-	while (1) {
-		for (i=0; i<6; i++) {
-			morse_P(PSTR("SOS"));
-			_delay_ms(1500);
-		}
-		morse_P(PSTR("DOES ANYBODY STILL KNOW MORSE CODE?"));
-		_delay_ms(4000);
+	LED_ON;
+
+	// Set the port to 31.25 K-baud, 1 start, 8 data, 1 parity
+	UBRR1H = 0;
+	UBRR1L = 28;
+	UCSR1B = 1 << RXEN1;
+	UCSR1C = (0 << UCSZ12) | (1 << UCSZ11) | (1 << UCSZ10);
+
+	print("waiting for data\n");
+
+	while (1)
+	{
+		if (!(UCSR1A & (1 << RXC1)))
+			continue;
+		LED_ON;
+		unsigned c = UDR1;
+		put_hexchar(c >> 4);
+		put_hexchar(c >> 0);
+		pchar('\n');
+		LED_OFF;
 	}
 }
 
+
 // blink a single character in Morse code
 void morse_character(char c)
 {