void setup() {
// Set up the direction register and output register pointers
volatile char *dir, *dirk, *ink, *outf;
dir = (volatile char *) 0x30; // Data direction register for output (7-segment)
dirk = (volatile char *) 0x107; // Data direction register for switch
ink = (volatile char *) 0x106; // Input register (switch input)
outf = (volatile char *) 0x31; // Output register for 7-segment display
*dir = 0xFF; // Set the 7-segment display port as output
*dirk = 0x00; // Set the switch port as input
}
void loop() {
volatile char *ink = (volatile char *) 0x106; // Input register (switch input)
volatile char *outf = (volatile char *) 0x31; // Output register (7-segment display)
// Array holding the 7-segment values for numbers 0 to 9
char segmentMap[10] = {
0x3F, // 0
0x06, // 1
0x5B, // 2
0x4F, // 3
0x66, // 4
0x6D, // 5
0x7D, // 6
0x07, // 7
0x7F, // 8
0x6F // 9
};
for (int i = 0; i < 10; i++) { // Traverse numbers 0 to 9
*outf = segmentMap[i]; // Set the 7-segment display to show the digit
// Large delay to observe the change
for (long n = 0; n < 5000000; n++);
}
}