18F Keypad (4*3) Example
Swordfish has its own
keypad library,
but its default use is for 4 * 4
keypads like
the image shown below;

The problem is that a lot
of people use the 4 * 3
keypads without the "ABCD" as shown above. This example
shows you how to use the
Keypad12
Library, a library designed by me for 4 * 3
keypads
- also modified so that users do not require resistors in series with the
different keys, simply a resistor network tying the inputs to earth.

Circuit Diagram:

Note the PIC's
power supply/oscillator are not shown
Click here to
see this circuit in action!
If your using PORTB for the
keypad, then
be sure to disable PORTB internal pullups
if they are not already configured by default.
Notice when I press
"*",
the value 10
is returned, that's because the
"*" key
is the next one inline from the
"9" key.
A simple
Select Case
routine could configure each value. See the
16 Button
Keypad example for more information regarding this approach.
Here is a
basic program covering some aspects of the library;
Device = 18F2520
Clock = 8
Config OSC = INTIO67
Dim Key As Byte
#option KEYPAD_PORT = PORTB
Include "INTOSC8.bas" // sets up the internal oscillator for 8Mhz straight away
Include "usart.bas" // to allow for USART data sending/receiving
Include "Keypad12.bas" // for interfacing with 12 button keypads
include "Convert.bas" // to convert numbers into ascii strings
USART.SetBaudrate(br9600)
While True
// wait for a key to be pressed, then send it via uart
Key = 0
While Key = 0
Key = Keypad12.Value
Wend
USART.Write("Key Pressed: ", Convert.DecToStr(Key), 13)
// wait for the user to release the key
Keypad12.Debounce
Wend
Video Tutorials:
Download
Spency's
Keypad12.Bas Library
Link:
What is a Swordfish
Library?
Where you can get the components;

 | Site Tutorial Index |
|  | 16F PIC Examples |
|  | 18F PIC Examples |
| |  | 7 Segment Displays |
| |  | 7 Segment Displays |
| |  | RS232 and UART |
| |  | Code Snippets |
|  | Handy Tips |