# keyboard

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

Author | Javier Martnez, 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

- `var byte scan0, scan1, scan2, scan3`
- `var byte lastkey = 0xff`

### Procedures

### Functions

- `getkey() return byte`
- `getkey_once() return byte`

## API details

### Global variables/contants

- `var byte scan0, scan1, scan2, scan3`

  No documentation found

- `var byte lastkey = 0xff`

  No documentation found

### 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:

16f648a | 16f648a_keyboard.jal
16f723 | 16f723_keyboard.jal
16f73 | 16f73_keyboard.jal
16f876a | 16f876a_rtc_timeset.jal
16f876a | 16f876a_keyboard_lcd.jal
16f877 | 16f877_keyboard.jal
16f877a | 16f877a_rtc_timeset.jal
16f877a | 16f877a_keyboard_lcd.jal
16f877a | 16f877a_keyboard.jal
16f88 | 16f88_keyboard.jal
18f14k50 | 18f14k50_keyboard.jal
18f2450 | 18f2450_keyboard.jal
18f2520 | 18f2520_keyboard.jal
18f2550 | 18f2550_keyboard.jal
18f2620 | 18f2620_keyboard.jal
18f26j11 | 18f26j11_rtcc_hw_kbd_lcd.jal
18f452 | 18f452_keyboard.jal
18f4550 | 18f4550_keyboard.jal
18f4620 | 18f4620_keyboard.jal
18f67j50 | 18f67j50_keyboard.jal