Hi following is the routine i found at net for 4x4 matrix keypad in C.
www.8051projects.net/.../8051-programming.php
can i use this to display digits using the keypad inputs or do i need any keypad numabers matrix to be assigned?. If yes, Can sombody reply me the simple main code[while(1)] to monitor the key lets say if 5 is pressed then make P1 as high or something like that?. I just want to display digit 5 using keypad.
Thanks in advance.
The function get_key() does not take any parameter. It returns a value, so you call it with key=get_key().
Thanks a lot. this is where my actual doubt is.
So, while (1){ key = get_key(); If(key == 5){ P1 = 1; } If(key == 6){ P1=0; } }
So it will keep monitoring key value from get_key() and will assign to local variable key, if 5 P1 -> high, If 6 P1->low.
Will try the routine and this code with keil.
Hi Per Westermark, Thanks for your help, It is working fine. Will give the remaining code since it will helpful to other peoples like me, The remaining code for the above routine is,
void main(){ unsigned int key; key_init(); while (1){ key = get_key(); If(key == 5){ P1 = 0xFF; } If(key == 6){ P1=0; } } }
Where the above works fine which will simply make P1 as high if key value is 5 and low if 6. For remaining keys it will latch the previous value.
It is often better to use space instead of tab for indenting the code. With spaces, the indent will be consistent when switching between editors or when presenting the code on the net.
Another thing. For an 8-bit processor, the code will be smaller and faster if you use 8-bit variables whenever you can, instead of using the 16-bit int data type.
Don't retype source code when making posts. Always copy/paste, to make sure you don't introduce errors. In C, the keyword is "if", and not "If".
In C, a function that doesn't take parameters should be specified with "void" instead of an empty list between the parentheses.
int main(void){ unsigned char key; key_init(); while (1) { key = get_key(); if (key == 5) { P1 = 0xFF; } if (key == 6) { P1 = 0; } } return 0; }
I would simply recommend that you always use spaces for indenting code - never use TABs!
The interpretation of TABs is entirely undefined - even different users of the same application may see different results due to different user settings!
The only thing you can be certain of with TABs is that they will not give reliable results!
Thanks for your kind guidance, Since i am in learning phase, i am making many mistakes. Will try to rectify it through experience.
I made the program as u said, It was working great. So i got excited, Your coding style is really good, Will follow it in future.
Thanks.