Most of the applications of embedded systems require keypads to take the user inputs, especially in case where an application requires more number of keys. With simple architecture and easy interfacing procedure, matrix keypads are replacing normal push-buttons by offering more inputs to the user with the lesser I/O pins. As a Human Machine Interface (HMI) keypad plays a major role in vital microprocessor and microcontroller based projects and equipments. Therefore, this article gives you a brief idea on matrix keypad interfacing with 8051 microcontroller.
Introduction to Matrix Keypad
A Matrix keypad is the most commonly used input device in many of the application areas like digital circuits, telephone communications, calculators, ATMs, and so on. A matrix keypad consists of a set of push button or switches which are arranged in a matrix format of rows and columns. These keypads are available in configurations like 3×4 and 4×4 based on the application it is implemented for. Internal diagram of this matrix keypad is shown in the below figure.
Matrix Keypad Interfacing with 8051 Microcontroller
Matrix keypad can be connected to the microcontroller in numerous ways or techniques, but the fundamental logic is same as making the columns as input and the rows as output. So, in order to detect the key pressed from the keypad, the row lines have to be made low one by one and to read the columns. So let us discuss in brief about 8051 microcontroller interfacing with this matrix keypad.
- In this project a 4×3 matrix keypad is interfaced to the microcontroller, which is a 12-key keypad consisting of four rows and three columns.
- The upper pins of port 1, i.e., pin 1.0 to pin 1.3 of the microcontroller are connected to the row lines of the keypad and lower pins (pin 1.4 to pin 1.6) are connected to the column lines. These are connected in such a way that the column lines acts as input to the microcontroller , and the row line as output lines. The input lines are pulled up internally.
- Here 16×2 LCD is connected to the port 0 and port 2 pins. As the port 0 has no internal pull up, it is pulled up externally using a set of resistors which are connected to 8-data lines of the LCD. And control lines of the LCD are connected to the Port 2 pins.
- As the given circuit is simulated, one RESET and crystal oscillator circuits are not necessarily be connected. But for hardware implementation these must be provided.
- Make sure that the all the rows of port 1 high in order to give the signal to microcontroller when any key is pressed.
- The working of the keypad goes like this: If any of the keys in row1 of the matrix keypad is pressed, the corresponding column line will give low and similarly if the second key is pressed in row1, then the column line 2 will give low. This process is repeated for all the rows.
- When the circuit is powered and any key is pressed, then corresponding pins of the port 1 get enabled. Depending on the program in the microcontroller, it displays the number on the 16×2 LCD. But this cannot display any number when two keys are pressed at the same time. The program code of the above given interfacing circuit is given below.
Applications of the Interfacing Keypad with 8051
Keypad Interfacing to Password Based Load Control
This system switches the loads based on the password entered from the keypad. This is of security based load control system and is one of the concept of industrial automation systems. The figure shows the matrix keypad interfacing with the 8051microcontroller for entering password in order to have switching operation of loads. (Here a set of lights indicates the electrical loads or appliances).
The 8051 microcontroller acts as a central controller, which accepts the inputs from the matrix keypad and correspondingly control the loads. Here the control circuit is powered with regulated DC power supply and loads are with AC mains supply. A relay driver is interfaced to the microcontroller for switching the relays corresponding to the loads. This 8051 microcontroller and its programming is done in such a way that the password entered from the keypad is compared with the pre-stored password in the ROM of the microcontroller. If the password matches, then the control signals are sent to the relay driver to switch the load. The information of the password authentication and load switching is also displayed on the LCD.
Keypad Interfacing to Programmable Medication Reminder
This project reminds people to take their medicines on time, which is engaged by a doctor. This system is very helpful for the elderly persons and people who are busy and forget taking medicines on time. In this system, the keypad interfacing with 8051 microcontroller allows the user to set the timings for each and every medicine as shown in the figure.
A Real Time Clock (RTC) is connected to the microcontroller to have a real time timing operation so that it give an alarm at set timings. A 4×3 matrix keypad is interfaced to the microcontroller for entering the timings prescribed by the doctors. LCD and buzzers are connected to microcontroller as output devices for generating display and alarm indications, respectively. Batteries are connected to power the entire circuit making this as portable so that the user can take it to every place easily.
The 8051 Microcontroller is programmed in such that it continuously scans the set timings with real-time clock, when both matches it generates an alarm by giving control signals to the buzzer and correspondingly displays the medicine information on the LCD display.
This is about the keypad interfacing with 8051 microcontroller circuit, operation, program code and applications. Hope that the reader has got the basic idea of this peripheral interfacing technique with the given examples. For any further help regarding this topic or any other interfacing circuits, you can write to us by commenting below.