void setup() {
// put your setup code here, to run once:
volatile char *dirf,*outf;
volatile char *dirk,*ink;
volatile char *dira,*outa;
dirf=0x30; outf=0x31;
dirk=0x107; ink=0x106;
dira=0x21; outa=0x22;
*dirf=0xFF; *dirk=0x00; *dira=0xFF;
volatile char x;
volatile long arr[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
int i;
while(1)
{
for(i=0;i<2;i++)
{
*outf=1<<i;// giving 5V to rows
x=*ink;// reading the pressed switch value
if(*outf==1 && (x & 1)==1)//when 1st switch pressed in 1st row
{
*outa=arr[0];//display 0 on 7-segment
}
if(*outf==1 && (x & 2)==2)//when 2nd switch pressed in 1st row
{
*outa=arr[1];//display 1 on 7-segment
}
if(*outf==2 && (x & 1) == 1)//when 1st switch pressed in 2nd row
{
*outa=arr[2];//display 2 on 7-segment
}
if(*outf==2 && (x & 2) == 2)//when 2nd switch pressed in 2nd row
{
*outa=arr[3];//display 3 on 7-segment
}
}
}
}
void loop() {
// put your main code here, to run repeatedly:
}