void setup()
{
volatile char *dirf,*outf;
volatile char *dirk,*ink;
dirf=0x30; outf=0x31;
dirk=0x107; ink=0x106;
*dirf=0xFF; *ink=0x00;
volatile char switches;
volatile long arr1[]={63,6,91,79,102,109,125,7,127};
volatile long arr2[]={0,1,2,4,8,16,32,64,128};
unsigned long sum=0,num,res[4];
volatile long i,j,k,l,n,m,p,q,add;
loop:while(1)
{
sum=0;
num=0;
*outf=0;
switches=*ink;
for(i=1;i<=8;i++)
{
if((switches & arr2[i]) == arr2[i])//enter 1st digit of number
{
res[0]=i;//store 1st digit in array
for(n=0;n<=50000;n++);//delay for debouncing
while(1)
{
switches=*ink;
for(j=1;j<=8;j++)
{
if((switches & arr2[j]) == arr2[j])//enter 2nd digit of number
{
res[1]=j;//store second digit in array
for(n=0;n<=50000;n++);//delay for debouncing
while(1)
{
switches=*ink;
for(k=1;k<=8;k++)
{
if((switches & arr2[k]) == arr2[k])//enter 3rd digit of number
{
res[2]=k;//store third digit in array
for(n=0;n<=50000;n++);//delay for debouncing
while(1)
{
switches=*ink;
for(l=1;l<=8;l++)
{
if((switches & arr2[l]) == arr2[l])//enter 4th digit of number
{
res[3]=l;//store fourth digit in array
for(n=0;n<=50000;n++);//delay for debouncing
for(p=0;p<=3;p++)
{
sum=sum+res[p];//sum of digits of number
}
add=sum;
if(add>9)// is sum is not a single digit
{
while(add!=0)
{
num=num+(add%10);
add=add/10;
}
if(num<10)//if sum is in single digit
{
for(l=1;l<=8;l++)
{
if(l==num)//compare index and num(sum)
{
*outf=arr1[l];//display sum of digits
for(volatile long h=0;h<=900000;h++);//delay
goto loop;
}
}
}
}
else{
for(q=1;q<=8;q++)
{
*outf=arr1[q];
goto loop;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
void loop()
{
}