Experiment No. 8: Aim: WAP To Interface The 4x4 Keypad With Microcontroller and Display The Respective Digit On
Experiment No. 8: Aim: WAP To Interface The 4x4 Keypad With Microcontroller and Display The Respective Digit On
8
Aim: WAP to interface the 4x4 keypad with microcontroller and display the respective digit on
LCD.
Apparatus required: 89s5x trainer kit, connecting chords.
Circuit diagram:
VCC
40
VCC
10 uF
10K
EA/ VPP
30 pF
VCC
P0.5
31
P0.4
X1
11.06MHz
18
P0.0
9
10
GND
P0.7
P0.3
19
30 pF
P0.6
11
12
13
14
15
1
2
3
4
X2
RST
P0.1
P0.2
P3.0/RXD
P3.1/TXD
P2.0
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P2.1
89s51
P2.2
P2.3
P2.4
P1.0
P2.5
P1.1
P2.6
P1.2
P2.7
P1.3
PSEN
ALE
P3.6/ WR
P1.4
P1.5
P1.6
8
P1.7
P3.7/ RD
GND
39
16x2
33
VEE
VSS
D6D7VCC
11 12 13 14 2
D4
9 10
D3
7 8
D1
D2
D0
RS
35
34
R/W
36
37
D5
38
10K
32
21
22
23
24
25
26
27
28
29
30
16
17
20
GND
Fig.1: Circuit diagram for interfacing the 4x4 keypad and LCD with microcontroller
Program:
#include <stdio.h>
#include <reg51.h>
#define DATA P1
void lcd_init(void);
void lcd_cmd(unsignedchar);
void lcd_display(unsigned ch);
void Key_Scan(void);
void DelayMs(int);
sbit RS = P3^4;
sbit RW = P3^5;
sbit lcd_e = P3^6;
unsigned char R,C,ch;
unsigned int i=0;
unsigned char Key[4][4] =
{'1','2','3','4',
'5','6','7','8',
'9','0','A','B',
'C','D','E','F',
};
unsigned char msg[] = ("keypad
interfacing");
unsigned char msg1[] = (" BOARD
");
void main()
{
lcd_init();
while(1)
{
Key_Scan();
ch = Key[C][R];
SBUF=ch;
DelayMs(35);
lcd_display(ch);
lcd_cmd(0x80);
DelayMs(35);
}
}
void Key_Scan(void)
{
unsigned int i = 0;
P2 = 0x0F;
while(P2==0x0F);
if(P2 == 0x0E)
R = 0;
DelayMs(35);
i=0;
while(msg[i]!='\0')
{
lcd_display(msg[i]);
i++;
}
DelayMs(50);
lcd_cmd(0xc0);
DelayMs(35);
i=0;
while(msg1[i]!='\0')
{
lcd_display(msg1[i]);
i++;
}
DelayMs(50);
lcd_cmd(0x06);
DelayMs(50);
}
void DelayMs(int k)
{
unsigned int a;
for(a=0;a<=k;a++);
}
Hardware:
Fig2:hardware interfacing.
Worksheet
8051 Lines
ROW-0
P2.0
ROW-1
P2.1
ROW-2
P2.2
ROW-4
P2.3
COLUMN-0
P2.4
COLUMN-1
P2.5
COLUMN-2
P2.6
COLUMN COLUMN-3
P2.7
ROW
Data=0x66;
}
}
void Key_Scan(void)
{
unsigned int i = 0;
P2 = 0x30;
while(P2==0x30);
if(P2 == 0x20)
R = 0;
else if(P2 == 0x10)
R = 1;
while(P2 == 0xC0);
if(P2 == 0x80)
C = 0;
else if(P2 == 0x40)
C = 1;
DelayMs(50);
}
void DelayMs(int k)
{
unsigned int a;
for(a=0;a<=k;a++);
}