### Have You Seen

#### B0505S-1WR3 MORNSUN Isolated DC - DC Converter

Mornsun B0505S-1WR3 DC-DC Isolated ConverterMORNSUN B0505S 1WR3 1 watt, 5 Volts Isolated DC to DC Po..

Rs.106.20 (inc GST)
Rs.90.00 + GST

#### XL1509-Adj E1 Buck DC to DC Converter IC (SOP8L Package)

XL1509-Adj E1 Buck DC to DC Converter IC (SOP8L Package)XL1509-Adj E1 Buck DC to DC Converter IC, Ad..

Rs.25.96 (inc GST)
Rs.22.00 + GST

# Interfacing Matrix Keypad to 8051

Before learning “Interfacing Matrix Keypad to Microcontroller” you should know how to interface a switch to microcontroller for which please click here.

As you have seen in the article for interfacing switches to microcontroller normally the port pin is high but when a switch is pressed the controller pin gets a Low signal and we come to know that a switch has been pressed. One end of switch is connected to the port pin whereas the other end is connected to the Ground.

In case of matrix Keypad both the ends of switches are connected to the port Pin. Over here we have considered a 4x3 matrix keypad i.e. four rows and three columns. So in all twelve switches have been interfaced using just seven lines.

The adjoining figure shows the diagram of a matrix keypad and how it is interfaced with the controller.

As you can see no pin is connected to ground, over here the controller pin itself provides the ground. We pull one of the Column Pins low & check the row pins if any of the Pin is low then we come to know which switch is pressed.

Suppose we make column 1 pin low and while checking the rows we get Row 3 is low then we come to know switch 7 has been pressed.

 Interfacing Matrix Keypad to 8051

ALGORITHM

1.    Start.

2.    Make All Pins High.

3.    Make Column 1 pin low.

4.    Check if Row 1 is low, if yes then Switch 1 has been pressed.

5.    Check if Row 2 is low, if yes then Switch 4 has been pressed.

6.    Check if row 3 is low if yes then Switch 7 has been pressed.

7.    Check if row 4 is low if yes then Switch 10 has been pressed.

8.    Make Column 1 Pin high & Column 2 Pin Low.

9.    Check if Row 1 is low, if yes then Switch 2 has been pressed.

10.   Check if Row 2 is low, if yes then Switch 5 has been pressed.

11.   Check if row 3 is low if yes then Switch 8 has been pressed.

12.   Check if row 4 is low if yes then Switch 11 has been pressed.

13.   Make Column 2 Pin high & Column 3 Pin Low.

14.   Check if Row 1 is low, if yes then Switch 3 has been pressed.

15.   Check if Row 2 is low, if yes then Switch 6 has been pressed.

16.   Check if row 3 is low if yes then Switch 9 has been pressed.

17.   Check if row 4 is low if yes then Switch 12 has been pressed.

18.   Make column 3 pin high.

19.   Stop.

Please make sure at any time only one column Pin should remain Low.

For the complete working code in Assembly please check the code library or click here.