Spread the love

keypad interfacing with 8051

____________________________________________________________________________________________________

  • What is keypad(keyboard) ? – What you probably have in front of you, is a keyboard with more than 100 keys on it… If you are not familiar with the key matrices, then you may think that inside this keyboard, there is a chip that has at least the same number of inputs to read each key separately. Well, this is not true…

keypad interfacing with 8051

  • What are the key matrices?–   The matrices are actually an interface technique. According to this technique, the I/O are divided into two sections: the columns and the rows. You can imagine a matrix as an excel sheet. Here is a 4 x 4 matrix. The A,B,C and D are the columns and the 1,2,3 and 4 are the rows. There are 16 knots that the rows and columns intersect. To make a keypad matrix, we will have to connect a switch to each knot. The switch will have a push-to-make contact. When the operator pushes this switch, it will connect the column and the row that it corresponds to.

keypad-schematic

  • How does keypad matrix works? –   To understand the operation principle, i will re-draw the above matrix without colors as you can see on above pic. I will also put connection switch to each row and column wire and show practical hardware pic. For the above 16-button 4×4 matrix, 8 pins of the microcontroller will be used. The first 4 pins will be OUTPUTS (gives logic ‘1’)  and will be connected to the COLUMN wires, while the other 4 pins will be INPUTS (logic ‘0’) and will be connected to the ROW wires. The matrix is controlled by a microcontroller. The OUTPUTS of the microcontroller will NOT all have power at the same time. The outputs will go high one by one in cycle. This happens many times per second.  When operator press switch 11 (highlighted in red color), column C and row 3’s connection established, current pass from column C to row 3, and in actual sense row 3 read logic ‘1’ from column D and microcontroller manipulate this connection and do work as we decided in programming.

1332_MED

  • Applications –  As you can see on above pics keypad is used in ATMs, cell phones and where multi parameter want to input.

1. Circuit Diagram Of  LCD and KEYPAD interfacing with 8051

LCD, KEYPAD interfacing with 8051

1. lcd and 4×4 keypad interfacing with 8051 in which Data Entered From KEYPAD is Displayed On LCD

/******************************************************
IDE :- Keil
DEVELOPED BY:- FIRMWARE DEVELOPER (www.firmcodes.com)
WHAT PROGRAM DO:- DATA INTERFACING WITH KEYPAD DISPLAYED
 ON LCD USING 8051
******************************************************/
#include<reg51.h>

// for keypad
sbit r1=P1^0;  // for row 1
sbit r2=P1^1;  // for row 2
sbit r3=P1^2;  // for row 3
sbit r4=P1^3;  // for row 4
sbit c1=P1^4;  // for column 1
sbit c2=P1^5;  // for column 2
sbit c3=P1^6;  // for column 3
sbit c4=P1^7;  // for column 4

// for lcd
sfr lcd=0xA0;  // lcd data pins
sbit rs=P3^0;  // lcd rs pin
sbit rw=P3^1;  // lcd rw pin
sbit en=P3^2;  // lcd enable pin

void delay();    // for delay purpose

void cmd();      // command  of lcd

void display();  // display function of lcd

void lcd_ini();  // initilization of lcd

