Keypad Interfacing with Pic Microcontroller and Mikor C
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.
Keypad is set of button. It contain digits,symbols&alphabetical letters. It can be (4x4),(4x3) & (3x2). 4x3 it means 3 column and 4 row. Matrix keypads are commonly used in calculator , digital scale, security systems ,electronic device etc. Matrix keypad is array of push switch. Push button switch leg are connected to columns and rows. 4x4 matrix keypad contain (4*4)=16 push button switch. If we are use 3x4 matrix there are (3*4)=12 push button switch. 4x4 matrix keypad has (4+4)=8 pin connection and 3x4 matrix keypad (3+4)=7 pin connection.
MATRIX KEYPAD
Before I interface the keypad with PIC16F877A microcontroller , frist we need to understand how to working matrix keypad.Keypad is set of button. It contain digits,symbols&alphabetical letters. It can be (4x4),(4x3) & (3x2). 4x3 it means 3 column and 4 row. Matrix keypads are commonly used in calculator , digital scale, security systems ,electronic device etc. Matrix keypad is array of push switch. Push button switch leg are connected to columns and rows. 4x4 matrix keypad contain (4*4)=16 push button switch. If we are use 3x4 matrix there are (3*4)=12 push button switch. 4x4 matrix keypad has (4+4)=8 pin connection and 3x4 matrix keypad (3+4)=7 pin connection.
4X4 MATRIX KEYPAD STRUCTURE
When press the any key than any column & row are connected each other at a time. Than current flowing column to row.
![]() |
3x4 matrix keypad |
CIRCUIT DIAGRAM OF KEYPAD INTERFACING
![]() |
3x4 matrix keypad and Lm16x2 Lcd display |
PROJECT ANALISIS
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.
While press the any key from keypad the row is active high(1). Than microcontroller read the value.
CASE 1 :
If RC2 active high(1) and press 1 than RC4 reached active high(1). Lcd display show digit first row and first column '1'.
CASE 2 :
If RC1 active high(1) and press 2 than RC4 reached active high(1). Lcd display show digit '2'.
CASE 3 :
If RC0 active high(1) and press 3 than RC4 reached active high(1). Lcd display show the digit '3'.CASE 4 :
If RC2 active high(1) and press 4 than RC5 reached active high(1). Lcd display show the digit '4'.CASE 5 :
If RC1 active high(1) and press 5 than RC5 reached active high(1). Lcd display show the digit '5'.CASE 6 :
If RC0 active high(1) and press 6 than RC5 reached active high(1). Lcd display show the digit '6'.CASE 7 :
If RC2 active high(1) and press 7 than RC6 reached active high(1). Lcd display show the digit '7'.CASE 8 :
If RC1 active high(1) and press 8 than RC6 reached active high(1). Lcd display show the digit '8'.CASE 9 :
If RC0 active high(1) and press 9 than RC6 reached active high(1). Lcd display show the digit '9'.CASE 10 :
If RC2 active high(1) and press * than RC7 reached active high(1). Lcd display cursor position is change. Cursor shift first row and first column of the Lcd display.CASE 11 :
If RC1 active high(1) and press 0 than RC7 reached active high(1). Lcd display show the digit '0'.CASE 12 :
If RC0 active high(1) and press # than RC7 reached active high(1). Lcd display cursor position is change. Cursor shift second row and first column of the Lcd displayLCD INTERFACING
In this project I am use LM16x02 LCD display. If you don't know how to interface Lcd display with microcontroller than click here for more details.
Mikor C code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
You can download mikro C and protiues file. Click the download.
![]() |
download |
This a good project
ReplyDelete