Introduction to Microcontroller Programming
About PICmicro Chips
Clocking Your PICmicro Devices E-Blocks Flowcode Step By Step
PICmicro Projects
Labs |
Exploring the KeypadIn this section we will take a look at how the keypad works. Using the keypad to enter only a single digit is easy enough, but using it to enter numbers larger than 10 introduces some complexities. First the basics though:
In top to bottom icon order this is explained as follows: start the LCD display, an endless loop, set the LCD 'Cursor' to '0,0' (top left), call the 'GetKeypadNumber' macro and put the result in the variable 'key'. Lastly display variable 'key' on the LCD using the LCD 'PrintNumber' macro.
If you run the program you will see that to start with the LCD displays the number 255. This is what the keypad returns when there is no button pressed. When you press a key the display will print the number of the key pressed. However you will notice that it does not erase all of the old number. To do this enter a new LCD Component macro with the function 'Clear' after the 'Cursor 0,0' macro and you will see only the number pressed. On the keypad there are the numbers 0 to 9 as well as # and * keys. These are allocated the numbers 10 and 11. You can use the # and * keys as control characters to allow humans to indicate that the number is complete: a bit like the 'Enter' key on your computer keyboard. To understand how you can use the keypad to enter larger numbers you need to now learn a few new concepts: what ASCII is, and how strings work. |