From f61f9355daeb1ff28716f40087d7380c0b219713 Mon Sep 17 00:00:00 2001 From: Vineet K Date: Sun, 21 Apr 2024 22:30:53 -0400 Subject: [PATCH] read lcd values from usart instead of random --- lcd.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/lcd.c b/lcd.c index 4dd6a88..5501d86 100644 --- a/lcd.c +++ b/lcd.c @@ -23,6 +23,35 @@ char notesBuffer[NOTES_BUFFER_SIZE]; int serialIndex = 0; int notesIndex = 0; volatile int buttonState = 0; // Holds the state of all buttons + +void +usart_init(void) +{ + // 9600 bps, RX enabled + UBRR0 = 103; + UCSR0B = 1 << RXEN0; + UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); +} + +char +getNote(void) +{ + while (!(UCSR0A & (1 << RXC0))); + + unsigned char c = UDR0; + + // convert 0-9 to ascii character + if (c <= 9) + c += '0'; + // convert to capital hex + else if (c >= 0xa && c <= 0xf) + c = c - 0xa + 'A'; + // shift to rest of alphabet + else if (c >= 0x10) + c = c - 0x10 + 'G'; + + return c; +} // void lcd_putValue(unsigned char val) { @@ -111,11 +140,6 @@ char getSerialData() { return ' '; } -char getNote() { - // Read notes data and return it - return ' '; -} - void setup() { // Initialize Serial communication // Initialize LCD @@ -154,7 +178,7 @@ void displayNotes() { lcd_clear(); _delay_ms(1000); while (buttonState == 4) { - char randomValue = '0' + (rand() % 10); + char randomValue = getNote(); if (bufferIndex == 16) { // Remove the first value and shift other values down @@ -196,7 +220,7 @@ void displaySerialData() { lcd_clear(); _delay_ms(1000); while (buttonState == 5) { - char randomValue = '0' + (rand() % 10); + char randomValue = getNote(); if (bufferIndex == 16) { // Remove the first value and shift other values down