#include"ECEN.h"
void setup() {
volatile int Number1=0,sec=60,Switch=0,counter1=0,counter2=0,Number2=0,Number3=0,x=0,clear=0;// Declaration of Required Variables
volatile int outputmodeF=0xff,outputmodeK=0x0f,outputmodeA=0xff,outputmodeC=0x00; // Initialaization of input and output modes
init_portF(outputmodeF);// Initialization of Port F
init_portK(outputmodeK); // Initialization of Port K
init_portA(outputmodeA); // Initialization of Port A
init_portC(outputmodeC); // Initialization of Port C
while(1)
{
    Switch=Read_KeyPadSwitch(); // Reading Switch
   if((counter1==0 ) && (Switch==1 || Switch==0 || Switch==2 || Switch==3 || Switch==4 || Switch==5 || Switch==6 || Switch==7 || Switch==8 || Switch==9))
  {
    Number1=Switch;
    x=Number1;
    counter1++;
  } 
  else if((Switch==14) && (counter2==2 || counter2==3 || counter2==4 || counter2==5))
 {
  x=Number1+Number2;
  Display4(x);
  counter1=0;
  counter2=0;
   clear=1;
 }
 else if(Switch==10)
  {
    counter2++;
    counter1=-1;
  }
 else if((counter1==1) && (Switch==1 || Switch==0 || Switch==2 || Switch==3 || Switch==4 || Switch==5 || Switch==6 || Switch==7 || Switch==8 || Switch==9))
  {
    counter1++;
     Number1=Number1*10+Switch;
     x=Number1;
  }
   else if((counter1==2) && (Switch==1 || Switch==0 || Switch==2 || Switch==3 || Switch==4 || Switch==5 || Switch==6 || Switch==7 || Switch==8 || Switch==9))
  {
    counter1++;
     Number1=Number1*10+Switch;
     x=Number1;
  }
     else if((counter1==3) && (Switch==1 || Switch==0 || Switch==2 || Switch==3 || Switch==4 || Switch==5 || Switch==6 || Switch==7 || Switch==8 || Switch==9))
  {
    counter1++;
     Number1=Number1*10+Switch;
     x=Number1;
  }
  else if((counter2==1) && (Switch==1 || Switch==0 || Switch==2 || Switch==3 || Switch==4 || Switch==5 || Switch==6 || Switch==7 || Switch==8 || Switch==9))
  {
    counter2++;
     Number2=Switch;
     x=Number2;
  }
    else if((counter2==2) && (Switch==1 || Switch==0 || Switch==2 || Switch==3 || Switch==4 || Switch==5 || Switch==6 || Switch==7 || Switch==8 || Switch==9))
  {
    counter2++;
     Number2=Number2*10+Switch;
     x=Number2;
  }
      else if((counter2==3) && (Switch==1 || Switch==0 || Switch==2 || Switch==3 || Switch==4 || Switch==5 || Switch==6 || Switch==7 || Switch==8 || Switch==9))
  {
    counter2++;
     Number2=Number2*10+Switch;
     x=Number2;
  }
  else if((counter2==4) && (Switch==1 || Switch==0 || Switch==2 || Switch==3 || Switch==4 || Switch==5 || Switch==6 || Switch==7 || Switch==8 || Switch==9))
  {
    counter2++;
     Number2=Number2*10+Switch;
     x=Number2;
  }
else if((clear==1) && (Switch==1 || Switch==0 || Switch==2 || Switch==3 || Switch==4 || Switch==5 || Switch==6 || Switch==7 || Switch==8 || Switch==9))
 {
    Number1=Switch;
    x=Number1;
    Number2=0;
    counter1=1;
    counter2=0;
    clear=0;
 }
 else
 {
  Display4(x);
 }
   
}
}
void loop() {
 }