Matrix Keypad: Matrix Keypads are commonly used in calculators, telephones etc where a number of input switches are required. 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.
1) Circuit:
a) C Code:
#include<util/delay.h>
void display()
{
PORTA=0B00000101;
_delay_ms(100);
PORTA=0B00000001;
}
void command()
{
PORTA=0B00000100;
_delay_ms(1000);
PORTA=0B00000000;
}
int i,j,k;
unsigned char arr[]={0x38,0x0e,0x01,0x80,0x06};
void main()
{
DDRA=DDRB=0XFF;
DDRC=0X00;
for (i=0; i<=4; i++)
{
PORTB= arr[i];
command();
}
PORTB= 'V';
display();
while(1)
{
PORTC=0X10;
PINC=0X10;
if(PINC&0X01)
{
PORTB='A';
display();
}
if(PINC&0X02)
{
PORTB='B';
display();
}
if(PINC&0X04)
{
PORTB='C';
display();
}
if(PINC&0X08)
{
PORTB='D';
display();
}
PORTC=0X20;
PINC=0X20;
if(PINC&0X01)
{
PORTB='E';
display();
}
if(PINC&0X02)
{
PORTB='F';
display();
}
if(PINC&0X04)
{
PORTB='G';
display();
}
if(PINC&0X08)
{
PORTB='H';
display();
}
}
}
b) Simulation:
0 comments:
Post a Comment
if you have any doubt please let me know