Aim:
Matrix Keypads are commonly used in calculators, telephones etc where a number of input switches are required. A keypad is a set of buttons arranged in a block or “pad” which usually bear digits, symbols and usually a complete set of alphabetical letters. If it mostly contains numbers then it can also be called a numeric keypad. Keypads are found on many alphanumeric keyboards and on other devices such ascalculators, push-button telephones, combination locks, and digital door locks, which require mainly numeric input.
Description:
We know that matrix keypad is made by arranging push button switches in row and columns. In the straight forward way to connect a 4×4 keypad (16 switches) to a microcontroller we need 16 inputs pins. But by connecting switches in the following way we can read the status of each switch using 8 pins of the microcontroller.
The status of each keys can be determined by a process called Scanning. For the sake of explanation lets assume that all the column pins (Col1 – Col4) are connected to the inputs pins and all the row pins are connected to the output pins of the microcontroller. In the normal case all the column pins are pulled up (HIGH state) by internal or external pull up resistors. Now we can read the status of each switch through scanning.
- A logic LOW is given to Row1 and others (Row2 – Row-4) HIGH
- Now each Column is scanned. If any switch belongs to 1strow is pressed corresponding column will pulled down (logic LOW) and we can detect the pressed key.
- This process is repeated for all rows.
The keypad has 8 communication lines namely R1, R2, R3, R4, C1, C2, C3 and C4. R1 to R4 represents the four rows and C1 to C4 represents the four columns. When a particular key is pressed the corresponding row and column to which the terminals of the key are connected gets shorted. For example if key 1 is pressed row R1 and column C1 gets shorted and so on. The program identifies which key is pressed by a method known as column scanning. In this method a particular row is kept low (other rows are kept high) and the columns are checked for low. If a particular column is found low then that means that the key connected between that column and the corresponding row (the row that is kept low) is been pressed. For example if row R1 is initially kept low and column C1 is found low during scanning, that means key 1 is pressed.
Block Diagram
Schematic
Code
// ********************************************************* // Project: Interfacing keypad to LPC2148 microcontroller // Author: Hack Projects India // Module description: Operate keypad // ********************************************************* #include<lpc214x.h> void delay_ms(double ms); void delay_ms(double ms) { unsigned int i,j; for(i=0;i<ms;i++) for(j=0;j<1000;j++); } int main() { PINSEL0=0x00000000; //set all GPIO pins PINSEL1=0x00000000; PINSEL2=0x00000000; IO0DIR |=0xf0; IO1DIR |=(1<<16)| (1<<17) | (1<<18) |(1<<19)| (1<<20) | (1<<21) |(1<<22); //set 16,17,18,19,20,21,22 as output pins while(1) { delay_ms(100); IO0CLR=0xff; IO0SET=0x10; if(IO0PIN & 0x01) { IO1CLR=0x00ff0000; IO1SET=0x00060000; } else if(IO0PIN & 0x02) { IO1CLR=0x00ff0000; IO1SET=0x00660000; } else if(IO0PIN & 0x04) { IO1CLR=0x00ff0000; IO1SET =0x00070000; } else if(IO0PIN & 0x08) { IO1CLR=0x00ff0000; IO1SET=0x00760000; } delay_ms(100); IO0CLR=0xff; IO0SET=0x20; if(IO0PIN & 0x01) { IO1CLR=0x00ff0000; IO1SET=0x005b0000; } else if(IO0PIN & 0x02) { IO1CLR=0x00ff0000; IO1SET=0x006d0000; } else if(IO0PIN & 0x04) { IO1CLR=0x00ff0000; IO1SET=0x007f0000; } else if(IO0PIN & 0x08) { IO1CLR=0x00ff0000; IO1SET=0x003f0000; } delay_ms(100); IO0CLR=0xff; IO0SET=0x40; if(IO0PIN & 0x01) { IO1CLR=0x00ff0000; IO1SET=0x004f0000; } else if(IO0PIN & 0x02) { IO1CLR=0x00ff0000; IO1SET=0x007d0000; } else if(IO0PIN & 0x04) { IO1CLR=0x00ff0000; IO1SET=0x006f0000; } else if(IO0PIN & 0x08) { IO1CLR=0x00ff0000; IO1SET=0x00760000; } } }
Downloads:
The code was compiled in Keil uvision4 and simulation was made in Proteus v7.7.
To download code and proteus simulation click here.
Further Reading suggestions:
You may also like,
- nterfacing DAC with ARM(LPC2148)
- Interfacing with UART of ARM(LPC2148) controller
- Interfacing SPI communication with PIC
- ARM(LPC2148) Displaying Custom Characters on LCD
- RTC interfacing using I2C in ARM(LPC2148)
- Interfacing Graphical LCD with ARM(LPC2148)
- Interfacing ultrasonic sensor with ARM(LPC2148)
- Interfacing GPS Modu with ARM(LPC2148)
- Interfacing GSM Module with ARM(LPC2148)
- Interfacing PWM in ARM(LPC2148)
- Interfacing ADC with ARM(LPC2148)
- Scrolling string on LCD using ARM(LPC2148)
- nterfacing DAC with ARM(LPC2148)
- Interfacing with UART of ARM(LPC2148) controller
- Interfacing SPI communication with PIC
- ARM(LPC2148) Displaying Custom Characters on LCD
- RTC interfacing using I2C in ARM(LPC2148)
- Interfacing Graphical LCD with ARM(LPC2148)
- Interfacing ultrasonic sensor with ARM(LPC2148)
- Interfacing GPS Modu with ARM(LPC2148)
- Interfacing GSM Module with ARM(LPC2148)
- Interfacing PWM in ARM(LPC2148)
- Interfacing ADC with ARM(LPC2148)
- Scrolling string on LCD using ARM(LPC2148)
No comments:
Post a Comment