read lcd values from usart instead of random

This commit is contained in:
Vineet K 2024-04-21 22:30:53 -04:00 committed by Shokara Kou
parent 4644a4b0ae
commit f61f9355da

38
lcd.c
View File

@ -23,6 +23,35 @@ char notesBuffer[NOTES_BUFFER_SIZE];
int serialIndex = 0; int serialIndex = 0;
int notesIndex = 0; int notesIndex = 0;
volatile int buttonState = 0; // Holds the state of all buttons 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) void lcd_putValue(unsigned char val)
{ {
@ -111,11 +140,6 @@ char getSerialData() {
return ' '; return ' ';
} }
char getNote() {
// Read notes data and return it
return ' ';
}
void setup() { void setup() {
// Initialize Serial communication // Initialize Serial communication
// Initialize LCD // Initialize LCD
@ -154,7 +178,7 @@ void displayNotes() {
lcd_clear(); lcd_clear();
_delay_ms(1000); _delay_ms(1000);
while (buttonState == 4) { while (buttonState == 4) {
char randomValue = '0' + (rand() % 10); char randomValue = getNote();
if (bufferIndex == 16) { if (bufferIndex == 16) {
// Remove the first value and shift other values down // Remove the first value and shift other values down
@ -196,7 +220,7 @@ void displaySerialData() {
lcd_clear(); lcd_clear();
_delay_ms(1000); _delay_ms(1000);
while (buttonState == 5) { while (buttonState == 5) {
char randomValue = '0' + (rand() % 10); char randomValue = getNote();
if (bufferIndex == 16) { if (bufferIndex == 16) {
// Remove the first value and shift other values down // Remove the first value and shift other values down