我给出部分代码吧,eeworld对帖子的尺寸有限制的
static int GetADCValue()
{
int Value = -1;
if (Ain0AllocADC()) {
v_pADCregs->ADCCON = (1<<14) | (ADCPRS<< 6) | (0<<3);
v_pADCregs->ADCCON |= (1 << 0); /* Start Auto conversion */
while (v_pADCregs->ADCCON & 0x1); /* check if Enable_start is low */
while (!(v_pADCregs->ADCCON & (1 << 15))); /* Check ECFLG */
Value = v_pADCregs->ADCDAT0 & 0x3FF;
v_pADCregs->ADCCON = 0x3FC4; // Reset it to initial
FreeADC();
}
RETAILMSG(TS_DBGON, (L"Done...ADC is %d\n\r", Value));
return Value;
}
static void FreeADC()
{
AdcOwner = ADC_OWN_BY_NONE;
}
static bool TsAllocADC()
{
long ret = InterlockedCompareExchange(&AdcOwner, ADC_OWN_BY_TS, ADC_OWN_BY_NONE);
switch (ret) {
case ADC_OWN_BY_TS:
RETAILMSG(1, (TEXT("Warning: Alloc ADC Again\r\n")));
return true;
case ADC_OWN_BY_NONE:
return true;
default:
return false;
}
}
PUBLIC VOID
DdsiTouchPanelGetPoint(TOUCH_PANEL_SAMPLE_FLAGS * pTipStateFlags,
INT * pUncalX,
INT * pUncalY)
{
static INT PrevX=0;
static INT PrevY=0;
INT TmpX = 0;
INT TmpY = 0;