diff options
| author | Vineet K <git@vineetk.net> | 2024-04-21 22:30:53 -0400 |
|---|---|---|
| committer | Shokara Kou <kou@13f0.net> | 2024-04-21 22:31:37 -0400 |
| commit | f61f9355daeb1ff28716f40087d7380c0b219713 (patch) | |
| tree | 08a0ffdded45d31bcde061356068252dafac3e90 | |
| parent | 4644a4b0ae20267b9692885b2bacc6b467b382ac (diff) | |
read lcd values from usart instead of random
| -rw-r--r-- | lcd.c | 38 |
1 files changed, 31 insertions, 7 deletions
| @@ -23,6 +23,35 @@ char notesBuffer[NOTES_BUFFER_SIZE]; | |||
| 23 | int serialIndex = 0; | 23 | int serialIndex = 0; |
| 24 | int notesIndex = 0; | 24 | int notesIndex = 0; |
| 25 | volatile int buttonState = 0; // Holds the state of all buttons | 25 | volatile int buttonState = 0; // Holds the state of all buttons |
| 26 | |||
| 27 | void | ||
| 28 | usart_init(void) | ||
| 29 | { | ||
| 30 | // 9600 bps, RX enabled | ||
| 31 | UBRR0 = 103; | ||
| 32 | UCSR0B = 1 << RXEN0; | ||
| 33 | UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); | ||
| 34 | } | ||
| 35 | |||
| 36 | char | ||
| 37 | getNote(void) | ||
| 38 | { | ||
| 39 | while (!(UCSR0A & (1 << RXC0))); | ||
| 40 | |||
| 41 | unsigned char c = UDR0; | ||
| 42 | |||
| 43 | // convert 0-9 to ascii character | ||
| 44 | if (c <= 9) | ||
| 45 | c += '0'; | ||
| 46 | // convert to capital hex | ||
| 47 | else if (c >= 0xa && c <= 0xf) | ||
| 48 | c = c - 0xa + 'A'; | ||
| 49 | // shift to rest of alphabet | ||
| 50 | else if (c >= 0x10) | ||
| 51 | c = c - 0x10 + 'G'; | ||
| 52 | |||
| 53 | return c; | ||
| 54 | } | ||
| 26 | // | 55 | // |
| 27 | void lcd_putValue(unsigned char val) | 56 | void lcd_putValue(unsigned char val) |
| 28 | { | 57 | { |
| @@ -111,11 +140,6 @@ char getSerialData() { | |||
| 111 | return ' '; | 140 | return ' '; |
| 112 | } | 141 | } |
| 113 | 142 | ||
| 114 | char getNote() { | ||
| 115 | // Read notes data and return it | ||
| 116 | return ' '; | ||
| 117 | } | ||
| 118 | |||
| 119 | void setup() { | 143 | void setup() { |
| 120 | // Initialize Serial communication | 144 | // Initialize Serial communication |
| 121 | // Initialize LCD | 145 | // Initialize LCD |
| @@ -154,7 +178,7 @@ void displayNotes() { | |||
| 154 | lcd_clear(); | 178 | lcd_clear(); |
| 155 | _delay_ms(1000); | 179 | _delay_ms(1000); |
| 156 | while (buttonState == 4) { | 180 | while (buttonState == 4) { |
| 157 | char randomValue = '0' + (rand() % 10); | 181 | char randomValue = getNote(); |
| 158 | 182 | ||
| 159 | if (bufferIndex == 16) { | 183 | if (bufferIndex == 16) { |
| 160 | // Remove the first value and shift other values down | 184 | // Remove the first value and shift other values down |
| @@ -196,7 +220,7 @@ void displaySerialData() { | |||
| 196 | lcd_clear(); | 220 | lcd_clear(); |
| 197 | _delay_ms(1000); | 221 | _delay_ms(1000); |
| 198 | while (buttonState == 5) { | 222 | while (buttonState == 5) { |
| 199 | char randomValue = '0' + (rand() % 10); | 223 | char randomValue = getNote(); |
| 200 | 224 | ||
| 201 | if (bufferIndex == 16) { | 225 | if (bufferIndex == 16) { |
| 202 | // Remove the first value and shift other values down | 226 | // Remove the first value and shift other values down |
