diff --git a/USART.c b/USART.c
new file mode 100644
index 0000000..875933b
--- /dev/null
+++ b/USART.c
@@ -0,0 +1,55 @@
+/**
+ * (C) Copyright Collin J. Doering 2015
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+*/
+
+/**
+ * File: USART.c
+ * Author: Collin J. Doering
+ * Date: Oct 6, 2015
+ */
+
+#include
+#include "USART.h"
+#include
+
+#ifndef BAUD /* if not defined in Makefile... */
+#define BAUD 9600 /* set a safe default baud rate */
+#endif
+
+void initUSART(void) { /* requires BAUD */
+ UBRR0H = UBRRH_VALUE; /* defined in setbaud.h */
+ UBRR0L = UBRRL_VALUE;
+#if USE_2X
+ UCSR0A |= (1 << U2X0);
+#else
+ UCSR0A &= ~(1 << U2X0);
+#endif
+ /* Enable USART transmitter/receiver */
+ UCSR0B = (1 << TXEN0) | (1 << RXEN0);
+ UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); /* 8 data bits, 1 stop bit */
+}
+
+
+void transmitByte(uint8_t data) {
+ /* Wait for empty transmit buffer */
+ loop_until_bit_is_set(UCSR0A, UDRE0);
+ UDR0 = data; /* send data */
+}
+
+uint8_t receiveByte(void) {
+ loop_until_bit_is_set(UCSR0A, RXC0); /* Wait for incoming data */
+ return UDR0; /* return register value */
+}
diff --git a/USART.h b/USART.h
new file mode 100644
index 0000000..170e7ce
--- /dev/null
+++ b/USART.h
@@ -0,0 +1,28 @@
+/**
+ * (C) Copyright Collin J. Doering 2015
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+*/
+
+/**
+ * File: USART.h
+ * Author: Collin J. Doering
+ * Date: Oct 6, 2015
+ */
+
+void initUSART(void);
+
+void transmitByte(uint8_t data);
+
+uint8_t receiveByte(void);
diff --git a/lcdOutput.c b/lcdOutput.c
index 2e1081c..34219cf 100644
--- a/lcdOutput.c
+++ b/lcdOutput.c
@@ -31,27 +31,38 @@
#include
#include "lcdLib.h"
+#include "USART.h"
+
+void showSomePrases(void) {
+ const char* data[4] = { "Hello there friend!!\nIsn't it a nice day.\nAnyways, I must go..\nTo a midnight show;)",
+ "This is some other text. It should be wrapped appropriately.\nIsn't that neat!",
+ "Welcome! (line 1)\nThis is line 2.\nAnd here is line 3.\nAnd finally, line 4.",
+ "Finally, this is the\nend; of the array,\nthat is.\nCheers."};
+
+ for (uint8_t i = 0; i < 4; i++) {
+ writeStringToLCD(data[i]);
+ _delay_ms(5000);
+ clearDisplay();
+ }
+ _delay_ms(3000);
+}
int main(void) {
clock_prescale_set(clock_div_1);
STATUS_LED_DDR |= 1 << STATUS_LED; // DEBUG
- const char* data[4] = { "Hello there friend!!\nIsn't it a nice day.\nAnyways, I must go..\nTo a midnight show;)",
- "This is some other text. It should be wrapped appropriately.\nIsn't that neat!",
- "Welcome! (line 1)\nThis is line 2.\nAnd here is line 3.\nAnd finally, line 4.",
- "Finally, this is the\nend; of the array,\nthat is.\nCheers."};
+ initUSART();
+ char serialChar;
initLCD();
//initLCDByInternalReset();
-
+
+ showSomePrases();
+
while (1) {
- for (uint8_t i = 0; i < 4; i++) {
- writeStringToLCD(data[i]);
- _delay_ms(10000);
- clearDisplay();
- }
- _delay_ms(3000);
+ serialChar = receiveByte();
+ writeCharToLCD(serialChar);
}
return 0;