From b17bc8bbc955b36cf399e6f8430b192bfc011662 Mon Sep 17 00:00:00 2001 From: zervo Date: Sat, 25 Jan 2025 12:07:39 +0100 Subject: [PATCH] Fix stupid displaytest bug --- RKTNTSTRP-FIRMWARE/platformio.ini | 1 + RKTNTSTRP-FIRMWARE/src/display.cpp | 7 +++++-- RKTNTSTRP-FIRMWARE/src/main.cpp | 4 ++++ RKTNTSTRP-FIRMWARE/src/systest.cpp | 16 +++++++++------- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/RKTNTSTRP-FIRMWARE/platformio.ini b/RKTNTSTRP-FIRMWARE/platformio.ini index 00cf6a1..ac317b6 100644 --- a/RKTNTSTRP-FIRMWARE/platformio.ini +++ b/RKTNTSTRP-FIRMWARE/platformio.ini @@ -11,6 +11,7 @@ [env:ATmega1284P] platform = atmelavr board = ATmega1284P +debug_tool = simavr framework = arduino upload_protocol = custom upload_port = /dev/ttyACM0 diff --git a/RKTNTSTRP-FIRMWARE/src/display.cpp b/RKTNTSTRP-FIRMWARE/src/display.cpp index 5d28159..8b4d04f 100644 --- a/RKTNTSTRP-FIRMWARE/src/display.cpp +++ b/RKTNTSTRP-FIRMWARE/src/display.cpp @@ -21,9 +21,12 @@ Display::Display(bool inverse) void Display::write(uint8_t digit) { uint8_t pattern = _digitToPattern(digit); + + // Shift the pattern to align with PD3–PD6 + pattern <<= 3; - // Write the pattern to PORTD - PORTD = (PORTD & ~0x7F) | (pattern & 0x7F); // Mask out the lower 7 bits and set the correct pattern + // Write the pattern to PORTD, preserving unrelated bits + PORTD = (PORTD & 0x87) | (pattern & 0x78); // Preserve bits 7, 2–0; update bits 6–3 } // Convert the digit (0-9) to the 4-bit pattern for the CD4511 diff --git a/RKTNTSTRP-FIRMWARE/src/main.cpp b/RKTNTSTRP-FIRMWARE/src/main.cpp index e2b9bd1..b2748c4 100644 --- a/RKTNTSTRP-FIRMWARE/src/main.cpp +++ b/RKTNTSTRP-FIRMWARE/src/main.cpp @@ -20,12 +20,16 @@ int main(void) DDRB |= (1 << PB0) <-- as output *************************************************/ + // "Attempt" LEDs. + // Configured as output. DDRA |= (1 << LED_T1); DDRA |= (1 << LED_T2); DDRA |= (1 << LED_T3); DDRA |= (1 << LED_T4); DDRA |= (1 << LED_T5); + // "Status" LEDs. + // Configured as output. DDRC |= (1 << LED_LATE); DDRC |= (1 << LED_EARLY); DDRC |= (1 << LED_COIN); diff --git a/RKTNTSTRP-FIRMWARE/src/systest.cpp b/RKTNTSTRP-FIRMWARE/src/systest.cpp index 8beac7a..ced6d5b 100644 --- a/RKTNTSTRP-FIRMWARE/src/systest.cpp +++ b/RKTNTSTRP-FIRMWARE/src/systest.cpp @@ -42,13 +42,15 @@ void systest(void) _delay_ms(1000); // Create an instance of the CD4511 class - Display display(true); // Set inverse to false (or true if you need inverted logic) - display.update(1, 0); + Display display(false); // Set inverse to false (or true if you need inverted logic) + //display.update(1, 2); - // Display digits 0 to 9 in sequence - //for (uint8_t i = 0; i < 10; ++i) { - // display.update(1, i); // Write the current digit to the CD4511 - // _delay_ms(500); // Wait for 1 second before changing the digit - //} + //Display digits 0 to 9 in sequence + for (uint8_t x = 0; x < 5; ++x) { + for (uint8_t i = 0; i < 10; ++i) { + display.update(x, i); // Write the current digit to the CD4511 + _delay_ms(500); // Wait for 1 second before changing the digit + } + } } \ No newline at end of file