Keypad is a widely used input device with lots of application in our everyday life. From a simple telephone to keyboard of a computer, ATM, electronic lock, etc., keypad is used to take input from the user for further processing. In this article we are interfacing keypad with the MCU AT89C51 and displaying the corresponding number on LCD. This module can be further used in a number of systems to interfaced keypad with microcontroller and other processors to get desired output. The program to interface keypad with controller is written in C language which is very easy to understand.
Keypad is organized as a matrix of switches in rows and column. The article uses a 4X3 matrix keypad and a 16×2 LCD for displaying the output of keypad.




Project Source Code
###
// Program to interface controller with controller #include<reg51.h> #define port P1 #define dataport P2 // Dataport for lcd #define key P0 // Port for keypad #define sec 100 sbit rs = port^1; sbit rw = port^2; sbit en = port^3; sbit col1=key^4; sbit col2=key^5; sbit col3=key^6; sbit row1=key^0; sbit row2=key^1; sbit row3=key^2; sbit row4=key^3; void delay(unsigned int msec) //Time delay function { int i,j ; for(i=0;i<msec;i++) for(j=0;j<1275;j++); } void lcd_cmd(unsigned char item) //Function to send command to LCD { dataport = item; rs= 0; rw=0; en=1; delay(1); en=0; return; } void lcd_data(unsigned char item) //Funtion to send data on LCD { dataport = item; rs= 1; rw=0; en=1; delay(1); en=0; return; } void lcd_data_string(unsigned char *str) // Function to send string on LCD { int i=0; while(str[i]!='