Connect Matrix Keypad with PIC Controller Code




The mikroC PRO for PIC provides a library for working with 4×4 keypad. The library routines can also be used with 4×1, 4×2, or 4×3 keypad. For connections explanation see schematic at the bottom of this page.

External dependencies of Keypad Library

The following variable must be defined in all projects using Keypad Library: Description : Example :
extern sfr char keypadPort; Keypad Port. char keypadPort at PORTD;

Connect Matrix Keypad with PIC Controller CodeLibrary Routines

  • Keypad_Init
  • Keypad_Key_Press
  • Keypad_Key_Click

Keypad_Init

Prototype void Keypad_Init(void);
Returns Nothing.
Description Initializes port for working with keypad.
Requires Global variable :

  • keypadPort – Keypad port

must be defined before using this function.

Example
// Keypad module connections
char keypadPort at PORTD;
// End of keypad module connections
...
Keypad_Init();

Keypad_Key_Press

Prototype char Keypad_Key_Press(void);
Returns The code of a pressed key (1..16).
If no key is pressed, returns 0.
Description Reads the key from keypad when key gets pressed.
Requires Port needs to be initialized for working with the Keypad library.
Example
char kp;
...
kp = Keypad_Key_Press();

Keypad_Key_Click

Prototype char Keypad_Key_Click(void);
Returns The code of a clicked key (1..16).
If no key is clicked, returns 0.
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.
Requires Port needs to be initialized for working with the Keypad library.
Example
char kp;
...
kp = Keypad_Key_Click();

Connect Matrix Keypad with PIC Controller Code schematichCode Example

This is a simple example of using the Keypad Library. It supports keypads with 1..4 rows and 1..4 columns. The code being returned by Keypad_Key_Click() function is in range from 1..16. In this example, the code returned is transformed into ASCII codes [0..9,A..F] and displayed on Lcd. In addition, a small single-byte counter displays in the second Lcd row number of key presses.




Current Project / Post can also be found using:

  • mikroc pro for pic keypad project

Leave a Comment

*
= 3 + 7

Read previous post:
PIC Evaluation/Development Board Implementation using pic-microcontroller

Abstract The objective of this project is to produce a PIC evaluation/development board to be used by future ECPE senior...

Close
Scroll to top