Keypad Library

mikroPascal PRO for ARM provides a library for working with 4x4 keypad. The library routines can also be used with 4x1, 4x2, or 4x3 keypad.

External dependencies of Keypad Library

Stellaris

The following variable must be defined in all projects using Keypad Library: Description : Example :
var keypadPort : dword; sfr; external; Keypad Port. var keypadPort : byte at GPIO_PORTH_DATA;
var keypadPort_Direction : dword; sfr; external; Keypad Port direction. var keypadPort_Direction : byte at GPIO_PORTH_DIR;

MSP432

The following variable must be defined in all projects using Keypad Library: Description : Example :
var keypadPort : word; sfr; external; Keypad Port. var keypadPort : word at DIO_P5OUT;
var keypadPort_Direction : word; sfr; external; Keypad Port direction. var keypadPort_Direction : word at DIO_P5DIR;

STM32

The following variable must be defined in all projects using Keypad Library: Description : Example :
var keypadPort_Input : dword; sfr; external; Keypad Input Port. var keypadPort_Input : dword at GPIOD_IDR;
var keypadPort_Output : dword; sfr; external; Keypad Output Port. var keypadPort_Output : dword at GPIOD_ODR;

CEC1x02

The following variable must be defined in all projects using Keypad Library: Description : Example :
var keypadPort_Input : byte; sfr; external; Keypad Input Port. var keypadPort_Input : byte at GPIO_INPUT_010_017;
var keypadPort_Output : byte; sfr; external; Keypad Output Port. var keypadPort_Output : byte at GPIO_OUTPUT_010_017;

Library Routines

Keypad_Init

Prototype

procedure Keypad_Init();

Description

Initializes given port for working with keypad.

Parameters

None.

Returns

Nothing.

Requires

External dependencies of the library from the top of the page must be defined before using this function.

Example

Stellaris

// Keypad module connections
var keypadPort : byte at GPIO_PORTH_DATA;
var keypadPort_Direction : byte at GPIO_PORTH_DIR;
// End Keypad module connections
...
Keypad_Init();

MSP432

// Keypad module connections
var keypadPort : word at DIO_P5OUT;
var keypadPort_Direction : word at DIO_P5DIR;
// End Keypad module connections
...
Keypad_Init();

STM32

// Keypad module connections
var keypadPort_Input:  dword at GPIOD_IDR;
var keypadPort_Output: dword at GPIOD_ODR;
// End Keypad module connections
...
Keypad_Init();

CEC1x02

// Keypad module connections
var keypadPort_Input:  byte at GPIO_INPUT_010_017;
var keypadPort_Output: byte at GPIO_OUTPUT_010_017;
// End Keypad module connections
...
Keypad_Init();
Notes

The Keypad library uses lower byte (bits <7..0>) of keypadPort.

Keypad_Key_Press

Prototype

function Keypad_Key_Press(): word;

Description

Reads the key from keypad when key gets pressed.

Parameters

None.

Returns

The code of a pressed key (1..16).

If no key is pressed, returns 0.

Requires

Port needs to be initialized for working with the Keypad library, see Keypad_Init.

Example
var kp : word;
...
kp := Keypad_Key_Press();
Notes

None.

Keypad_Key_Click

Prototype

function Keypad_Key_Click(): word;

Description

Call to Keypad_Key_Click is a blocking call: the function waits until some key is pressed and released. When released, the function returns 1 to 16, depending on the key. If more than one key is pressed simultaneously the function will wait until all pressed keys are released. After that the function will return the code of the first pressed key.

Parameters

None.

Returns

The code of a clicked key (1..16).

If no key is clicked, returns 0.

Requires

Port needs to be initialized for working with the Keypad library, see Keypad_Init.

Example
kp := Keypad_Key_Click();
Notes

None.