#include"keypad.h"
unsigned char keycode,keyPressed='\0',i;
uint8_t row,column,column1,column2,column3;
unsigned char key_press(unsigned char press)
{
for(i=0;i<4;i++)
	{
	HAL_Delay(1);
	if(i==0){
		ROW1_RESET; ROW2_SET; ROW3_SET; ROW4_SET;
				row=0x08;
			}
	else if(i==1){
		ROW1_SET; ROW2_RESET; ROW3_SET; ROW4_SET;
				row=0x04;
			}
	else if(i==2){
		ROW1_SET; ROW2_SET; ROW3_RESET; ROW4_SET;
				row=0x02;
			}
	else if(i==3){
		ROW1_SET; ROW2_SET; ROW3_SET; ROW4_RESET;
				row=0x01;
			}
	HAL_Delay(1);
	if(COLUMN1) column1=0;
	else column1=0x80;
	if(COLUMN2) column2=0;
	else column2=0x40;
	if(COLUMN3) column3=0;
	else column3=0x20;
	column=column1|column2|column3;
	HAL_Delay(20);
	if(column != 0x00)
	{
	HAL_Delay(20);
	if(column == 0x00) goto OUT;
	keycode=(row&0x0f)|(column&0xf0);
	//HAL_Delay(20);
	switch(keycode)
		{
			case (0x88): keyPressed = '1'; 
				 		 break;
			case (0x48): keyPressed = '2';
				 		 break;
			case (0x28): keyPressed = '3'; 
			   			 break;
			case (0x84): keyPressed = '4';
				 		 break;
			case (0x44): keyPressed = '5'; 
				 		 break;
			case (0x24): keyPressed = '6'; 
				 		 break;
			case (0x82): keyPressed = '7'; 
				 		 break;
			case (0x42): keyPressed = '8'; 
				 		 break;
			case (0x22): keyPressed = '9'; 
				 		 break;
			case (0x81): keyPressed = '*'; 
				 		 break;
			case (0x41): keyPressed = '0';
				 		 break;
			case (0x21): keyPressed = '#'; 
				 		 break;
		}
		OUT:;
	}
	}
return (keyPressed);
}

