3. Here Rows as INTPUT
If B4 is low the answer will be HEX E (15 - 1 = 14) 1110 Row 1
If B5 is low the answer will be HEX D (15 - 2 = 13) 1101 Row 2
It B6 is low the answer will be HEX B (15 - 4 = 11) 1011 Row 3
If B7 is low the answer will be HEX 7 (15 - 8 = 7) 0111 Row 4
Here Columns as OUTPUT
If B0 is low the low nibble will be HEX E (15 – 1 = 14) 1110 Column 1
If B1 is low the low nibble will be HEX D (15 – 2 = 13) 1101 Column 2
ff B2 is low the low nibble will be HEX B (15 – 4 = 12) 1011 Column 3
If B3 is low the low nibble will be HEX 7 (15 – 8 = 7) 0111 Column 4
4. Start
Ground all
Columns
All keys
open ?
Read all
Rows
Wait for
key
debounce
Ground
First
Column
Read all
Rows
Wait for
key
debounce
Ground
2nd
Column
Read all
Rows
Wait for
key
debounce
Ground
3rd
Column
Read all
Rows
Wait for
key
debounce
Ground
Fourth
Column
Read all
Rows
Wait for
key
debounce
which key is
pressed?
'1','2','3','4'
which key is
pressed?
''5','6','7','8'
which key is
pressed?
'9','0',' ','E'
which key is
pressed?
'+','- ','x','/ '
Figure . KEY 4 X 4 Scan Flow Chart
NO
YES
YES YES YES
NO
NO NO
YES
Return
match KEY
Return
KEY=’Q’
Return
match KEY
Return
match KEY
Return
match KEY
Return
KEY=’Q’
5. //Ground all the columns (C1,C2,C3 & C4)
//B0 = B1 = B2 = B3 = 0;
PORTB = 0xF0;
//Wait for key debounce
Delay_ms();
//Read all Rows
Key=Key & 0xF0;
If (Key!=0xF0)
{Key is Pressed, Find which key is pressed.}
Else
{Return (‘Q’); // Key not Pressed}
Key is Pressed, Find which key is pressed
Ground the C1
PORTB = 0xFE;
Delay_ms();
Read all Rows
Key=Key & 0xF0;
Switch(ROW)
{
Case ROW1:
return (‘1’);break;
Case ROW2:
return (‘2’);break;
Case ROW3:
return (‘3’);break;
Case ROW2:
return (‘4’);break;
}