Академический Документы
Профессиональный Документы
Культура Документы
DATE:
OBJECTIVE
After completion of this experiment the student will be able to interface 4x4
keyboards. He / She will be able to generalize embedded C programs.
THEORY
Matrix Keypads are commonly used in calculators, telephones etc where a
large number of input switches are required. We know that matrix keypad is
made by arranging push button switches in row and columns. If the 16 switches
are straightly connected to microcontroller we need 16 inputs pins. But arranging
switches in matrix form, we can read the status of each switch using 8 pins of the
microcontroller.
The status of each key can be determined by a process called Scanning. For
the sake of explanation let’s 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 pull up resistors. Now we can read the status of each
switch through scanning.
2. Now each Column is scanned. If any switch belongs to 1st row is pressed
corresponding column will pulled down (logic LOW) and we can detect the
pressed key.
#include <avr/io.h>
#include <util/delay.h>
/* the following is done as the part of generalizing the code This code can be used any
where, all you need to do is change PORT below*/
void port_init(void)
DDRD = 0x0f;
PORTD = 0xff;
DDRB = 0xff;
PORTB = 0x00;
}
int main(void)
port_init();
while (1)
{
upperNibble = 0xff;
_delay_ms(1);
_delay_ms(1);
if (upperNibble != 0xff)
_delay_ms(20);
_delay_ms(20);
switch (keyCode) I
{
case (0xee):
keyPressed = 'F'; // read as F
break;
case (0xed):
keyPressed = 'E'; // read as E
break;
case (0xeb):
keyPressed = 'D'; // read as D
break;
case (0xe7):
keyPressed = 'C'; // read as C
break;
case (0xde):
keyPressed = 'B'; // read as B
break;
case (0xdd):
keyPressed = 'A'; // read as A
break;
case (0xdb):
keyPressed = '9'; // read as 9
break;
case (0xd7):
keyPressed = '8'; // read as 8
break;
case (0xbe):
keyPressed = '7'; // read as 7
break;
case (0xbd):
keyPressed = '6'; // read as 6
break;
case (0xbb):
keyPressed = '5'; // read as 5
break;
case (0xb7):
keyPressed = '4'; // read as 4
break;
case (0x7e):
keyPressed = '3'; // read as 3
break;
case (0x7d):
keyPressed = '2'; // read as 2
break;
case (0x7b):
keyPressed = '1'; // read as 1
break;
case (0x77):
keyPressed = '0'; // read as 0
break;
default : break;
}
OUT:;
}
_delay_ms(10);
DISPLAY_PORT = keyPressed;
} }