Fix stupid displaytest bug

This commit is contained in:
zervo 2025-01-25 12:07:39 +01:00
parent 99c45c5650
commit b17bc8bbc9
4 changed files with 19 additions and 9 deletions

View file

@ -11,6 +11,7 @@
[env:ATmega1284P] [env:ATmega1284P]
platform = atmelavr platform = atmelavr
board = ATmega1284P board = ATmega1284P
debug_tool = simavr
framework = arduino framework = arduino
upload_protocol = custom upload_protocol = custom
upload_port = /dev/ttyACM0 upload_port = /dev/ttyACM0

View file

@ -22,8 +22,11 @@ void Display::write(uint8_t digit)
{ {
uint8_t pattern = _digitToPattern(digit); uint8_t pattern = _digitToPattern(digit);
// Write the pattern to PORTD // Shift the pattern to align with PD3PD6
PORTD = (PORTD & ~0x7F) | (pattern & 0x7F); // Mask out the lower 7 bits and set the correct pattern pattern <<= 3;
// Write the pattern to PORTD, preserving unrelated bits
PORTD = (PORTD & 0x87) | (pattern & 0x78); // Preserve bits 7, 20; update bits 63
} }
// Convert the digit (0-9) to the 4-bit pattern for the CD4511 // Convert the digit (0-9) to the 4-bit pattern for the CD4511

View file

@ -20,12 +20,16 @@ int main(void)
DDRB |= (1 << PB0) <-- as output DDRB |= (1 << PB0) <-- as output
*************************************************/ *************************************************/
// "Attempt" LEDs.
// Configured as output.
DDRA |= (1 << LED_T1); DDRA |= (1 << LED_T1);
DDRA |= (1 << LED_T2); DDRA |= (1 << LED_T2);
DDRA |= (1 << LED_T3); DDRA |= (1 << LED_T3);
DDRA |= (1 << LED_T4); DDRA |= (1 << LED_T4);
DDRA |= (1 << LED_T5); DDRA |= (1 << LED_T5);
// "Status" LEDs.
// Configured as output.
DDRC |= (1 << LED_LATE); DDRC |= (1 << LED_LATE);
DDRC |= (1 << LED_EARLY); DDRC |= (1 << LED_EARLY);
DDRC |= (1 << LED_COIN); DDRC |= (1 << LED_COIN);

View file

@ -42,13 +42,15 @@ void systest(void)
_delay_ms(1000); _delay_ms(1000);
// Create an instance of the CD4511 class // Create an instance of the CD4511 class
Display display(true); // Set inverse to false (or true if you need inverted logic) Display display(false); // Set inverse to false (or true if you need inverted logic)
display.update(1, 0); //display.update(1, 2);
// Display digits 0 to 9 in sequence //Display digits 0 to 9 in sequence
//for (uint8_t i = 0; i < 10; ++i) { for (uint8_t x = 0; x < 5; ++x) {
// display.update(1, i); // Write the current digit to the CD4511 for (uint8_t i = 0; i < 10; ++i) {
// _delay_ms(500); // Wait for 1 second before changing the digit display.update(x, i); // Write the current digit to the CD4511
//} _delay_ms(500); // Wait for 1 second before changing the digit
}
}
} }