fbpx

Interface Keypad With ARM7

Description

Keypad is an input device.Keypad is essential in all embedded devices where the user needs to interact with devices. From Calculator to Computer, the keypad is essential where a number of input switches are required.

  • Keypad is made by arranging push button switches in row and columns in a matrix format.
  • In 4×3 matrix keypad, 12 input switch is required to connect with a microcontroller.
  • The status of the input switch can be determined by scanning row and column of the keypad.
  • In 4×3 matrix keypad, 4 row and 3 columns will be available.
  • A logic 0 is given to Row1 and logic 1 is given to Row2&Row4.
  • The column is scanned. If any switch belongs to 1st row is pressed the corresponding column will be logic 0 and we can detect the pressed key.
  • This process is repeated for all rows.

Hardware Required

  • 4×3 Keypad.
  • LPC21XX MicroController.

Circuit

Code

 #include<lpc21xx.h>
 char key;
 void delay(void)
 {
 unsigned int i;
 for(i=0;i<=20000;i++);
 }
 void cmd(unsigned char X)
 {
 IO1PIN=0X00020000;
 IO0PIN=X;
 delay();
 IO1PIN=0X00000000;
 }
 void dat(unsigned char Y)
 {
 IO1PIN=0X00030000;
 IO0PIN=Y;
 delay();
 IO1PIN=0X00010000;
 }
 char keypad(void)
 {
 while(1)
 {
 IO1CLR|=(1<<19);
 IO1SET|=(1<<20)|(1<<21)|(1<<22);
 if(!(IO1PIN&(1<<16)))
 {
 while(!(IO1PIN&(1<<16)));
 return '1';
 }
 if(!(IO1PIN&(1<<17)))
 {
 while(!(IO1PIN&(1<<17)));
 return '2';
 }
 if(!(IO1PIN&(1<<18)))
 {
 while(!(IO1PIN&(1<<18)));
 return '3';
 }
 IO1CLR|=(1<<20);
 IO1SET|=(1<<21)|(1<<22)|(1<<19);
 if(!(IO1PIN&(1<<16)))
 {
 while(!(IO1PIN&(1<<16)));
 return '4';
 }
 if(!(IO1PIN&(1<<17)))
 {
 while(!(IO1PIN&(1<<17)));
 return '5';
 }
 if(!(IO1PIN&(1<<18)))
 {
 while(!(IOPIN1&(1<<18)));
 return '6';
 }
 IO1CLR|=(1<<21);
 IO1SET|=(1<<22)|(1<<20)|(1<<19);
 if(!(IO1PIN&(1<<16)))
 {
 while(!(IO1PIN&(1<<16)));
 return '7';
 }
 if(!(IO1PIN&(1<<17)))
 {
 while(!(IO1PIN&(1<<17)));
 return '8';
 }
 if(!(IO1PIN&(1<<18)))
 {
 while(!(IO1PIN&(1<<18)));
 return '9';
 }
 IO1CLR|=(1<<22);
 IO1SET|=(1<<19)|(1<<20)|(1<<21);
 if(!(IO1PIN&(1<<16)))
 {
 while(!(IO1PIN&(1<<16)));
 return '*';
 }
 if(!(IO1PIN&(1<<17)))
 {
 while(!(IO1PIN&(1<<17)));
 return '0';
 }
 if(!(IO1PIN&(1<<18)))
 {
 while(!(IO1PIN&(1<<18)));
 return '#';
 }
 }
 }
 int main(void)
 {
 IO0DIR=0x000003ff;
 IO1DIR=0x00780000;
 cmd(0x38);
 cmd(0x0f);
 while(1)
 {
 key=keypad();
 dat(key);
 }
 } 

Leave a Reply

Your email address will not be published. Required fields are marked *