-
Notifications
You must be signed in to change notification settings - Fork 6
/
keypad.h
69 lines (51 loc) · 1.89 KB
/
keypad.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* keypad.h
*
* Created: 9/10/2021 10:31:52 AM
* Author: safifi
*/
#ifndef KEYPAD_H_
#define KEYPAD_H_
/*
-------------------------
| | | | | ---------- KP0
-------------------------
| | | | | ---------- KP1
-------------------------
| | | | | ---------- KP2
-------------------------
| | | | | ---------- KP3
-------------------------
| | | | PULL UP
| | | |
KP4 KP5 KP6 KP7
KP (0 TO 3) INPUT ==> PD0,1,2,3 OUTPUT
KP (4 TO 7) OUTPUT ==> PD4,5,6,7 INPUT PULL UPD
*/
#include "headers.h"
#define INIT_KEYPAD() DDRD = 0x0f; PORTD = 0xff; // pull up PD4,5,6,7
#define KP0(val) if(val == 0) CLRBIT(PORTD,0); else SETBIT(PORTD,0);
#define KP1(val) if(val == 0) CLRBIT(PORTD,1); else SETBIT(PORTD,1);
#define KP2(val) if(val == 0) CLRBIT(PORTD,2); else SETBIT(PORTD,2);
#define KP3(val) if(val == 0) CLRBIT(PORTD,3); else SETBIT(PORTD,3);
#define KP4() READBIT(PIND,4)
#define KP5() READBIT(PIND,5)
#define KP6() READBIT(PIND,6)
#define KP7() READBIT(PIND,7)
#define DELAY_MS(x) _delay_ms(x);
/*****************************************************************************
* Function Name: keypad_init
* Purpose : initialize keypad pins
* Parameters : void
* Return value : void
*****************************************************************************/
void keypad_init(void);
/*****************************************************************************
* Function Name: keypad_init
* Purpose : check if one of keypad button is pressed
* Parameters : void
* Return value : return the button value in case a button is pressed
* return -1 in case no button pressed
*****************************************************************************/
int8_t keypad_read(void);
#endif /* KEYPAD_H_ */