A little bit more code that (maybe) will help U understand the previous one :lol:
At the start you will find the declaration of some constants KeyPadAddress to Key_F. If you have other keys on your keypad change the name but not the data. e.g. If the key in col3 row3 is * instead of F, change the name Key_F to Key_Star but leave the data 000Fh unchanged.
Part 1: contains the endless loop.
If bit KeyRead is not set, there's no key pressed by the user so you can skip all the key stuff and do other things from LBL_001 on.
When the user press a key, the KeyPad module will set bit KeyRead and then you can jump into the key stuff (part 2).
Part 2: do key depending stuff
The KeyPad module writes a number from 0 to F into variable KeyCode depending on the pressed key. By comparing that variable with all the Key_0 to Key_F constants you will know what key is pressed.
Note that you don't need to check all the keys. If at a certain point in your programm you are interrested in keys 0 to 9, C and E, just check these keys only.
But don't forget to clear the KeyRead bit at the end!!!
Last Part:
Has to remain the last part in you program. The KeyPad module place an ascii character from that list into variable KeyAscii. Again, if the key in col3 row3 is * instead of F, replace that string by '0123456789ABCDE*'.
If you have an LCD in your project, you can write that variable directly to your LCD.
In the timer interrupt routine you need only one line of code for the KeyPad module:
Because the module use the datapointer you have to push it onto the stack.
Remember, if your compiler understand all the definitions in the KeyPad module, you don't have to change anything in that file. Just use it as a black box in all your future projects.
Have fun ...