Maker Pro
Maker Pro

Keypad interfacing to PIC contoller

shrihari

Apr 30, 2015
8
Joined
Apr 30, 2015
Messages
8
Dear all,

Hi to all,

My query is, recently i tried to interface 4x4 matrix keypad to the PIC16f877a controller and i found that my keypad buttons are getting automatically pressed whenever i make movement of keypad, to resolve and crosscheck this problem i have purchased a new keypad but still it is giving same problem. i hope the problem may be inside the keypad, but i don't know exactly what is the problem. If any one can suggest remedy to my problem i will be very thankful to him.
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Can you post a circuit diagram? And your code?
Thanks Adam
 

shrihari

Apr 30, 2015
8
Joined
Apr 30, 2015
Messages
8
Circuit Diagram:
1.0x0.jpg

The connector shown above is directly connected to PORT of PIC controller without connecting rows or columns to Vcc supply via resistors. I have used same keypad as showed in figure above.

My program is: The code is for only first row of keypad remaining rows are also giving the same problem.


#include <stdio.h>
#include <stdlib.h>

/*
*
*/
#include"newfileR.h"
void delay();
void lcd_cmd(int);
void lcd_data(int);
#define rs RC0
#define rw RC1
#define en RC2
#define r0 RD7
#define r1 RD6
#define r2 RD5
#define r3 RD4
#define c0 RD3
#define c1 RD2
#define c2 RD1
#define c3 RD0


void main(){
TRISB=0x00;
TRISC=0x00;
TRISD=0x0F; //row as output and column as input
PORTD=0x00;
PORTB=0x00;
PORTC=0x00;


ADCON1=0x80;
ADCON0=0x01;
ADIF=0;
lcd_cmd(0x38);
lcd_cmd(0x0C);
lcd_cmd(0x01);
lcd_cmd(0x80);

while(1){
lcd_cmd(0xC0);
r0=1;r1=0;r2=0;r3=0; // First Row
if(c0==1&&c1==0&&c2==0&&c3==0){
lcd_data(0x31);
while(c0==1&&c1==0&&c2==0&&c3==0);
}
if(c0==0&&c1==1&&c2==0&&c3==0){
lcd_data(0x32);
while(c0==0&&c1==1&&c2==0&&c3==0);
}
if(c0==0&&c1==0&&c2==1&&c3==0){
lcd_data(0x33);
while(c0==0&&c1==0&&c2==1&&c3==0);
}
if(c0==0&&c1==0&&c2==0&&c3==1){
lcd_data('A');
while(c0==0&&c1==0&&c2==0&&c3==1);
}


}
}
void delay(){
for(j=0;j<4000;j++);
}
void lcd_cmd(int cmd){
PORTB=cmd;
rw=0;
rs=0;
en=1;
for(i=0;i<120;i++);
en=0;
for(i=0;i<120;i++);
}
void lcd_data(int data){
PORTB=data;
rw=0;
rs=1;
en=1;
for(i=0;i<120;i++);
en=0;
for(i=0;i<120;i++);
}
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Bad design. First of all, pushing two buttons in the same column will short a low output to a high output.

But the problem you are seeing is because the input are floating when no button is pressed. You need a pullup resistor on each column. Then you need to change the row scanning to make only one row and output and put a zero on it, while the other rows are made to be inputs (I.e. by setting TRIS). Now when you push a button, you will see a zero on the column for that button when the row for that button is selected, and you will see a 1 in that column otherwise.

Bob
 

Emam

Jul 7, 2014
63
Joined
Jul 7, 2014
Messages
63
Is this meaning that the problem is mechanical rather than electrical?
Can we put some filters somewhere to avoid this problem?
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
No, the problem is electrical and I told you how to solve it.

Bob
 
Top