How to Interface Keypad with LPC2148 - ARM7 Slicker

keypad Interfacing With ARM7 Slicker

Tags: ARM7 LPC2148 Slicker Board, keypad Interfacing, Interfacing keypad to Microcontroller, Interfacing keypad with LPC2148 ARM7 Slicker, Pin details of keypad with LPC2148,, Circuit Diagram to Interface keypad with LPC2148, C Program to Interface 4 X 4 matrix keypad using LPC2148, C Program for keypad interfacing
Overall rating
ARM7 LPC2148 Slicker Board

The ARM7 LPC2148 Slicker board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through serial port.

NXP’s ARM7 (LPC2148), ARM Slicker Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 32-bit Microcontrollers.


A keypad is a set of buttons arranged in a block or "pad" which usually bear digits, symbols and usually a complete set of alphabetical letters. If it mostly contains numbers then it can also be called a numeric keypad. Here we are using 4 X 4 matrix keypad.

Interfacing keypad

Fig. 1 shows how to interface the 4 X 4 matrix keypad to two ports in microcontroller. The rows are connected to an output port and the columns are connected to an input port.

To detect a pressed key, the microcontroller grounds all rows by providing 0 to the output latch, and then it reads the columns. If the data read from the columns is D3-D0=1111, no key has been pressed and the process continues until a key press is detected. However, if one of the column bits has a zero, this means that a key press has occurred. For example, if D3-D0=1101, this means that a key in the D1 column has been pressed.

After a key press is detected, the microcontroller will go through the process of identifying the key. Starting with the top row, the microcontroller grounds it by providing a low to row D0 only; then it reads the columns.

If the data read is all 1s, no key in that row is activated and the process is moved to the next row. It grounds the next row, reads the columns, and checks for any zero. This process continues until the row is identified. After identification of the row in which the key has been pressed, the next task is to find out which column the pressed key belongs to.


Fig. 1 Interfacing keypad to Microcontroller

Interfacing keypad with LPC2148 - ARM7 Slicker

We now want to scan a keypad in LPC2148 Slicker Board. In case of 4X4 matrix Keypad both the ends of switches are connected to the port pin i.e. four rows and four columns. So in all sixteen switches have been interfaced using just eight lines.

Keypads arranged by matrix format, each row and column section pulled by high or low by selection J2, all row and column lines terminated at CN3.

Pin Assignment with LPC2148


In this Slicker Board, we are using any port line for input. Just connect an FRC cable to any port from the particular applications. The ARM Slicker 2148 Board has only eight inputs for accessing keys. When switch is pressed LOW, then the UART transmit some messages in PC at 9600 baud rate. The TXD and RXD pins are used to data transmission & reception.

Circuit Diagram to Interface keypad with LPC2148 - ARM7 Slicker


Source Code

The Interfacing keypad with LPC2148 program is very simple and straight forward that scan a keypad rows and columns. When pressing the key, the rows and columns are detected. When the rows and columns are detected, then the microcontroller will display some messages in PC through UART0. The C programs are developed in Keil software.

C Program to 4 X 4 matrix keypad using LPC2148


Title : Program to keypad interfacing - ARM7 Slicker




#include <LPC214x.h>

#include <stdio.h>


#define CR      0x0D

#define D0      24


void Delay(void);


unsigned char Row_Data, Col_Data;

unsigned char M,N;

            unsigned char Msg[4][4] =    { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'


          void main(void)



   U0LCR   =   0x83;   // 8-Bit, 1 Stop Bit, No Parity

   U0DLL   =   0x61;   // 9600 baud rate @ 15MHz Clock

   U0LCR   =   0x03;


   PINSEL0|=   0x05;   // P0.0 and P0.1 as UART0

   U0THR   =   0x0C;   // Clear the Hyperterminal


   while (1)




      KeyScan();       // KeyScan to Scan Row & Column


      if (Row_Data < 4 && Col_Data < 4)



         U0THR    =   Msg[Row_Data][Col_Data];


         U0THR   =   '\n';


         U0THR    =   '\r';





void Delay(void)


   unsigned int i,j;





void KeyScan ()




   IODIR1 = (0x0F << D0); // (P1.16 - P1.23)

   IOPIN1 = (0xF0 << D0);

   while (((IOPIN1>>D0)&0x00F0) == 0xF0);


   M = IOPIN1 >> D0;


  if (M == 0xE0)


     Row_Data = 0;


  else if (M == 0xD0)


     Row_Data = 1;


  else if (M == 0xB0)


     Row_Data = 2;



  else if (M == 0x70)


     Row_Data = 3;



     Row_Data = 4;





  IOPIN1   =   0x0F << D0;

  IODIR1   =    (0xF0 << D0); // (P1.16 - P1.23)

           IOPIN1   =    (0x0F << D0);

  while (((IOPIN1>>D0)&0x000F) == 0x0F);


  N = (IOPIN1 >> D0);


  if (N == 0x0E)


     Col_Data = 0;


  else if (N == 0x0D)


     Col_Data = 1;


  else if (N == 0x0B)


     Col_Data = 2;


  else if (N == 0x07)


     Col_Data = 3;



     Col_Data = 4;



  IOPIN1   =   0xF0 << D0;





To compile the above C code you need the KEIL software. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In KEIL, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without LPC2148 Slicker Board.

The Flash Magic software is used to download the hex file into your microcontroller IC LPC2148 through UART0.

Testing the Keypad with LPC2148

Give +3.3V power supply to LPC2148 Slicker Board; the serial cable is connected between the LPC2148 Slicker Board and PC. Open the Hyper Terminal screen, select which port you are using and set the default settings. Now the screen should show some text messages & it display which key is pressed in keypad.

If you not reading any text from UART0, then you just check the jumper connections & just check the serial cable is working. And also check the keypad keys are properly working or not. Otherwise you just check the code with debugging mode in KEIL.

If you want to see more details about debugging just see the videos in below link.

General Information

  • For proper working use the components of exact values as shown in Circuit file. Wherever possible use new components.
  • Solder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints.
  • Use the exact value crystal shown in schematic.
  • More instructions are available in following articles,
       - User Manual of LPC2148 Slicker Board.
       - Tutorial of how to create & Debug a project in KEIL.
       - Interfacing Switches with LPC2148.

Join the World's Largest Technical Community

we respect your privacy.