fbpx

Interface keypad with 8051

Keypad is essential in all embedded devices where user need to interact with devices.

  • From Calculator to Computer keypad ,it is essential where a number of input switches are required.
  • Keypad is a input device.
  • keypad is made by arranging push button switches in row and columns in a matrix format.
  • In 4×3 matrix keypad 12 input switch are required to connect with microcontroller.
  • The status of input switch can be determine by scanning row and column of keypad.
  • In 4×3 matrix keypad 4 row and 3 columns will available.
  • A logic 0 is given to Row1 and logic 1 is given to Row2&Row4.
  • Column is scanned. If any switch belongs to 1st row is pressed 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.
  • 8051 MicroController.

Circuit

Virtual Circuit

Code

 #include <REGX51.H>
 //Keypad Connections
 sbit R1 = P0^3;
 sbit R2 = P0^4;
 sbit R3 = P0^5;
 sbit R4 = P0^6;
 sbit C1 = P0^0;
 sbit C2 = P0^1;
 sbit C3 = P0^2;
 void delay()
 {
 int i,j;
 for(i=0;i<1000;i++)
 {
 for(j=0;j<100;j++);
 }
 }
 char Read_Keypad()
 {
 C1=1;
 C2=1;
 C3=1;
 R1=0;
 R2=1;
 R3=1;
 R4=1;
 if(C1==0){Delay(100);while(C1==0);return '1';}
 if(C2==0){Delay(100);while(C2==0);return '2';}
 if(C3==0){Delay(100);while(C3==0);return '3';}
 R1=1;
 R2=0;
 R3=1;
 R4=1;
 if(C1==0){Delay(100);while(C1==0);return '4';}
 if(C2==0){Delay(100);while(C2==0);return '5';}
 if(C3==0){Delay(100);while(C3==0);return '6';}
 R1=1;
 R2=1;
 R3=0;
 R4=1;
 if(C1==0){Delay(100);while(C1==0);return '7';}
 if(C2==0){Delay(100);while(C2==0);return '8';}
 if(C3==0){Delay(100);while(C3==0);return '9';}
 R1=1;
 R2=1;
 R3=1;
 R4=0;
 if(C1==0){Delay(100);while(C1==0);return '*';}
 if(C2==0){Delay(100);while(C2==0);return '0';}
 if(C3==0){Delay(100);while(C3==0);return '#';}
 return 0;
 }
 void main()
 {
 char a;
 a = Read_Keypad();
 if (a==1)
 {
 P3_1=0;
 }
 } 

Leave a Reply

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