void setup() {
// Set all pins on PORTK as outputs for digit control
DDRK = 0xFF;
// Set all pins on PORTA as outputs for segments (assuming the 7-segment display is connected to PORTA)
DDRF = 0xFF;
}
void displayDigit(volatile char *buto, unsigned int digitValue, bool isTens) {
unsigned char digit[] = {
0x3F, // 0
0x06, // 1
0x5B, // 2
0x4F, // 3
0x66, // 4
0x6D, // 5
0x7D, // 6
0x07, // 7
0x7F, // 8
0x6F // 9
};
unsigned int j;
if (isTens) {
PORTK &= ~(1 << PK0); // Activate tens digit (e.g., clear PK1)
//for(j=0;j<10000;j++);
PORTK |= (1 << PK1); // Deactivate unit digit (e.g., set PK0)
} else {
PORTK &= ~(1 << PK1); // Activate unit digit (e.g., clear PK0)
for(j=0;j<100000;j++);
PORTK |= (1 << PK0); // Deactivate tens digit (e.g., set PK1)
}
*buto = digit[digitValue]; // Set the segments for the digit
delay(5); // Short delay for stable display (5ms is generally enough)
}
void loop() {
volatile char *buto = (volatile char *)0x31; // Address of PORTA (for segments)
unsigned int number = 47; // Example number to display
unsigned int unit = number % 10; // Get the unit digit
unsigned int tens = number / 10; // Get the tens digit
// Continuously switch between the tens and unit digits
while (true) {
displayDigit(buto, tens, true);
// Display the tens digit
displayDigit(buto, unit, false);
delay(1500);// Display the unit digit
}
}