04-05-2016, 10:11 AM
Abstract
A keypad consists of 3 columns and 4 rows, hence the name, whenever the user taps one button, the column and the row corresponding to that button are shorted, for example, if a user chooses to tap the "5" button, col2 and row2 are shorted, if a users picks "0" button, col2 and row4 are shorted, and so on.
So how do you read a keypad using a Microcontroller?
the method used to read such input is called Scanning, you connect the rows and the columns to the microcontroller, you set the columns as outputs, rows as inputs (or vice versa) and you start feeding a pattern of inputs to the columns while checking the readings of the rows.
For example, if you tied all rows through pull-up resistors to Vcc, all row inputs are typically 1s (1111), now if you start feeding columns with the following pattern, 011, 101, 110, you can check which row conducts the 0 signal to the controller, thus, you'll detect the shorted row and column.
example: if a user presses button "6", when I feed the columns by 011, the rows output would be 1111, when I feed it by 101, the rows output would be also 1111, but when I feed it by 110, button "6" will conduct the 0 signal, thus my rows output would be 1011, Knowing that I used col3 to conduct the 0 signal, and I got the 0 signal at row2, I'll know the pressed button is "6".
Using PIC-C to Read a Keypad:
PIC-C provides a common library for reading keypads named kbd.c, all you have to do is to include the kbd.c library in your code, and use the function kbd_getc() to scan the keypad.
kbd.c library uses either port D or port B to interface the keypad, you'll find the schematic for the interface further below, but if you need to use other ports to interface your keypad, you'll have to use a user defined library, you can find those on ccsinfo.com forum, or you can write your own library (which is pretty simple).
Note: the kbd_getc(); function returns the ASCII code of the pressed button (returns a character).
The Alphanumeric LCD:
An alphanumeric LCD is a type of LCDs that only displays English letters, numbers and some ASCII characters, those LCDs contains a controller unit that processes the input and forms the displayed character on the LCD, most alphanumeric LCDs have a parallel interface, some other LCDs have a serial interface to minimize the construction complicity.
Alphanumeric LCDs comes in different sizes, the size describes the number of characters an LCD can display, common sizes are 16x2, 20x2, 16x4, 20x4 ..etc. a 16x2 has 2 rows and can display 16 characters on each row.