Proton BASIC Compiler - InkeyX: A New Command to Read Keypads.


  • Pic® Basic


  • InkeyX: A New Command to Read Keypads.

    This new command, based on the PDS Inkey code, lets you include all the options that the user often codes in BASIC when using Proton Inkey.
    A few years ago I created a keypad reading routine based on the PDS InKey command but with modified code to resolve some problems with a keyboard project. It occurred to me to write these libraries to simplify their use and improve performance. The advantage of writing a library is that all options are available but only the options selected by the user will be compiled and loaded into your program.

    This new command includes very important options for PDS users.
    • Delay for reading the PORT.
    • Delay for the debounce routine.
    • Number of readings of the PORT.
    • Choice between NO Auto-Repeat or Auto-Repeat a key.
    • Key conversion table.
    • Number conversion table written by the user.
    • Enable / disable the internal pull-ups resistors of the PIC®.
    InkeyX command syntax.
    Result = InkeyX(Read Delay, Debounce Delay, NOAutoRepeat/AutoRepeat)

    PART 1: Standard Bus
    The configuration of the additional command options must be enabled/disabled before the InkeyX_44.inc, InkeyX_43.inc, InkeyX_42.inc files.
    These libraries should use the Declare Keypad_Port = PORTB (or another PORT).

    Example:
    '$define _Disable_Pullups_
    '$define _NO_KEYPADTABLE_
    $define _NumberKeypadTable_ 3
    $define NumberReadingX 4
    Include "InkeyX_44.Inc"

    4x4 Keypad: library InkeyX_44.inc
    The InkeyX command uses 8 bits of the PIC® PORT in the same manner as the command PDS Inkey and is fully compatible, saving much BASIC code for the user. The demo program is ready to be viewed with the built-in ISIS of the PDS compiler.
    Library_InkeyX_44.zip

    4x3 Keyboard: Library InkeyX_43.inc
    The InkeyX command uses only 7 bits of a PIC® PORT. When using a 4x3 keypad, one pin of the keyboard PORT is free and available for the user.
    Library_InkeyX_43.zip

    4x2 Keyboard (or 8 buttons): Library InkeyX_42.inc
    The InkeyX command uses only 6 bits of a PIC® PORT. When using a 4x2 keypad, two pins of the keyboard PORT are free for the user.
    Library_InkeyX_42.zip

    Note: The InKeyX command may only be written once in your program due to code included in the BASIC macro. However, for purists, I rewrote the code as an example. It's just not as efficient with more lines of compiled code (more Gosub’s).
    4x4 Keypad: library InkeyX_44P.inc
    Library_InkeyX_44P.zip

    Consult the manual for details.
    Manual InKeyX.zip

    PART 2: The new 4-Bits Bus Keypad.
    There are some new Bus 8bits libraries update described in the first part. I just modified only the local variables definitions.
    UpdateInkeyX.zip

    In the second part, I have described the keypads using only 4 bits Bus with the same InkeyX command structure. To fully understand the InkeyX command you have to download the PART 1 manual.
    Result = InkeyX(Read Delay, Debounce Delay, NOAutoRepeat/AutoRepeat)

    A new control option is incorporated when interrupts are used. (See the manual)
    $define _NO_INT_Control_

    New Bus 4 lines keypad:
    In this project I have developed a new code based on a Mike Rigby-Jones’s keypad with his kind permission which is published here:
    http://www.piclist.com/techref/micro...y4io8diode.htm
    http://www.mikerj.clara.net/keypad.html

    I've only chosen the system bus that seemed more reliable for me. From the Mike Rigby-Jones’s design I have developed my own code by using the same InkeyX macro skeleton.
    Thanks to the efficiency of the InkeyX library structure, it was been easier to use multiple keypads with a single file. With this new library 5 different matrix Keypads (up to 24 keys) or with pushbuttons may be used. The 4x4 keypad is defined by default. Now the definitions of the InkeyX library are as follows:

    'Define the Keypad:
    $define _4x6_Keypad_
    '$define _4x5_Keypad_
    '$define _4x3_Keypad_
    '$define _4x2_Keypad_


    'Define the Functions:
    '$define _NO_INT_Control_
    '$define _NO_KEYPADTABLE_

    $define _NumberKeypadTable_ 3
    $define NumberReadingX 4
    Include “InkeyX_P4.Inc”

    Standard 4-bits Bus:
    The 4-bits bus library allows to connect the keypad to any PIC® PORT in the high or low side. This library does not support the PORT LCD yet.
    The new library for any PORT is: InkeyX_P4.inc
    InkeyX_P4.zip

    Keypad Bus shared with LCD:
    The data flowing through the LCD bus is very sensitive, so that, adding a new element that connects the keypad to the LCD bus when needed without affecting its operation. The perfect circuit is a Bus Switch. The keypad needs only the LCD 4 bits Bus + 1 control bit.
    The new library for the LCD PORT sharing with keypad is: InkeyX_LCD.inc
    InkeyX_LCD.zip

    Note: All the above libraries are written in the most efficient manner as possible. So a part of the BASIC code ​​has been written inside the macro. Do not repeat writing the InkeyX command in your main program. Normally it doesn´t matter because you need to write it only once.

    Consult the PART 2 manual for details.
    Manual_InKeyX_4bits_Eng.zip

    I hope these libraries could be useful for your projects with a keypad.

    17/06/2015 Updated the InkeyX drivers to work with PIC(r) of 28 pins.
    InkeyX_Drivers.zip
    Alberto Freixanet (Barcelona Spain)
  • Recent Activity

    Stephen Moss-711

    error in lcd 16x2

    Thread Starter: José

    best regards friends Well, I designed a code with pic 18f2550, this code is for measuring resistors and capacitors, but when simulating in...

    Stephen Moss Today, 14:05 Go to last post