1 |
/* mija 2009 key |
1 |
/* mija 2009 key |
2 |
|
2 |
|
3 |
source file for process keyboard |
3 |
source file for process keyboard |
4 |
|
4 |
|
5 |
!!! must be set PINs,PORTs,DDR in lcd.h |
5 |
!!! must be set PINs,PORTs,DDR in lcd.h |
6 |
|
6 |
|
7 |
|
7 |
|
8 |
ver.: 0.0 TESTED |
8 |
ver.: 0.0 TESTED |
9 |
|
9 |
|
10 |
*/ |
10 |
*/ |
11 |
|
11 |
|
12 |
#include <avr/io.h> |
12 |
#include <avr/io.h> |
13 |
#include "key.h" |
13 |
#include "key.h" |
14 |
|
14 |
|
15 |
void KeyInit() |
15 |
void KeyInit() |
16 |
{ |
16 |
{ |
17 |
KEY1Init(); |
17 |
KEY1Init(); |
18 |
KEY1Pullup(); |
18 |
KEY1Pullup(); |
19 |
KEY2Init(); |
19 |
KEY2Init(); |
20 |
KEY2Pullup(); |
20 |
KEY2Pullup(); |
21 |
} |
21 |
} |
22 |
|
22 |
|
23 |
void ProcesKey(uint8_t *key) |
23 |
void ProcesKey(uint8_t *key) |
24 |
{ |
24 |
{ |
25 |
//stav |
25 |
//stav |
26 |
enum{STABLE_NO_KEY,NO_STABLE,REPEAT}; |
26 |
enum{STABLE_NO_KEY,NO_STABLE,REPEAT}; |
27 |
static uint8_t stav = STABLE_NO_KEY; |
27 |
static uint8_t stav = STABLE_NO_KEY; |
28 |
static uint8_t KeyPrev = NOKEY; |
28 |
static uint8_t KeyPrev = NOKEY; |
29 |
static uint16_t KeyTimer; |
29 |
static uint16_t KeyTimer; |
30 |
uint8_t Key; |
30 |
uint8_t Key; |
31 |
|
31 |
|
32 |
Key = NOKEY; |
32 |
Key = NOKEY; |
33 |
if (KEY1Input()) Key = TL1; |
33 |
if (KEY1Input()) Key = TL1; |
34 |
if (KEY2Input()) Key = TL2; |
34 |
if (KEY2Input()) Key = TL2; |
35 |
if (KEY1Input() && KEY2Input()) Key = TL1TL2; |
35 |
if (KEY1Input() && KEY2Input()) Key = TL1TL2; |
36 |
|
36 |
|
37 |
switch (stav) |
37 |
switch (stav) |
38 |
{ |
38 |
{ |
39 |
case STABLE_NO_KEY: if (Key){ |
39 |
case STABLE_NO_KEY: if (Key){ |
40 |
KeyPrev = Key; |
40 |
KeyPrev = Key; |
41 |
KeyTimer = KEYSTABLETIME; |
41 |
KeyTimer = KEYSTABLETIME; |
42 |
stav = NO_STABLE; |
42 |
stav = NO_STABLE; |
43 |
} |
43 |
} |
44 |
*key = NOKEY; |
44 |
*key = NOKEY; |
45 |
break; |
45 |
break; |
46 |
case NO_STABLE: if (--KeyTimer){ |
46 |
case NO_STABLE: if (--KeyTimer){ |
47 |
*key = NOKEY; |
47 |
*key = NOKEY; |
48 |
break; |
48 |
break; |
49 |
} |
49 |
} |
50 |
if (Key == KeyPrev){ |
50 |
if (Key == KeyPrev){ |
51 |
*key = Key; |
51 |
*key = Key; |
52 |
KeyTimer = KEYFIRSTREPEATTIME; |
52 |
KeyTimer = KEYFIRSTREPEATTIME; |
53 |
stav = REPEAT; |
53 |
stav = REPEAT; |
54 |
break; |
54 |
break; |
55 |
} |
55 |
} |
56 |
stav = STABLE_NO_KEY; |
56 |
stav = STABLE_NO_KEY; |
57 |
*key = NOKEY; |
57 |
*key = NOKEY; |
58 |
break; |
58 |
break; |
59 |
/* case FIRST_REPEAT: if (--KeyTimer){ |
59 |
/* case FIRST_REPEAT: if (--KeyTimer){ |
60 |
if (Key == NOKEY) stav = STABLE_NO_KEY; |
60 |
if (Key == NOKEY) stav = STABLE_NO_KEY; |
61 |
*key = NOKEY; |
61 |
*key = NOKEY; |
62 |
break; |
62 |
break; |
63 |
} |
63 |
} |
64 |
if (Key == KeyPrev){ |
64 |
if (Key == KeyPrev){ |
65 |
*key = Key; |
65 |
*key = Key; |
66 |
KeyTimer = KEYREPEATTIME; |
66 |
KeyTimer = KEYREPEATTIME; |
67 |
stav = REPEAT; |
67 |
stav = REPEAT; |
68 |
break; |
68 |
break; |
69 |
} |
69 |
} |
70 |
stav = STABLE_NO_KEY; |
70 |
stav = STABLE_NO_KEY; |
71 |
*key = NOKEY; |
71 |
*key = NOKEY; |
72 |
break;*/ |
72 |
break;*/ |
73 |
case REPEAT: if (--KeyTimer){ |
73 |
case REPEAT: if (--KeyTimer){ |
74 |
if (Key != KeyPrev) stav = STABLE_NO_KEY; |
74 |
if (Key != KeyPrev) stav = STABLE_NO_KEY; |
75 |
*key = NOKEY; |
75 |
*key = NOKEY; |
76 |
break; |
76 |
break; |
77 |
} |
77 |
} |
78 |
if (Key == KeyPrev){ |
78 |
if (Key == KeyPrev){ |
79 |
*key = Key; |
79 |
*key = Key; |
80 |
KeyTimer = KEYREPEATTIME; |
80 |
KeyTimer = KEYREPEATTIME; |
81 |
//stav = REPEAT; |
81 |
//stav = REPEAT; |
82 |
break; |
82 |
break; |
83 |
} |
83 |
} |
84 |
default: stav = STABLE_NO_KEY; |
84 |
default: stav = STABLE_NO_KEY; |
85 |
*key = NOKEY; |
85 |
*key = NOKEY; |
86 |
} |
86 |
} |
87 |
} |
87 |
} |