/*Get a 4 digit number from user (Press the switch
Sequentially (Example 1256) Add the sum of
Them the sum is more than 1 digit then add
them again and show the sum on display..*/
void setup()
{
volatile char *dir;
volatile char *dirk;
dir=0x30;
dirk=0x107;
*dir=0xFF;
*dirk=0x00;
}
char digicode(int i)
{
volatile char y;
switch(i) {
case 0:
y=0x3f;
break;
case 1:
y=0x06;
break;
case 2:
y=0x5b;
break;
case 3:
y=0x4f;
break;
case 4:
y=0x66;
break;
case 5:
y=0x6d;
break;
case 6:
y=0x7d;
break;
case 7:
y=0x07;
break;
case 8:
y=0x7f;
break;
case 9:
y=0x6f;
break;
}
return y;
}
void loop()
{
volatile char *out;
volatile char *ink;
volatile char x;
volatile char y[4];
volatile unsigned char z;
volatile int i=9,count=1,k=0,prev,sum=0;
volatile long j;
out=0x31;
ink=0x106;
while(count<=4)
{
x=*ink;
y[count]=x;
sum+=y;
count++;
if(count==4)
{
if(sum/10!=0)
{
int ones,tens;
ones=sum%10;
tens=sum/10;
sum=ones+tens;
}
*out=digicode(sum);
for(j=0;j<60000;j++);
}
}
}