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_4();
}
void display_4(){
volatile char *outf,*outa,*outc,*ink,x;
volatile int i,num ,count,total;
outf = 0x31;ink = 0x106; outc = 0x28;outa = 0x22;
volatile char numbers[]={0xC0,0xF9,0xA4,0xB0,0X99,0X92,0X82,0xF8,0x80,0x90};
count = 0;
total = 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;
count+=1;
}
if(*outf==1 && x == 2){//row 1 column 2 (2)
num = 2;
count+=1;
}
if(*outf==1 && x == 4){//row 1 column 3 (3)
num = 3;
count+=1;
}
if(*outf==2 && x == 1){// row 2 column 1 (4)
num = 4;
count+=1;
}
if(*outf==2 && x == 2){// row 2 column 2 (5)
num = 5;
count+=1;
}
if(*outf==2 && x == 4){// row 2 column 3 (6)
num = 6;
count+=1;
}
if(*outf==4 && x == 1){// row 3 column 1 (7)
num = 7;
count+=1;
}
if(*outf==4 && x == 2){// row 3 column 2 (8)
num = 8;
count+=1;
}
if(*outf==4 && x == 4){// row 3 column 3 (9)
num = 9;
count+=1;
}
if(*outf==8 && x == 2){// row 4 column 2 (0)
num = 0;
count+=1;
}
*outc=0x01;
*outa=numbers[num];
delay(200);
total = (total*10) + num;
}
}
if(count == 4){
int thousand,hundred,ten,one;
thousand = (total/1000);
hundred = ((total/100)%10);
ten = ((total/10)%10);
one = (total%10);
//display 1st digit entered
*outc = 1;
*outa = numbers[thousand];
delay(500);
//display 2nd digit entered
*outc = 2;
*outa = numbers[hundred];
delay(500);
//display 3rd digit entered
*outc = 4;
*outa = numbers[ten];
delay(500);
//display 4th digit entered
*outc = 8;
*outa = numbers[one];
delay(2000);
//reset count back to 0 and display to nothing
count = 0;
total = 0;
*outc = 0x08;
*outa = 0x00;
}
}
}