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.

Matrix Keypad Not Working.

Status
Not open for further replies.

gauravkothari23

Advanced Member level 2
Joined
Mar 21, 2015
Messages
508
Helped
3
Reputation
6
Reaction score
3
Trophy points
18
Activity points
4,751
Hi Friends,
This is Gaurav Kothari and as i am very new to electonics want a bit help from you regarding matrix keypad.
I am trying to build electronic door lock system using 89S52 and 4x4 matrix keypad and 20x2 LCD display.
The keypad does work properly with proteus. but when i build a proper circuit and tried to make an entry using my keypad, it only shows me 3 numbers (7,8 and 9). whatever keys are pressed it displays me only 7,8 or 9.
my code for keypad is:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
int keypad() 
 {
   unsigned char dat[4][4]=
{
                            '7','8','9','%',
                            '4','5','6','*',
                '1','2','3','-',
                        'C','0','=','+',
                           };
 unsigned char colloc,rowloc;
 COL=0xFF;
 ROW=0x00;
 rs=0;
 rw=0;
 en=0;
 busy=0;
 /* setting LCD screen*/ 
 ldata=0x00;
 lcdcmd(0x38);
 lcdcmd(0x0E);
 lcdcmd(0x06);
 
 while(1)
 {
/* reading character from keyboard */
   do
   {
    ROW=0x00;
    colloc=COL;
    colloc&=0x0F;
    }while(colloc!=0x0F);
    do
    {
     do
     {
      msdelay(25);
      colloc=COL;
      colloc&=0x0F;
      }while(colloc==0x0F);
      msdelay(25);
      colloc=COL;
      colloc&=0x0F;
      }while(colloc==0x0F);
    while(1)
    {
     ROW=0xFE;
     colloc=COL;
     colloc&=0x0F;
     if(colloc!=0x0F)
     { 
      rowloc=0;
      break;
      }
      ROW=0xFD;
      colloc=COL;
      colloc&=0x0F;
       if(colloc!=0x0F)
       {
        rowloc=1;
        break;
        }
      ROW=0xFB;
      colloc=COL;
      colloc&=0x0F;
       if(colloc!=0x0F)
       {
        rowloc=2;
        break;
        }
      ROW=0xF7;
      colloc=COL;
      colloc&=0x0F;
    if(colloc!=0x0F)
      {  
          rowloc=3;
          break;
        }
       }
   if(colloc==0x0E)
   return(dat[rowloc][0]);
   else if(colloc==0x0D)
   return(dat[rowloc][1]);
   else if(colloc==0x0B)
   return(dat[rowloc][2]);
   else
    return(dat[rowloc][3]);
    }
    }



can you please give me the solution for this problem.

- - - Updated - - -

My Circuit Diagram Is:
 
Last edited by a moderator:

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
19,454
Helped
4,300
Reputation
8,605
Reaction score
4,260
Trophy points
1,393
Activity points
129,013
Hi,

Well documented code...

You have to insert delay after output row and before input col.
Be sure to enable pullup at col.

Klaus
 

gauravkothari23

Advanced Member level 2
Joined
Mar 21, 2015
Messages
508
Helped
3
Reputation
6
Reaction score
3
Trophy points
18
Activity points
4,751
sorry friend.... as i am new to electronics and programming part......did not get you....
can u please explain me bit clearly or practically...
 

gauravkothari23

Advanced Member level 2
Joined
Mar 21, 2015
Messages
508
Helped
3
Reputation
6
Reaction score
3
Trophy points
18
Activity points
4,751
is it necessary to power the keypad(5V).
or have to add an 1K resistor at all ports
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
19,454
Helped
4,300
Reputation
8,605
Reaction score
4,260
Trophy points
1,393
Activity points
129,013
Hi,

before you post your code next time, please document it, so we know what you want to do.
Reading - and understanding - undocumented code is hard to do.

****
insert delay:

Code:
/* output row */
    ROW=0xFE;
/* delay 1ms, wait for signals to settle */
      msdelay(1);
/* input col */
     colloc=COL;

you must do this every time you scan a row.

Klaus
 

gauravkothari23

Advanced Member level 2
Joined
Mar 21, 2015
Messages
508
Helped
3
Reputation
6
Reaction score
3
Trophy points
18
Activity points
4,751
can u plz explain me how to enable pullup at column.
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
19,454
Helped
4,300
Reputation
8,605
Reaction score
4,260
Trophy points
1,393
Activity points
129,013
Hi,

I'm not familiar with this microcontroller,
So you have go read datasheet on your own.

Hint:
Column is on port2.
Open pdf and do a search on "pullup".
At least this is how i would do..

Klaus
 

gauravkothari23

Advanced Member level 2
Joined
Mar 21, 2015
Messages
508
Helped
3
Reputation
6
Reaction score
3
Trophy points
18
Activity points
4,751
Appreciate You and your ideas.

Have tried changing the code as u said...
it worked perfectly....
and u said about the pullup.
actually 89S52 has an internal pullup...
So i would really thank you a lot....
Thanks....
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
19,454
Helped
4,300
Reputation
8,605
Reaction score
4,260
Trophy points
1,393
Activity points
129,013
Hi,

thanks. Good to hear that i could help.


Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top