//press switch 1 ------ display 0 to 9 nos
//press switch 2 ------ display 9 to 0 nos
//press switch 3 ------ display even nos
//press switch 4 ------ display odd nos
//press switch 5 ------ display prime nos
#define DELAY 500000
void setup() {
// put your setup code here, to run once:
volatile char *dir1 = 0x30;
*dir1 = 0x00;
volatile char *dir2 = 0x107;
*dir2 = 0xff;
}
void loop() {
// put your main code here, to run repeatedly:
volatile long x,i,j,k;
volatile char *input;
input =0x2f;
volatile char *output;
output = 0x108;
volatile int arr1[]={0x01,0x02,0x04,0x08,0x10};
volatile int arr2[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
while(1)
{
for(k=0;k<6;k++)
{
x = *input;
if((x & arr1[k]) == arr1[k])
{
if(x == 0x01){ //press sw 1
for(j=0;j<10;j++)
{
*output = arr2[j]; //count 0 to 9
for(i=0;i<DELAY;i++);
}
}
if(x == 0x02){ //press sw 2
for(j=9;j>0;j--)
{
*output = arr2[j]; //display 9 t0 0
for(i=0;i<DELAY;i++);
}
}
if(x == 0x04){ //press sw 3
for(j=0;j<10;j++)
{
if(j%2 == 0) //display even nos
*output = arr2[j];
for(i=0;i<DELAY;i++);
}
}
if(x == 0x08){ //press sw 4
for(j=0;j<10;j++)
{
if(j%2 == 1) //display odd nos
*output = arr2[j];
for(i=0;i<DELAY;i++);
}
}
if(x == 0x10){ //press sw 5
volatile char prime,l;
for(j=2;j<10;j++)
{
prime =1;
for(l=2;l<(j-1);l++) //prime nos
{
if(j%l == 0)
{
prime =0;
break;
}
}
if(prime ==1)
{
*output = arr2[j];
for(i=0;i<DELAY;i++);
}
}
}
}
}
*output = 0;
}
}