ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Пятница
12 июля
443450 Топик полностью
SciFi (18.09.2013 14:00, просмотров: 78) ответил SciFi на Вот так:
Вот более полный пример: /* file: keyboard.h */ #ifndef KEYBOARD_H #define KEYBOARD_H enum key_code { KEY_NONE, KEY_A, KEY_B }; extern void key_init(void); extern void key_poll(void); extern enum key_code key_get(void); #endif /* file: keyboard.c */ #include "keyboard.h" #include "timer.h" static enum key_code last_key; key_init(void) { /* configure ports etc. */ } static void key_scan(void) { static enum key_code previous = KEY_NONE; enum key_code current; if (KEY_A_PIN != 0) { current = KEY_A; } else if (KEY_B_PIN != 0) { current = KEY_B; } else { current = KEY_NONE; } if (current != previous && current != KEY_NONE) { last_key = current; } previous = current; } void key_poll(void) { static unsigned int prev; unsigned int now; now = timer_uptime_ticks(); if (now - prev > TIMER_TICKS_PER_SECOND / 10) { prev = now; key_scan(); } } enum key_code key_get(void) { enum key_code ret = last_key; last_key = KEY_NONE; return ret; }
ส็็็็็็็็็็็็็็็็็็็็็็็็็༼ ຈل͜ຈ༽ส้้้้้้้้้้้้้้้้้้้้้้้