|
#include #define RepeatFast 5 //TIMER0 initialisation - prescale:1024 void timer0_init(void) unsigned char KeyNew,KeyOld; void interrupt [TIMER0_OVF0_vect] timer0_ovf(void) Далее в основной программе обработка Кey
E-mail:
info@telesys.ru
//#define Saver 50
#define RepeatPause 150
// задержка
// desired value: 20mSec
// actual value: 20,000mSec (0,0%)
//Resonator frequency = 4,608 MHz
{
TCCR0 = 0x00; //stop timer
TCNT0 = 0xA6; //set count value A6 для 20mSec (D3 для 10,00 mSec)
TCCR0 = 0x05; //start timer
//TIMSK |= (1 << TOIE0);
}
unsigned char KeyCnt;
unsigned char Key; // глобальный код нажатой клавиши
{
// Работа с клавиатурой
//TCCR0 = 0x00; //stop timer
KeyOld=KeyNew;
KeyNew=ReadKey(); // читаем текущую клавишу
if(KeyNew!=KeyOld) // если клавишу нажали или отпустили
KeyCnt=RepeatFast;
if(KeyCnt==0) // можно считывать следующую клавишу
{
Key=KeyNew; // читаем текущую клавишу (может и 0)
//if(Key)
// {
KeyCnt=RepeatPause;
// }
// else KeyCnt=RepeatPause;
}
else KeyCnt--; // если клавиша нажата
TCNT0 = 0xA6; //reload counter value
TCCR0 = 0x05; //start timer
}
while(1) // крутимся
{
switch (Key)
.
.
Key=0;
Ответы