keyboard

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

Author Javier Martínez, Copyright (c) 2003, all rights reserved.
Adapted-by Eur van Andel, eur@fiwihex.nl, Joep Suijs
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 A     row1  
     4 5 6 B     row2 
     7 8 9 C     row3 
     * 0 # D     row4 



 col 1 2 3 4


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
             10          *
             11          #
             12 .. 15    ???
             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:

16f876a16f876a_keyboard_lcd.jal
16f877a16f877a_keyboard_lcd.jal