void setup() {
volatile char *dirf,*dirk,*dira,*dirc;
dirf = 0x30; dirk = 0x107; dira = 0x21; dirc = 0x27;
*dirf = 0x0f; *dirk = 0x00; *dira = 0xff; *dirc = 0x0f;
}
void loop(){
display_add();
}
void display_add(){
volatile char *outf,*outa,*outc,*ink,x;
volatile int i,num ,count,sum,tl,cs,add;
outf = 0x31;ink = 0x106; outc = 0x28;outa = 0x22;
volatile char numbers[]={0xC0,0xF9,0xA4,0xB0,0X99,0X92,0X82,0xF8,0x80,0x90};
sum = 0;
add = 0;
tl = 0;
cs = 0;
while(1){
for(i=0;i<4;i++){
*outf=1 << i;
x=*ink;
if(x!=0){//checks if any switch is pressed on keypad
if(*outf==1 && x == 1){//row 1 column 1 (1)
num = 1;
}
if(*outf==1 && x == 2){//row 1 column 2 (2)
num = 2;
}
if(*outf==1 && x == 4){//row 1 column 3 (3)
num = 3;
}
if(*outf==2 && x == 1){// row 2 column 1 (4)
num = 4;
}
if(*outf==2 && x == 2){// row 2 column 2 (5)
num = 5;
}
if(*outf==2 && x == 4){// row 2 column 3 (6)
num = 6;
}
if(*outf==4 && x == 1){// row 3 column 1 (7)
num = 7;
}
if(*outf==4 && x == 2){// row 3 column 2 (8)
num = 8;
}
if(*outf==4 && x == 4){// row 3 column 3 (9)
num = 9;
}
if(*outf==8 && x == 2){// row 4 column 2 (0)
num = 0;
}
tl = (tl*10)+num;
//display pressed number
*outc=0x01;
*outa=numbers[num];
delay(200);
//add button
if(*outf == 1 && x == 8){
cs = tl;
add++;
}
// function of = button
if(*outf == 8 && x == 4 && add>0){
int ld,vl;
ld = tl%10;
vl = (cs/10)+ld;
int tens,ones;
tens = vl/10;
ones = vl%10;
*outc = 0x01;
*outa = numbers[tens];
delay(500);
*outc = 0x02;
*outa = numbers[ones];
delay(500);
tl = 0;
add = 0;
}
}
}
}
}