#define DELAY 10000
volatile long i;
volatile char *outf, *outk, *outa, *outc;
unsigned int digit[10] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; // Patterns for 0-9
unsigned int Digit[10] = { 0xbf, 0x86, 0xdb, 0xcf, 0xe6, 0xed, 0xfd, 0x87, 0xff, 0xef};
unsigned int rdigit[10]= {0x6f,0x7f,0x07,0x7d,0x6d,0x66,0x4f,0x5b,0x06,0x3f};
void setup() {
// Initialize direction registers (set them as output)
volatile char *dirf, *dirk, *dira, *dirc;
dirf = (volatile char *)0x030;
dirk = (volatile char *)0x107;
dira = (volatile char *)0x021;
dirc = (volatile char *)0x027;
*dirf = 0xff;
*dirk = 0xff;
*dira = 0xff;
*dirc = 0xff;
// Initialize output pointers
outf = (volatile char *)0x031;
outk = (volatile char *)0x108;
outa = (volatile char *)0x022;
outc = (volatile char *)0x028;
}
void loop() {
int number;
// Loop from 0000 to 9999
//for (number = 0; number <= 60; number++) {
clock(number); // Display the current number on the 7-segment display
delay1(); // Delay to allow the number to be visible
//}
}
void delay1(void) {
volatile long j;
for (j = 0; j < DELAY; j++);
}
void clock(int number) {
int thousands, hundreds, tens, units,i,count=0;
// int displaystarted=0;
// Extract each digit from the number
// thousands = (number / 1000) % 10;
//hundreds = (number / 100) % 10;
//tens = (number / 10) % 10;
//units = number % 10;
for(number=0;number<=60;number++){
thousands=number%10;
*outk=digit[thousands];
activateDigit(4);
delay1();
hundreds=number/10;
*outf=digit[hundreds];
delay1();
for(i=0;i<=60;i++){
tens=i/10;
*outa=digit[tens];
activateDigit(2);
delay1();
units=i%10;
*outc=digit[units];
activateDigit(1);
delay1();
}
}
//thousands=(number/1000)%10;
//*outf=digit[thousands];
//activateDigit(4);
//delay1();
//hundreds=(number/100)%10;
//*outk=digit[hundreds];
//delay1();
}
// Display each digit on the corresponding 7-segment display
//if(thousands!=0){
//*outf = digit[thousands]; // Display thousands
//activateDigit(4); // Activate the digit 1 (thousands)
//delay1(); // Short delay
// displaystarted=1;
//}
//if(hundreds!=0||displaystarted){
//*outk = digit[hundreds]; // Display hundreds
//activateDigit(3); // Activate the digit 2 (hundreds)
//delay1(); // Short delay
//displaystarted=1;
//}
//if(tens!=0||displaystarted){
//*outa = Digit[tens]; // Display tens
//activateDigit(2); // Activate the digit 3 (tens)
//delay1(); // Short delay
//displaystarted=1;
//}
// *outc = digit[units]; // Display units
//activateDigit(1); // Activate the digit 4 (units)
//delay1(); // Short delay
//}
void activateDigit(int digitPosition) {
// Assuming digit position corresponds to the digit selector lines
// This is hardware-dependent; below is a hypothetical example
switch(digitPosition) {
case 1:
// Code to activate the first digit (thousands)
// E.g., setting certain control lines to activate the first digit
break;
case 2:
// Code to activate the second digit (hundreds)
break;
case 3:
// Code to activate the third digit (tens)
break;
case 4:
// Code to activate the fourth digit (units)
break;
}
}