Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] 4*4 Matrix Keypad Optimization help needed

Status
Not open for further replies.

Thota Suresh Avionics

Member level 2
Joined
Jul 15, 2013
Messages
45
Helped
2
Reputation
4
Reaction score
2
Trophy points
8
Activity points
345
Hi,

Below mentioned code is 4*4 alphanumeric keypad,
my code is working absolutely fine, is there any optimizing techniques to reduce code size and complications can any one please suggest me...

KEYPAD Specification:

M 1 2 3

U 4 5 6

D 7 8 9

E S 0 C


O/P(col) = 0
I/P(row) = 1 |



Code:
#include<P30f5011.h>

int main()
{
	uart_init();
	while(1)
	{
		KeyPadScan();
		delay(100);
	}

}





const unsigned char keys[16]  =	  {0x11,0x12,0x14,0x18,
								   0x21,0x22,0x24,0x28,
								   0x41,0x42,0x44,0x48,
								   0x81,0x82,0x84,0x88};
 
															//[R][C]
const unsigned char key_char[16][4]=   {{'M','M','M','M'},  //[1][0]
							 			{'1',',','.','@'},	//[1][1]
										{'2','A','B','C'},	//[1][2]
										{'3','D','E','F'},	//[1][3] 
																		
										{'U','U','U','U'},	//[2][0]
										{'4','G','H','I'},	//[2][1]
										{'5','J','K','L'},	//[2][2]
										{'6','M','N','O'},  //[2][3]


										{'D','D','D','D'},	//[3][0]
										{'7','P','Q','R'},	//[3][1]
										{'8','S','T','U'},	//[3][2]
										{'9','U','V','W'},	//[3][3]

										{'E','E','E','E'},	//[4][0]
										{'*','X','Y','Z'},	//[4][1]
										{'0','0','0','0'},	//[4][2]
										{'C','C','C','C'}};	//[4][3]


unsigned char key_pos1=0,n=0;

void KP_INIT(void)
{
ADCON1bits.ADON = 0;	//ADC DISABLED
ADPCFG = 0xFFFF; 	      //Digital port active	
TRISB	= 	0x00F0;  //COL as I/P ROW as OP
LATB	=	0x0000;		//ALL LATB PINS LOW
printf("Key pad init done...\n");
}

void KeyPadScan( void )
{
unsigned char j=0,i=0;

PORTB=0x0F;  					 
if(PORTB != 0x0F )
{
for(i=0;i<4;i++)			
{
PORTB = 1<<i;						for(j=0;j<16;j++)
{
if((PORTB == keys[j]))
{
if(key_pos1 != j)
	n=0;						
key_pos1 = j;
					
 if(n==0 || n==1 || n==2 || n==3)
{							printf("%c\n",key_char[j][n]);
	n++;
	if(n==4)
	n=0;
	break;
}}}}}}

- - - Updated - - -

Application: Alphanumeric Keys Required
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top