We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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); } } }