121 lines
4.8 KiB
C++
121 lines
4.8 KiB
C++
|
|
|||
|
/********************************** (C) COPYRIGHT *******************************
|
|||
|
* File Name : TouchKey.C
|
|||
|
* Author : WCH
|
|||
|
* Version : V1.0
|
|||
|
* Date : 2017/01/20
|
|||
|
* Description : CH554 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD>ͨ<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
|
|||
|
#include "..\Public\CH554.H"
|
|||
|
#include "..\Public\Debug.H"
|
|||
|
#include "TouchKey.H"
|
|||
|
#include "stdio.h"
|
|||
|
|
|||
|
#pragma NOAREGS
|
|||
|
|
|||
|
UINT16 KeyFree[KEY_LAST-KEY_FIRST+1]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD>ڱȽϰ<C8BD><CFB0><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵС<D6B5>ڻ<EFBFBD>ֵ<D7BC><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
UINT8V KeyBuf; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC>Ϊ0<CEAA><30>ʾ<EFBFBD>ް<EFBFBD><DEB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30>ʾ<EFBFBD><CABE>ǰ<EFBFBD><C7B0><EFBFBD>ⰴ<EFBFBD><E2B0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* Function Name : GetTouckKeyFreeBuf()
|
|||
|
* Description : <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>״̬<EFBFBD><EFBFBD>ֵ
|
|||
|
* Input : None
|
|||
|
* Output : None
|
|||
|
* Return : None
|
|||
|
*******************************************************************************/
|
|||
|
void GetTouckKeyFreeBuf()
|
|||
|
{
|
|||
|
UINT8 i,j;
|
|||
|
UINT8 TmpSum = 0;
|
|||
|
KeyBuf = 0; //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ް<EFBFBD><DEB0><EFBFBD>״̬
|
|||
|
for(i=KEY_FIRST;i<(KEY_LAST+1);i++)
|
|||
|
{
|
|||
|
j = KEY_BASE_SAMPLE_TIME; //<2F>ɶ<EFBFBD><C9B6><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>ֵ<EFBFBD><D6B5>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD>
|
|||
|
TKEY_CTRL = (TKEY_CTRL & 0xF8 | i)+1; //<2F><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD>ͨ<EFBFBD><CDA8>
|
|||
|
while(j--)
|
|||
|
{
|
|||
|
while((TKEY_CTRL&bTKC_IF) == 0); //bTKC_IF<49><46>Ϊ1ʱ<31><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
TmpSum += TKEY_DAT&0x0F; //<2F><><EFBFBD><EFBFBD>ֵ<EFBFBD>ȶ<EFBFBD><C8B6><EFBFBD>ȡ<EFBFBD><C8A1>4λ<34><EFBFBD><CDB9><EFBFBD>
|
|||
|
}
|
|||
|
KeyFree[i] = TKEY_DAT&0x07F0 + TmpSum/5; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
}
|
|||
|
#if INTERRUPT_TouchKey
|
|||
|
IE_TKEY = 1; //ʹ<><CAB9>Touch_Key<65>ж<EFBFBD>
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* Function Name : TouchKeyChannelSelect(UINT8 ch)
|
|||
|
* Description : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>
|
|||
|
* Input : UINT8 ch <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>
|
|||
|
0~5 <EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>
|
|||
|
* Output : None
|
|||
|
* Return : <EFBFBD>ɹ<EFBFBD> SUCCESS
|
|||
|
ʧ<EFBFBD><EFBFBD> FAIL <EFBFBD><EFBFBD>֧<EFBFBD>ֵ<EFBFBD>ͨ<EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
UINT8 TouchKeyChannelSelect(UINT8 ch)
|
|||
|
{
|
|||
|
if(ch < 6)
|
|||
|
{
|
|||
|
TKEY_CTRL = (TKEY_CTRL & 0xF8 | ch)+1;
|
|||
|
return SUCCESS;
|
|||
|
}
|
|||
|
return FAIL;
|
|||
|
}
|
|||
|
|
|||
|
#if INTERRUPT_TouchKey
|
|||
|
/*******************************************************************************
|
|||
|
* Function Name : TouchKeyInterrupt(void)
|
|||
|
* Description : Touch_Key <EFBFBD>жϷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
void TouchKeyInterrupt( void ) interrupt INT_NO_TKEY using 1 //Touch_Key<65>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ʹ<>üĴ<C3BC><C4B4><EFBFBD><EFBFBD><EFBFBD>1
|
|||
|
{
|
|||
|
UINT8 ch;
|
|||
|
UINT16 KeyData;
|
|||
|
|
|||
|
KeyData = TKEY_DAT; //<2F><><EFBFBD><EFBFBD>87us,<2C><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>
|
|||
|
ch = TKEY_CTRL&7; //<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>
|
|||
|
if ( ch > KEY_LAST ){
|
|||
|
TKEY_CTRL = TKEY_CTRL & 0xF8 | KEY_FIRST; //<2F><><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TKEY_CTRL ++; //<2F>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>
|
|||
|
}
|
|||
|
if ( KeyData < (KeyFree[ch-KEY_FIRST] - KEY_ACT) ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㣬<EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
KeyBuf=ch; //<2F><><EFBFBD><EFBFBD><EFBFBD>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD>а<EFBFBD><D0B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD>־֪ͨmain<69><6E><EFBFBD>д<EFBFBD><D0B4><EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
#else
|
|||
|
/*******************************************************************************
|
|||
|
* Function Name : TouchKeyChannelQuery()
|
|||
|
* Description : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD>ѯ
|
|||
|
* Input : None
|
|||
|
* Output : None
|
|||
|
* Return : None
|
|||
|
*******************************************************************************/
|
|||
|
void TouchKeyChannelQuery()
|
|||
|
{
|
|||
|
UINT8 ch;
|
|||
|
UINT16 KeyData;
|
|||
|
|
|||
|
while((TKEY_CTRL&bTKC_IF) == 0); //bTKC_IF<49><46>Ϊ1ʱ<31><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
KeyData = TKEY_DAT; //<2F><><EFBFBD><EFBFBD>87us,<2C><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>
|
|||
|
ch = TKEY_CTRL&7; //<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>
|
|||
|
if ( ch > KEY_LAST ){
|
|||
|
TKEY_CTRL = TKEY_CTRL & 0xF8 | KEY_FIRST; //<2F><><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
TKEY_CTRL ++; //<2F>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>
|
|||
|
}
|
|||
|
if ( KeyData < (KeyFree[ch-KEY_FIRST] - KEY_ACT) ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㣬<EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
KeyBuf=ch; //<2F><><EFBFBD><EFBFBD><EFBFBD>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD>а<EFBFBD><D0B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD>־֪ͨmain<69><6E><EFBFBD>д<EFBFBD><D0B4><EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
#endif
|
|||
|
|