Connect with us

Keypad interfacing to PIC contoller

Discussion in 'Microcontrollers, Programming and IoT' started by shrihari, May 1, 2015.

Scroll to continue with content
  1. shrihari

    shrihari

    8
    0
    Apr 30, 2015
    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.
     
  2. Arouse1973

    Arouse1973 Adam

    5,165
    1,087
    Dec 18, 2013
    Can you post a circuit diagram? And your code?
    Thanks Adam
     
  3. shrihari

    shrihari

    8
    0
    Apr 30, 2015
    Circuit Diagram:
    [​IMG]
    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++);
    }
     
  4. BobK

    BobK

    7,682
    1,688
    Jan 5, 2010
    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
     
  5. Emam

    Emam

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

    BobK

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

    Bob
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-