LPC-2148 Interfacing with KEYPAD

Keypad Interfacing with LPC2148


Schematic Diagram

keyboard_interfacing



Interfacing Description


LPC2148 Port Pin No.LCD Pins
P1.16D0
P1.17D1
P1.18D2
P1.19D3
P1.20D4
P1.21D5
P1.22D6
P1.23D7
P0.28RS
P0.29EN
P0.10BC
LPC2148 Port Pin No.Keyboard connection

P0.2,P0.3,P0.4,P0.5

Column Read Lines
 P0.6,P0.7,P0.8,P0.9Row Scan Lines

Algorithm

Step1:- Start
Step2:- Configure(set the direction) the row pins as an output (p0.6, p0.7, p0.8, p0.9)
Step3:- Configure(set the direction) the column pins as an input (p0.2, p0.3, p0.4, p0.5)
Step4:- Include lcd.h header file to display the pressed key
Step5:- Now ground each row (starting from row0 to row3) 
Step 6:- Now check the status of Row and Column simultaneously, if key is pressed then respective column will be grounded.
Step 7:- Nowyou know the row you have grounded and Column which has been grounded..i.e. key pressed has been detected
Step8:- Display the key pressed on LCD by calling LCDDATA function
Step9:- END

Embedded C program for the Interfacing


/**************************************************************************/
/* Project Name:- 4x4 Hexa-Decimal Keypad Interfacing with LPC2148     */
/* Device:- LPC2148                          */
/* Compiler:- KeiluVision4                   */
/* Language:- Embedded C  */
/* Visit www.wikinote.org for more Details   */
/******************************************************************************************/
#include<lpc21xx.h>
void lcdcmd(unsigned int);
void lcddata(unsigned int);
void delay_lcd(void);
int main(void)
{
   while(1)
{  
 IODIR1=0x00ff0000;
 IODIR0=0x300003c0;
 lcdcmd(0x38);
 lcdcmd(0x0e);
 lcdcmd(0x01);
 lcdcmd(0x06);
 lcdcmd(0x83);
 lcdcmd(0xC0);
IO0PIN=0x00000380;// First Scan Line(row status)
if(( IO0PIN & 0x0000003c )!= 0x0000003c))////(row & column)
{
switch(IO0PIN & 0x0000003c)
 {
case 0x00000038 : lcddata("C");break;
case 0x00000034 : lcddata("D");break;
case 0x0000002c : lcddata("E");break;
case 0x0000001c : lcddata("F");break;
 }
 }
 IO0PIN=0x00000340;// Second Scan Line(row status)
if(( IO0PIN & 0x0000003c )!= 0x0000003c) )////(row & column)
{
switch(IO0PIN & 0x0000003c)
 {
case 0x00000038 : lcddata("8");break;
case 0x00000034 : lcddata("9");break;
case 0x0000002c : lcddata("A");break;
case 0x0000001c : lcddata("B");break;
 }
 }
        IO0PIN=0x000002c0;// Third Scan Line(row)
if(( IO0PIN & 0x0000003c )!= 0x0000003c)////(row & column
{
switch(IO0PIN & 0x0000003c)
 {
case 0x00000038 : lcddata("4");break;
case 0x00000034 : lcddata("5");break;
case 0x0000002c : lcddata("6");break;
case 0x0000001c : lcddata("7");break;
 }
 }
 IO0PIN=0x000001c0; // Four Scan Line(row)
 if(( IO0PIN & 0x0000003c )!= 0x0000003c)////(row & column)
{
switch(IO0PIN & 0x0000003c)
 {
case 0x00000038 : lcddata("0");break;
case 0x00000034 : lcddata("1");break;
case 0x0000002c : lcddata("2");break;
case 0x0000001c : lcddata("3");break;
 }
 }
 delay_lcd();
}
}
void lcdcmd(unsigned int cmddata)
{
 IOCLR1=0x00ff0000;
 IOCLR0=0x10000000;
 cmddata=cmddata<<16;
 IOSET1=cmddata;
 IOSET0=0x20000000;
 delay_lcd();
 IOCLR0=0x20000000;
 delay_lcd();
return;
}
void lcddata(unsigned int outdata)
{
 IOCLR1=0x00ff0000;
 IOSET0=0x10000000;
 outdata=outdata<<16;
 IOSET1=outdata;
 IOSET0=0x20000000;
 delay_lcd();
 IOCLR0=0x20000000;
 delay_lcd();
return;
}
void delay_lcd(void)
{
int j;
for(j=0;j<10000;j++);
return;
}

References

  • WikiNote Foundation
  • Prof. Sujit Wagh

Last modified: Thursday, 5 March 2020, 12:13 AM