Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] 4x3 matrix key pad interfacing with 8051

Status
Not open for further replies.

johnpaularul

Newbie level 2
Joined
Oct 29, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,315
This is john..
Hi guys... Here I tried 4x3 matrix key pad interfacing with 8051 and its working... I have used port 3 and connected row 0, 1, 2, 3 in P3.4, P3.5, P3.6, P3.7 and column 0, 1, 2 in P3.2, P3.1, P3.0 respectively.

#include <REGX51.H>
sfr keypad = 0xB0; //port 3
sfr lcd_output = 0x90; //port 1
sbit RS = 0xA0; //port 2.0
sbit RW = 0xA1; //port 2.1
sbit EN = 0xA2; //port 2.2

void delay(unsigned int value){
unsigned int i, j;
for(i=0;i<=value;i++){
for(j=0;j<=1000;j++){
}
}
}

void lcd_cmd(unsigned char value){
lcd_output = value;
RS = 0;
RW = 0;
EN = 1;
delay(1);
EN = 0;
return;
}

void lcd_data(unsigned char value){
static int a =1;
a++;
if(a==17){
a=1;
lcd_cmd(0x01);
}
lcd_output = value;
RS = 1;
RW = 0;
EN = 1;
delay(1);
EN = 0;
return;
}

void lcd_init(){
lcd_cmd(0x38);
lcd_cmd(0x0C);
lcd_cmd(0x80);
}

void main(){
unsigned char arr[4][3] = {'1','2','3',
'4','5','6',
'7','8','9',
'*','0','#'};
unsigned int row, col;
lcd_init();
while(1){
keypad=0xF0;
while(keypad != 0xF0); //check for key not pressed
while(keypad==0xF0); //check for key pressed
if(keypad==0xE0){ //check for row 0
row = 0;
keypad=0xFF;
keypad=0xEF;
if(keypad==0xEB)
col = 0;
if(keypad==0xED)
col = 1;
if(keypad==0xEE)
col = 2;
lcd_data(arr[row][col]);
}
else if(keypad==0xD0){ //check for row 1
row = 1;
keypad=0xFF;
keypad=0xDF;
if(keypad==0xDB)
col = 0;
if(keypad==0xDD)
col = 1;
if(keypad==0xDE)
col = 2;
lcd_data(arr[row][col]);
}
else if(keypad==0xB0){ //check for row 2
row = 2;
keypad=0xFF;
keypad=0xBF;
if(keypad==0xBB)
col = 0;
if(keypad==0xBD)
col = 1;
if(keypad==0xBE)
col = 2;
lcd_data(arr[row][col]);
}
else if(keypad==0x70){ //check for row 3
row = 3;
keypad=0xFF;
keypad=0x7F;
if(keypad==0x7B)
col = 0;
if(keypad==0x7D)
col = 1;
if(keypad==0x7E)
col = 2;
lcd_data(arr[row][col]);
}
}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top