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.
Program:
#include<pic.h>
#include<htc.h>
#define __PIC16f877A_H
__CONFIG(WDTE_OFF&FOSC_HS&PWRTE_ON&LVP_OFF);
#include"lcd_header.h"
void main()
{
TRISB=0x00;
TRISC=0x00;
TRISD=0x00;
unsigned int i,a,b;
init();
while(1)
{
PORTC=0x0F;
a=PORTC;
PORTC=0xF0;
b=PORTC;
i=a|b;
switch(i)
{
case 0xE7:
datta('0');
delay(5000);
break;
case 0xEB:
datta('1');
delay(5000);
break;
case 0xED:
datta('2');
delay(5000);
break;
case 0xEE:
datta('3');
delay(5000);
break;
case 0xD7:
datta('4');
delay(5000);
break;
case 0xDB:
datta('5');
delay(5000);
break;
case 0xDD:
datta('6');
delay(5000);
break;
case 0xDE:
datta('7');
delay(5000);
break;
case 0xB7:
datta('8');
delay(5000);
break;
case 0xBB:
datta('9');
delay(5000);
break;
case 0xBD:
datta('A');
delay(5000);
break;
case 0xBE:
datta('B');
delay(5000);
break;
case 0x77:
datta('C');
delay(5000);
break;
case 0x7B:
datta('D');
delay(5000);
break;
case 0x7D:
datta('E');
delay(5000);
break;
case 0x7E:
datta('F');
delay(5000);
break;
default:
PORTC=0x00;
break;
}
}
}
0 comments:
Post a Comment
if you have any doubt please let me know