Summary of Connect Matrix Keypad with PIC Controller Code
The mikroC PRO for PIC offers a library to interface with 4x4, 4x1, 4x2, or 4x3 keypads. It initializes ports and provides functions like Keypad_Init, Keypad_Key_Press, and Keypad_Key_Click to detect and process inputs. The example demonstrates converting key codes to ASCII and displaying them on an LCD while counting presses.Parts used in the mikroC PRO for PIC Keypad Project:
- 4x4 Keypad (or 4x1, 4x2, 4x3)
- PIC Controller
- LCD Display
- Keypad Library
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; |
Library Routines
Keypad_Init
| Prototype | void Keypad_Init(void); |
|---|---|
| Returns | Nothing. |
| Description | Initializes port for working with keypad. |
| Requires | Global variable :
must be defined before using this function. |
| Example |
C source
|
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 |
Code listing (2)
|
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 |
Code listing (3)
|
Code Example
Quick Solutions to Questions related to mikroC PRO for PIC Keypad Project:
- What is the purpose of the Keypad_Init function?
It initializes the port for working with the keypad. - How does Keypad_Key_Press behave when no key is pressed?
It returns 0 if no key is pressed. - Can this library be used with keypads other than 4x4?
Yes, it can also be used with 4x1, 4x2, or 4x3 keypads. - What happens if multiple keys are pressed simultaneously in Keypad_Key_Click?
The function waits until all pressed keys are released before returning the code of the first pressed key. - What range of values does Keypad_Key_Click return?
It returns a value from 1 to 16 depending on the key. - Which variable must be defined before using the Keypad library?
The global variable keypadPort must be defined. - Does Keypad_Key_Click wait for a specific action?
Yes, it is a blocking call that waits until a key is pressed and then released. - How are key codes transformed in the provided code example?
The returned codes are transformed into ASCII codes [0..9,A..F] and displayed on the LCD.
Related projects
CAN FD Node based on a PIC18 Microcontroller
The introduction sets the stage for an embedded systems project that involves developing a Embedded C CAN FD project using the MCP2517FD...
Communication & InterfacingLAN9662 Gigabit Switch: Optimized for Industrial Ethernet
Introduction It should come as little surprise therefore that one element of what is now more commonly referred to in some circles...
Communication & InterfacingPIC Microcontroller: Fundamentals & Applications for Students
Introduction Microcontrollers are the key components in the embedded systems market. A variety of embedded systems was formed and developed after the...
Communication & Interfacing10BASE-T1S Ethernet: Simplified OEM Design for Auto Devices
Introduction Cars these days are surrounded by technology. They come loaded with all sorts of electronic gadgets and sensors. This project wants...
Communication & InterfacingDesigning a Microcontroller Framework for PC-Based Control of Electrical Appliances
ABSTRACT The preference for personal computers as a platform for designing and implementing control algorithms is growing due to the ease of...
Communication & InterfacingEfficient Multichannel Data Acquisition with USB Connectivity using PIC Microcontroller
1. INTRODUCTION With the rapid advancements in embedded technology, there is a growing demand for a data acquisition system that combines fast...

