In this tutorial I am show how to interface keypad with PIC16F877A microcontroller. In this project I  am use 3x4 matrix keypad.

You can watch this video or read the written tutorial below.

 

3x4 Keyboard schematic

When press the any key than any column & row are connected each other at a time. Than current flowing column to row.

 

Circuit Diagram

In this project keypad are connected PORTC. This keypad has 7 terminal and each terminal are connected. 3x4 mtrix keypad terminal are 1,2,3,A,B,C & D. 1,2 & 3 is row and A,B,C & D is column. Normaly row is active high(1) at a time and column is active low(0).
While press the any key from keypad the row is active high(1). Than microcontroller read the value.

 

Project Code

// start Lcd module connection
sbit LCD_RS at RB0_bit ;
sbit LCD_EN at RB1_bit ;
sbit LCD_D4 at RB2_bit ;
sbit LCD_D5 at RB3_bit ;
sbit LCD_D6 at RB4_bit ;
sbit LCD_D7 at RB5_bit ;

sbit LCD_RS_Direction at TRISB0_bit ;
sbit LCD_EN_Direction at TRISB1_bit ;
sbit LCD_D4_Direction at TRISB2_bit ;
sbit LCD_D5_Direction at TRISB3_bit ;
sbit LCD_D6_Direction at TRISB4_bit ;
sbit LCD_D7_Direction at TRISB5_bit ;
//end Lcd module connection

void main( ) {
      Lcd_Init( );                                                       // Intialize Lcd module
     Lcd_Cmd(_LCD_CLEAR);                             // clrear lcd
     Lcd_Out(1,3 , "WELCOME TO");                  //  lcd show "WELCOME TO"
     Lcd_Out(2,1,"MINA TECHNOLOGY");        // lcd show "MINA TECHNOLOGY"
     delay_ms(1000);                                               // 1 second delay
     Lcd_Cmd(_LCD_CLEAR);                              // lcd clear
     TRISC = 0XF0 ;      
     PORTC = 0X00;                                                // clear PORTC

     while(1){
              RC2_bit = 1 ;                                             // RC2 pin is high(1)
              if(RC4_bit == 1)Lcd_Chr_Cp(49);             // 1
              if(RC5_bit == 1)Lcd_Chr_Cp(52);             //4
              if(RC6_bit == 1)Lcd_Chr_Cp(55);              // 7
              if(RC7_bit == 1)Lcd_Cmd(_LCD_Second_Row);  // cursor shift second row
              PORTC = 0X00;                                        // clear PORTC
              
              RC1_bit = 1;                                            // RC1 pin is high(1)
              if(RC4_bit == 1)Lcd_Chr_Cp(50);           // 2
              if(RC5_bit == 1)Lcd_Chr_Cp(53);            // 5
              if(RC6_bit == 1)Lcd_Chr_Cp(56);           // 8
              if(RC7_bit == 1)Lcd_Chr_Cp(48);          // 0
              PORTC = 0X00;    // clear PORTC
            
              RC0_bit = 1;                                             // RC0 pin is high(1)
              if(RC4_bit ==1)Lcd_Chr_Cp(51);            //3
              if(RC5_bit ==1 )Lcd_Chr_Cp(54);          // 6
              if(RC6_bit == 1)Lcd_Chr_Cp(57);             // 9
              if(RC7_bit == 1)Lcd_Cmd(_LCD_FIRST_ROW);  // Cursor shift first row
              PORTC = 0X00 ;                                         // clear PORTC
              delay_ms(300);                                           // 300ms delay
              }

}

 

 

Download free source code

 

download