??? 08/21/08 19:00 Read: times |
#157644 - Lots of things to look into Responding to: ???'s previous message |
Don't do a dummy-loop for delay. You can't know how long it will take. With high optimization, the compiler may remove all code, resulting in zero delay.
Configure a timer and either wait for a timer interrupt, or poll the timer to check when x us or ms has passed. The col_check() function feels quite strange, since it doesn't start with an assign of the col_no variable, but tests it a lot before writing a result into it. Move the line col_no=col; into this function instead, so you can see the full function of the column check. Your code looks for first zero column - what if multiple keys are pressed? Your debounce busy-loops until col != 0xff. Then you try a debounce by having a delay and then one more busy-loop until col != 0xff. But if the key has been released during the delay, then your next key-press will not have any debounce, since your code is already at the second wait. You also have a variable debounce that isn't used in your code - you only make assigns to it, but never tests it. Don't you think it feels a bit strange that you only return a key after the key has been released. It is often better to return when pressed, and the next time you enter the scan routine, you wait until you have seen the key released for a couple of samples that you "arm" the code to look for a new key press. Then you can also extend the code to generate auto-repeat until the key has been released. You don't need to rotate your row bits i steps on every loop. Skip the temp variable and assign tmp row instead. Then rotate one step / iteration. If you want to remove the rotation, you can instead shift the value 1 i steps and invert the result, i.e. row = ~(1 << i); You have a number of time slots where the code may fail. For example: You wait until col != 0xff. Then you copy col to col_no before checking. col_check() assumes that at least one column is active, but the gap between the test for col != 0xff and the assign may be enough for the key to be released. Then col_check() will return 8, instead of the expected range 0..7. Your lookup of pressed key is "key_matrix[col_no]" - but that is a one-dimensional lookup. You have to think about the current row value also. |
Topic | Author | Date |
problem in 8x8 keypad | 01/01/70 00:00 | |
I see ... | 01/01/70 00:00 | |
this code with correction | 01/01/70 00:00 | |
Try the Insert Code button. | 01/01/70 00:00 | |
code with comment | 01/01/70 00:00 | |
Lots of things to look into | 01/01/70 00:00 | |
reply | 01/01/70 00:00 | |
One way to debounce | 01/01/70 00:00 | |
One Suggestion | 01/01/70 00:00 | |
the easy way to do keypads | 01/01/70 00:00 | |
indent, indent, indent | 01/01/70 00:00 | |
problem in keypad | 01/01/70 00:00 | |
Where is the code? | 01/01/70 00:00 | |
code of 8x8 keypad | 01/01/70 00:00 | |
Simplify and think about debounce![]() | 01/01/70 00:00 |