-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkeyboard.c
37 lines (32 loc) · 834 Bytes
/
keyboard.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**************************\
* Atikur Rahman Chitholian *
* CSE 2015-16 *
* University of Chittagong *
\**************************/
#include <avr/io.h>
#include <util/delay.h>
#include "keyboard.h"
unsigned char keys[4][4] = {
{'7', '8', '9', '/'},
{'4', '5', '6', '*'},
{'1', '2', '3', '-'},
{'C', '0', '=', '+'}
};
void init_keyboard() {
DDRB |= 0x0F; // PB 0-3 output for rows.
DDRC &= 0xF0; // PC 0-3 input for columns.
}
unsigned char scan_key() {
while (1) {
PORTC |= 0x0F;
for(int i = 0;i<4;i++){
PORTB = ~(0x01 << i);
for(int j = 0;j < 4;j++){
if(bit_is_clear(PINC, j)){
while(bit_is_clear(PINC, j)) _delay_ms(50);
return keys[i][j];
}
}
}
}
}