Key Codes
Paul Arana
1. Keypad Codes
2. Description of System

back to CE150






1. Keypad Codes      TOP




// Keypad Program developed by Paul Albert Arana
// This code is specific with a certain keypad.
// Please see other Sentinel documentation

int *store(int value,int result);
int keypad(void);

//doorlock = 0, wrong code; doorlock=1, correct code
int keypad(void)
{
	int value=0,result=0,doorlock=0;
	int array[3], user[3];
	user[0]=0;
	user[1]=0;
	user[2]=0;
	user[3]=0;
//set output values
	array[0] = 0xf5;
	array[1] = 0xf0;
	array[2] = 0xf6;

	int i=0,c=0,t=0,n=0,a=0;

//polling starts here
	outportb(CONTROL,0xf5);
	result = inportb(DATA);
	do
   {
   	result = inportb(DATA);
	   t++;
   }	while(result!=0xf7&&t<250);

	if(t==250) goto end;

	delay(1000);

	printf("\nEnter passcode...\n");

	//get user input
	for(n=0;n<4;n++)
   {
		do
	   {
			value = outp(CONTROL, array[i++]);
			result = inportb(DATA);
			if(i==3)i=0;
		} while(result==0xff);
		int *y = store(value,result);
		user[c++] = *y;
		delay(500);
	}

	//comparison starts here
	int code[3];
	code[0] = 1;
	code[1] = 2;
	code[2] = 3;
	code[3] = 4;

  for(a=0;a<4;a++)
  {
	 if(user[a]!=code[a])
	 {
		printf("Access denied!");
		doorlock=0;
		goto end;
	 }
  }

  printf("Access granted.");
  doorlock=1;
end:
//if timeout
	if(t==250){
		doorlock=0;
	}

return doorlock;

getch();
}

//decoding of the keys starts here
int *store(int value,int result)
{
int column[4],ucode[4];
int b=0;

if (value==0xf5)
	{column[b]=value;
	if (result==0xfe)
		ucode[b]=0x1;
	if (result==0xfd)
		ucode[b]=0x4;
	if (result==0xfb)
		ucode[b]=0x7;
	if (result==0xf7)
		ucode[b]='*';
   }
if (value==0xf0)
	{if (result==0xfe)
		ucode[b]=0x2;
	if (result==0xfd)
		ucode[b]=0x5;
	if (result==0xfb)
		ucode[b]=0x8;
	if (result==0xf7)
		ucode[b]=0x0;
	}
if (value==0xf6)
	{if (result==0xfe)
		ucode[b]=0x3;
	if (result==0xfd)
		ucode[b]=0x6;
	if (result==0xfb)
		ucode[b]=0x9;
	if (result==0xf7)
		ucode[b]='#';
	}
b++;
return ucode;
}


      TOP





back to CE150