In this article let’s discuss designing of matrix keypads and the programming part to get the information regarding the pressed key. The Matrix keypads are used in systems/control panels where Human Machine Interface (HMI) is required in order to change the operating parameters of a system/machine. The Computer keyboard is also a matrix keypad. The name itself infers that it has some keys arranged in rows and columns. Here arrangement of keys doesn’t mean the layout of the keys or physical placement on the circuit board, but the keys are identified in terms of elements of a matrix like M11, M12, and so on… up to M44 for a 4X4 Matrix Keypad. The advantage of these matrix keypads is that all the switches of the matrix can be read using lesser number of I/O pins of a processor/microcontroller. For example, consider a 4X4 Matrix keypad, which contains 4*4=16 Keys. We need 16-Pins of the microcontroller in order to read the status of these 16 switches/push buttons individually. But, by using the Matrix type of configuration just 8-Pins are sufficient. In this case, the Pin count is halved. Connecting the Push Buttons in a Matrix Keypad Format Let’s take 4X4 Matrix Keypad as a reference and understand the connections. For a 4X4 keypad there are 4*4=16 push buttons. For easy understanding, let’s arrange these 16 push buttons as the elements of a 4X4 Matrix i.e.., in four rows and four columns. These are electrically connected as shown below. As every button switch has two terminals, Terminal 1 of each switch in a row is connected to other switches. Similarly, switches in each column have one of their terminals connected to the remaining switches in the same column, thus giving out 4 pins representing four rows and 4 pins representing four columns. Programming a Microcontroller to Read the Pressed Key The pressed key is identified in terms of rows and columns. For this purpose, we will enable the columns one by one (by issuing logic HIGH) and then read the row which is enabled due to the pressed key for each of the columns. If there is no key in pressed state, then all the rows are read as LOW. The same procedure can be followed by interchanging the rows and columns. Now, let’s put the logic into a C-Program. For 4X4 Matrix, in a microcontroller, we need 4-Pins as outputs for enabling the columns and 4-Pins as inputs for reading the rows. The variable named as ‘column’ contains the information regarding the enabled column. The same data is loaded into PORTC using a temporary variable. This temporary variable is initially loaded with value ‘1’ and is left shifted by multiplying it with ‘2’ each time when the loop is executed. ‘For loop’ is restarted with temp=1 and column=1. As every row contains 4 switches, the switches of row 1 can be valued as columns. When a switch from the second row is pressed, as there are 4 switches before row 2, it is valued as ’4+column’. Thus, our logic is converted into C-Program. The identified key can be used according to the required application. In this example program, let’s show the number of the pressed key. For this purpose, a switch label with 16 cases for 16 keys is used to show the key value in Hexadecimal format. Key Debounce The switches that are used in the matrix keypad can be of various types. The Mechanical parts of the push buttons do not change their states in a smooth fashion. They produce a transient output which might be understood...
read more
The post Matrix Keypad Interfacing Using Proteus appeared first on Electronic Circuits and Diagram-Electronics Projects and Design.
No comments:
Post a Comment