This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

problem with interfacing keypad

Hey everoone! I'm using a lpc2138, And I wanna make a mini-project in this way that I have a keypad on port1(rows on P1.16 to P1.19)(columns on P1.20 to P1.23) and a lcd on port0, I want it that Once I click on a buttom of the keypad, the LCD shows the number of buttom (That Simple!).

The Lcd works, but I don't know what the problem is about the keypad! Actually I guess there is a problem in the subrootin that I have made for keypad.

It will be a pleasure if you tell me what the problem is!
thank you

Here is my code:

#include <lpc21xx.h>
#include "lcd4bit.h"
//////////////////////
int keypad(void)
{ int codes[4][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
int i,j,a=20;
IODIR1=0XF<<16;
for(i=0;i<4;i++)
{ IOSET1=0XF<<16;
IOCLR1=1<<(16+i);
delay(2);
if(IOPIN1 & 0XF<<20 != 0XF<<20 )
{

for(j=0;j<4;j++)
{ if(IOPIN1 & (1<<(j+20))==0 ) a=codes[i][j];
} }
else
a=20;

}
return a;
} ///////////////////////////////
int main(void)
{ int i,k=20;
char s[20];
IODIR0=0XFFF;
lcd_init();
sprintf(s,"NUMBER");
lcd_print(s);
while(1)
{ while(k==20)
k=keypad();
if(k!=20)
{ sprintf(s,"I=%d",k);
lcd_gotoxy(1,0);
lcd_print(s);
} }
}

Parents
  • Oh god.....dear my friend I did all of things you mentioned....I did all about debuging and pen-and-paper and I tried my best to debug it...but I could'nt debug it and that was why I asked my problem in this forum!

    Anyway let me ask you my question in this way.....
    I wanna learn it as a starter.....WHAT DO U SUGGEST TO WRITE AS A FUNCTION OF READING KEYPAD???

    That's it!

Reply
  • Oh god.....dear my friend I did all of things you mentioned....I did all about debuging and pen-and-paper and I tried my best to debug it...but I could'nt debug it and that was why I asked my problem in this forum!

    Anyway let me ask you my question in this way.....
    I wanna learn it as a starter.....WHAT DO U SUGGEST TO WRITE AS A FUNCTION OF READING KEYPAD???

    That's it!

Children
  • So if you did all that - why not present it here, following the bullet list I posted earlier?

    Proper posts about a bug would be:
    - what output stimuli you give in the code
    - what the output pins actually does
    - what the input pins reads
    - what you expected the input pins to read
    - your conclusions why you think actual and expected differ

    This is not black magic. If you did what you claimed you did, you would already have solved your problems.

    If your assumptions and reality matches, then you would get a correct answer, wouldn't you? So if you don't get a correct answer, then you must be able to spot a difference between what you assumed, and what actually happened. Just that the processor is very exact in what it is doing - it doesn't gloss over the instructions but performs them one-by-one exactly as written. Have your pen-and-paper test done that?

    In the end, debugging is one of the critical parts of software development your school wants you to learn.

  • just a sidebar
    what the output pins actually does
    if you configure the output pins for push-pull you get pretty blue smoke when someone push two buttons at the same time.