Positron Compiler Documentation

Inkey

Source: Positron8 Compiler User Manual, PDF page 156

+5 Volts R1 4.7k RB7 VDD MCLR R2-R5 C1 10uf C2 0.1uf 4MHz Crystal OSC1 RB6 RB5 RB4 RB3 RB2 RB1 RB0 PIC16F84

Syntax

Variable = Inkey

Overview

Scan a keypad and place the returned value into variable

Parameters

Variable is a user defined variable

Example

Dim bVar1 as Byte
bVar1 = Inkey
                        ' Scan the keypad
DelayMs 50
                        ' Debounce by waiting 50ms
Print Dec bVar1, " "
                        ' Display the result on the LCD

Notes

Inkey will return a value between 0 and 16. If no key is pressed, the value returned is 16.

Using a LookUp command, the returned values can be re-arranged to correspond with the legends printed on the keypad: -

bVar1 = Inkey
bKey = LookUp bVar1, [255,1,4,7,"*",2,5,8,0,3,6,9,"#",0,0,0]

The above example is only a demonstration, the values inside the LookUp command will need to be re-arranged for the type of keypad used, and its connection configuration.

Declare for Inkey

Declare Keypad_Port Port

Assigns the Port that the keypad is attached to.

The keypad routine requires pull-up resistors, therefore, the best Port for this device is PORTB, which comes equipped with internal pull-ups. If the Declare is not used in the program, then PORTB is the default Port.

The diagram illustrates a typical connection of a 12-button keypad to a PIC16F84. If a 16-button type is used, then COL- UMN 4 will connect to PORTB.7 (RB7). R O W S OSC2 C3 22pf C4 22pf RA4 RA3 RA2 RA1 RA0 VSS

#

*

0v COLUMNS