Matrix Keypad Row and Column Scanning Process

Status
Not open for further replies.

Thread Starter

Parth786

Joined Jun 19, 2017
642
I want make routine in c programming that will read keypad get the key from keypad

upload_2017-10-28_19-37-25.jpeg
This picture is just for example to show keypad

I have studied about matrix keyboard and after that I have created this table to scan keypad. Is it right logic to read keypad ? I tried to make flow chart but I don't understand where to start. while making flowchart i was not deciding where to go.
upload_2017-10-28_19-24-27.png

I have made a routine. I know this will not work in programming. we don't write program like this . There are many errors in this routine . But I think this can be make better
C:
unsigned char Read_key(void)
{
   char Port_Data = 0000 0001;

   char R;
   for( R = 0; R < 4;  R++ )
   {
     KEY_PORT = Port_Data;

     if(!C1)
     if(!C2)
     if(!C3)

    Port_Data <<= 1;
   }
  return key;
}
 
Last edited:

simozz

Joined Jul 23, 2017
114
For this kind of tasks it's better to use interrupts.
If you have all the keypad pins connected to a single port with interrupt on change, the interrupt service routine is just a matter of a one or two logical ANDs.
 

JohnInTX

Joined Jun 26, 2012
4,337
Status
Not open for further replies.
Top