Fix stupid displaytest bug
This commit is contained in:
parent
99c45c5650
commit
b17bc8bbc9
4 changed files with 19 additions and 9 deletions
|
@ -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
|
||||||
|
|
|
@ -21,9 +21,12 @@ Display::Display(bool inverse)
|
||||||
void Display::write(uint8_t digit)
|
void Display::write(uint8_t digit)
|
||||||
{
|
{
|
||||||
uint8_t pattern = _digitToPattern(digit);
|
uint8_t pattern = _digitToPattern(digit);
|
||||||
|
|
||||||
|
// Shift the pattern to align with PD3–PD6
|
||||||
|
pattern <<= 3;
|
||||||
|
|
||||||
// Write the pattern to PORTD
|
// Write the pattern to PORTD, preserving unrelated bits
|
||||||
PORTD = (PORTD & ~0x7F) | (pattern & 0x7F); // Mask out the lower 7 bits and set the correct pattern
|
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
|
// Convert the digit (0-9) to the 4-bit pattern for the CD4511
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue