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:

12 Button Keypad Entry

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:

  • None as yet
  • None as yet

    Download Spency's Keypad12.Bas Library

    Link: What is a Swordfish Library?

Where you can get the components;

 Skip Navigation Links.

Collapse Site Tutorial IndexSite Tutorial Index
Expand 16F PIC Examples16F PIC Examples
Collapse 18F PIC Examples18F PIC Examples
LED's
Switches
Collapse 7 Segment Displays7 Segment Displays
12 Button Keypad
16 Button Keypad
LCD's
Expand 7 Segment Displays7 Segment Displays
ADC
ADC (Another Example)
EEPROM's
DS1307
Expand RS232 and UARTRS232 and UART
DS18B20
External ADC
Hall Effect Sensor
Pulse Width Modulation (PWM)
Infrared UART
Swordfish Modules
Expand Code SnippetsCode Snippets
Expand Handy TipsHandy Tips