1 | /*
|
2 | Name: Test "key-routines.h"
|
3 | µC: ATmega328P
|
4 | Date: Nov 2017
|
5 | */
|
6 |
|
7 |
|
8 | #define F_CPU 16000000
|
9 |
|
10 |
|
11 |
|
12 | #include <avr/io.h>
|
13 | #include <avr/interrupt.h>
|
14 | #include "key-routines.h"
|
15 |
|
16 | int main(void)
|
17 | {
|
18 | KEY_DDR &= ~ALL_KEYS; // configure key port for input
|
19 | KEY_PORT |= ALL_KEYS; // and turn on pull up resistors
|
20 |
|
21 | TCCR0B = (1<<CS02)|(1<<CS00); // prescaler 1024
|
22 | TCNT0 = (uint8_t)(int16_t)-(F_CPU / 1024 * 10e-3 + 0.5); // preload for 10ms
|
23 | TIMSK0 |= 1<<TOIE0; // enable timer interrupt
|
24 |
|
25 | sei();
|
26 |
|
27 | while(1){
|
28 | if( get_key_short( 1<<KEY1 )) {
|
29 | //Do something
|
30 | }
|
31 |
|
32 | if( get_key_long( 1<<KEY1 )) {
|
33 | //Do something
|
34 | }
|
35 |
|
36 | if( get_key_press( 1<<KEY2 ) || get_key_rpt( 1<<KEY2 )) {
|
37 | //Do something
|
38 | }
|
39 | }
|
40 | }
|