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); } } }
"How this function does't give me an output number to print on the lcd??"
And that is exactly where you are expected to do debugging.
Have you bothered to look at processor pins and compared to what you expected?
Have you bothered to run it with pen-and-paper?
Writing software isn't just about pasting code into the editor - you also have to check if the code does what you expect it to do. And you have to check if what you expect the code to do matches what the customer/teacher expects it to do.
And it still doesn't sound like you have done any debugging of your keyboard code - it's irrelevant how well the LCD code works if you don't test the keyboard code.
Remember that you can stop time and set up all pins for one specific row/col combination and verify the pin states. Try that four all for combinations of the outer loop with one button pressed. Then you can with pen-and-paper run the full code and see what it would produce based on such pin states. If it fails, then you have found a bug.
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!
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.