keyboard

keyboard, scans 4x4 keybaord and returns 0x00..0x0F is keypressed, 0x10 if none pressed

Author Javier Martínez, Copyright © 2003, all rights reserved.
Adapted-by Eur van Andel, eur@fiwihex.nl, Joep Suijs, Rob Hamerling
Compiler >=2.4g

Description

This library is used to scan a 4x3 or 4x4 keyboard.
To use it, you need to define three variables:
   keydrive is the half port (_high or _low) with the cols connected.
   keydrive_direction is the related direction register.
   keyscan  is the half port (_high or _low) with the rows connected.



   Example:



   var volatile byte keyscan  is porta_low      -- rows of keyboard
   var volatile byte keydrive is portb_low      -- columns of keyboard
   var volatile byte keydrive_direction is portb_low_direction
   include keyboard
Note: if you don't want keyboard.jal change the direction of your pins, make sure all
keydrive pins are set to output before you call the library and define:
   var volatile byte keydrive_direction is keydrive



The library has two functions to read the keyboard:
getkey()       returns the key pressed.
getkey_once()  returns a pressed key only once (and 'none', 0x10 until the next key is pressed)



Hardware setup: connect the keyboard rows to a half port (higher or lower 4 bits of a port)
and connect the cols to a half port. Put a pull-down resistor (10k - 47k) on each row pin.
Adaptation: soldering your wires in the right order is a lot harder than you think.
Make sure you keep the rows and cols together and connect them to right port.
You could either adapt your wiring to match the default configuration or reconfigure the
library by defining the next 8 constants before you include keyboard.jal, like:
   const row1 = 0b0000_0100
   const row2 = 0b0000_0001
   const row3 = 0b0000_0010
   const row4 = 0b0000_1000
   const col1 = 0b0000_1000
   const col2 = 0b0000_0010
   const col3 = 0b0000_0100
   const col4 = 0b0000_0001
Connect the keyboard and press the buttons. Adapt the row and column constants so
pressing the buttons give the right result.
Note: you need to specify all 8 constants, even when you have a 4x3 keyboard. In
this case you can specify:
   const col4 = 0b0000_0000



keyboard map (4x4, col4 is left out with 4x3 keyboard)



     1 2 3 C     row 1
     4 5 6 D     row 2
     7 8 9 E     row 3
     * 0 # F     row 4



 col 1 2 3 4


Notes

[RobH] Added a 1 microsecond delay after changing keydrive
              to obtain reliable results with oscillator frequencies
              of 8 MHz and higher


Dependencies

No dependency found



Summary

Global variables/contants

Procedures

Functions


API details

Global variables/contants

Procedures

Functions

  • getkey() return byte

    getkey - return the key pressed (until it is released)
    
    return:  0 .. 9      numeric key pressed 0..9
    10          * (or A)
    11          # (or B)
    12 .. 15    C, D, E, F
    16          no key pressed.
    17          error (more then one key pressed)
    
    

  • getkey_once() return byte

    getkey_once - return the value of a key pressed only once
    
    returns: see getkey()
    
    


Related samples

Here are the list of samples which use this library:

16f648a16f648a_keyboard.jal
16f72316f723_keyboard.jal
16f7316f73_keyboard.jal
16f876a16f876a_rtc_timeset.jal
16f876a16f876a_keyboard_lcd.jal
16f87716f877_keyboard.jal
16f877a16f877a_rtc_timeset.jal
16f877a16f877a_keyboard_lcd.jal
16f877a16f877a_keyboard.jal
16f8816f88_keyboard.jal
18f14k5018f14k50_keyboard.jal
18f245018f2450_keyboard.jal
18f252018f2520_keyboard.jal
18f255018f2550_keyboard.jal
18f262018f2620_keyboard.jal
18f26j1118f26j11_rtcc_hw_kbd_lcd.jal
18f45218f452_keyboard.jal
18f455018f4550_keyboard.jal
18f462018f4620_keyboard.jal
18f67j5018f67j50_keyboard.jal