void main()
{
        unsigned int i;
        lcd_ini();     // lcd initilization function is called in main program
        while(1)
         {
                for(i=0;i<4;i++)
                  {
                        if(i==0)
                          {
                                r1=0;       // make row1 as 0
                                r4=r3=r2=1; // make row2,row3,row4 as 1
                                if(c1==0)   // checking column 1 
                                  {
                                        lcd='7';    // lcd data pin is loaded with '7'
                                        display();  // display mode of lcd is called
                                        delay();    // delay function is callled
                                  }
                                else if(c2==0)  // checking column 2
                                  {
                                        lcd='8';   // lcd data pin is loaded with '8'
                                        display(); // display mode of lcd is called
                                        delay();   // delay function is callled
                                  }
                                else if(c3==0)  // checking column 3
                                  {
                                        lcd='9';   // lcd data pin is loaded with '9'
                                        display(); // display mode of lcd is called
                                        delay();   // delay function is callled
                                  }
                                else if(c4==0)  // checking column 4
                                  {
                                        lcd='/';    // lcd data pin is loaded with '/'
                                        display();  // display mode of lcd is called
                                        delay();    // delay function is callled
                                  }
                         }
                        
                        if(i==1)
                          {
                                r1=r3=r4=1;// make row1,row3,row4 as 1
                                r2=0;      // make row2 as 0
                                if(c1==0)  // checking column 1
                                  {
                                        lcd='4';     // lcd data pin is loaded with '4'
                                        display();   // display mode of lcd is called
                                        delay();     // delay function is callled
                                   }
                                else if(c2==0)  // checking column 2
                                  {
                                        lcd='5';    // lcd data pin is loaded with '5'
                                        display();  // display mode of lcd is called
                                        delay();   // delay function is callled
                                  }
                                else if(c3==0)  // checking column 3
                                  {
                                        lcd='6';    // lcd data pin is loaded with '5'
                                        display();  // display mode of lcd is called
                                        delay();   // delay function is callled
                                  }
                                else if(c4==0)  // checking column 4
                                  {
                                        lcd='*';    // lcd data pin is loaded with '*'
                                        display();  // display mode of lcd is called
                                        delay();   // delay function is callled
                                  }
                          }       
                                
                        
                  if(i==2)
                    {
                                r1=r2=r4=1; // make row1,row2,row4 as 1
                                r3=0;       // make row3 as 0
                                 if(c1==0)  // checking column 1
                                  {
                                        lcd='1';    // lcd data pin is loaded with '1'
                                        display(); // display mode of lcd is called
                                        delay();   // delay function is callled
                                  }
                                else if(c2==0)  // checking column 2
                                  {
                                        lcd='2';    // lcd data pin is loaded with '2'
                                        display();  // display mode of lcd is called
                                        delay();   // delay function is callled
                                  }
                                else if(c3==0)  // checking column 3
                                  {
                                        lcd='3';   // lcd data pin is loaded with '3'
                                        display();  // display mode of lcd is called
                                        delay();    // delay function is callled
                                  }
                                else if(c4==0)  // checking column 4
                                  {
                                        lcd='-';    // lcd data pin is loaded with '_'
                                        display();  // display mode of lcd is called
                                        delay();   // delay function is callled
                                  }
                   }
                
                 if(i==3)
                   {
                                r1=r2=r3=1;// make row1,row2,row3 as 1
                                r4=0;      // make row4 as 0
                                if(c1==0)  // checking column 1
                                  {
                                        lcd=0x01;  // lcd data pin is loaded with '0x01'
                                        cmd();    // command mode of lcd is called
                                        delay();  // delay function is callled
                                  }
                                else if(c2==0)  // checking column 2
                                  {
                                        lcd='0';  // lcd data pin is loaded with '0'
                                        display();  // display mode of lcd is called
                                        delay();   // delay function is callled
                                  }
                                else if(c3==0)  // checking column 3
                                  {
                                        lcd='=';   // lcd data pin is loaded with '='
                                        display();  // display mode of lcd is called
                                        delay();   // delay function is callled
                                  }
                                else if(c4==0)  // checking column 4
                                  {
                                        lcd='+';   // lcd data pin is loaded with '+'
                                        display();  // display mode of lcd is called
                                        delay();   // delay function is callled
                                  }
                          }
                  }
         }
  }

void delay()   // for delay purpose
{
unsigned int i,j;
for(i=0;i<100;i++)
for(j=0;j<153;j++);
}
void cmd()       // command  of lcd
{
unsigned char i;
rs=0;
rw=0;
en=1;
for(i=0;i<2;i++);
en=0;
delay();
}
void display() // display function of lcd
{
unsigned char i;
rs=1;
rw=0;
en=1;
for(i=0;i<2;i++);
en=0;
delay();
}
void lcd_ini()     // initilization of lcd
{
lcd=0x38;
cmd();
lcd=0x0e;
cmd();
lcd=0x01;
cmd();
lcd=0x06;
cmd();
lcd=0x80;
cmd();
delay();
}

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)

download (1)

______________________________________________________________________________________________________

Content for the tab VIDEO