void time_delay(void);
int main(void)
{
// Configure PORTS Direction PORTF to Output, PORTK to Input
volatile char *dirf, *dirk;
dirf = (char *) 0x30;
*dirf = 0xFF;
dirk = (char *) 0x107;
*dirk = 0x00;
// Setup input register of PORTK and output register of PORTF
volatile char *outf, *ink;
outf = (char*) 0x31;
ink = (char*) 0x106;
// Declare a volatile variable to store values read from PORTK
volatile char x = 0;
// Array containing seven segment values to display 0 to 9
unsigned char sev_seg[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D,
0x7D, 0x07, 0x7F, 0x67};
unsigned char size = (unsigned char) sizeof(sev_seg)/sizeof(sev_seg[0]);
volatile char i = size - 1;
while (1)
{
/* Initially display 9.
When switch 2 is pressed every time decrement by 1 */
if (i >= 0)
*outf = sev_seg[i];
else
i = size - 1;
x = *ink;
if (x & 0x02) // check if switch 2 is pressed. If true, decrement i
{
time_delay(); // delay for switch debouncing
i--;
}
}
}
void time_delay(void)
{
volatile long del = 0;
while (del++ < 100000);
}