📄 keyboard.c
字号:
#include "..\\spce061\\061reg.h"
#include "keyboard.h"
// This Valume User Extern
unsigned int keyEvent;
// This Program User
static unsigned int keyTimer, xrefTimer, currentKey=KEY_NONE, lastKey=KEY_NONE;
/*
keyEvent Ret KeyValue:
000X is First Press Key
400X is Release Key
800X is Second Function Key or Rep Key
*/
void KeyEvent()
{// 50MS Once Event
static unsigned int repKey=0;
currentKey= KeyScan();
if( currentKey != KEY_NONE )
{// New Key Press or Re-Press Key
if( currentKey != lastKey)
{// New Key Press (First Press Key)
keyEvent= currentKey;
repKey=0;
keyTimer= 0x00;
xrefTimer= 0x1f; // 1.5 Sec
}
else
{// Re Press Key
if( ++keyTimer > xrefTimer )
{
repKey= 1;
keyEvent = 0x8000 | currentKey;
keyTimer= 0x00;
xrefTimer= 0x15; // 1.0 Sec
}
}
}
else
{// KEY NONE
if((lastKey != KEY_NONE) && (repKey != 1))
{
keyEvent=lastKey | 0x4000;
}
else
{
keyEvent= KEY_NONE;
}
repKey=0;
keyTimer=0x00;
xrefTimer=0x1f;
}
lastKey=currentKey;
}
unsigned int KeyScan()
{
unsigned int max, min, k, i;
InitAD();
do
{
//Set Max & Min
max= 0x0000;
min= 0xFFFF;
for(k= 0; k < 3; k++)
{
*P_Watchdog_Clear=C_WDTCLR;
i = GetAD();
i >>= 4;
if(i > max) max= i;
if(i < min) min= i;
}
}
while( (max-min) > 0x020);
i= ((max + min) / 2) + 1;
if ( i > KEY_NONE_VALUE ) k= KEY_NONE;
else if ( i > KEY_VOLUME_INC_VALUE ) k= KEY_VOLUME_INC;
else if ( i > KEY_VOLUME_DEC_VALUE ) k= KEY_VOLUME_DEC;
else if ( i > KEY_FF_VALUE ) k= KEY_NEXT;
else if ( i > KEY_STOP_VALUE ) k= KEY_STOP;
else if ( i > KEY_FR_VALUE ) k= KEY_LAST;
else if ( i > KEY_AB_VALUE ) k= KEY_AB;
else if ( (i > KEY_PLAY_VALUE - 0xc5) && (i < KEY_PLAY_VALUE + 0xc5) ) k= KEY_PLAY;
else k= KEY_NONE;
return(k);
}
unsigned int GetAD(void)
{
unsigned int uiData;
while(!(*P_ADC_MUX_Ctrl&0x8000)); //wait,until ADC complete
uiData=*P_ADC_LINEIN_Data;
return(uiData&0xffc0);
}
void InitAD()
{
*P_ADC_MUX_Ctrl=C_ADC_CH1; //LINE_IN-------IOA0
*P_ADC_Ctrl= C_ADCE; //ADC enable
}
void KeyInit()
{
*P_TimerB_Ctrl=C_SourceC_4096Hz;
*P_TimerB_Data=0xff32;
*P_INT_Ctrl=C_IRQ2_TMB;
IRQ_ON();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -