Keypad Interfacing With ARM7 Slicker
Keypad Interfacing With ARM7 Slicker
Interfacing Keypad
with LPC2148 ARM
Contents at a Glance
ARM7 LPC2148 Slicker Board ...........................................3
Keypad ............................................................................3
Interfacing keypad ...........................................................4
Interfacing keypad with LPC2148 .....................................6
Pin Assignment with LPC2148 ..........................................6
Circuit Diagram to Interface keypad with LPC2148 ...........7
Source Code ....................................................................7
C Program to 4 X 4 matrix keypad using LPC2148 .............8
Testing the Keypad with LPC2148................................... 11
General Information ...................................................... 12
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 D3D0=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.
VREF
VDD1
VDD2
VDD3
VDDA
VSS1
VSS2
VSS3
VSS4
VSS5
VSSA
P1.24
P1.25
P1.26
P1.27
32
28
24
64
SW7
SW8
SW9
+5V
SW10
SW11
SW12
SW13
SW14
SW15
SW16
SW17
SW18
2
3
4
5
6
7
8
9
LPC2148
XTAL1
60
56
52
20
22pf
10K
R16
SW19
SW20
SW21
SW22
12MHz
C52
GND
62
XTAL2
P1.28
P1.29
P1.30
P1.31
61
6
18
25
42
50
59
1
2
3
63
51
43
23
7
CON3
U16
X21
CN3
R1
R3
C1
C3
C53
22pf
4X4 KEYPAD
1
3
5
7
9
2
4
6
8
10
R2
R4
C2
C4
KEYPAD
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.
0x0D
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
U0DLL
U0LCR
=
=
=
0x83;
0x61;
0x03;
PINSEL0|=
U0THR
=
0x05;
0x0C;
while (1)
{
Delay();
KeyScan();
{
U0THR
=
Delay();
U0THR
=
Delay();
U0THR
=
Msg[Row_Data][Col_Data];
'\n';
'\r';
}
}
}
void Delay(void)
{
unsigned int i,j;
for(i=0;i<350;i++)
for(j=0;j<1234;j++);
}
void KeyScan ()
{
Delay();
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;
}
else
Row_Data = 4;
Delay();
Delay();
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;
}
else
Col_Data = 4;
Delay();
IOPIN1
=
Delay();
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.
How to Create & Debug a Project in KEIL.
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.
Join the Technical Community Today!
http://www.pantechsolutions.net
What do we sell?
Our products range from Various Microcontroller
development boards, DSP Boards, FPGA/CPLD boards,
Communication Kits, Power electronics, Basic electronics,
Robotics, Sensors, Electronic components and much more . Our
goal is to make finding the parts and information you need
easier and affordable so you can create awesome projects and
training from Basic to Cutting edge technology.