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
  • 1) You didn't properly tag the code when you posted.

    2) You have a bug - but doesn't seem to have done any debugging.

    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

    Debugging is about figuring out and solving the differences between expected behavior and actual behavior. And you are expected to be first-line support, yourself.

    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;
    }
    


    So - have you stepped through this step-by-step comparing map with reality?

Reply
  • 1) You didn't properly tag the code when you posted.

    2) You have a bug - but doesn't seem to have done any debugging.

    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

    Debugging is about figuring out and solving the differences between expected behavior and actual behavior. And you are expected to be first-line support, yourself.

    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;
    }
    


    So - have you stepped through this step-by-step comparing map with reality?

Children