|
开发板:三星2440 环境:wince
现在任务:采集ad数值
遇到问题:可以取到正确ad数值,但是当触摸屏被按住的时候,采集到的数值为触摸屏的x坐标值?
代码如下:
int CShowDlg::ReadAdc(int ch)
{
int i;
static int prevCh=-1;
v_pADCRegs->rADCCON = (1<<14)|(preScaler<<6)|(ch<<3); //setup channel
if(prevCh!=ch)
{
v_pADCRegs->rADCCON = (1<<14)|(preScaler<<6)|(ch<<3); //setup channel
for(i=0;i
prevCh=ch;
}
v_pADCRegs->rADCCON|=0x1; //start ADC
while(v_pADCRegs->rADCCON & 0x1); //check if Enable_start is low
while(!(v_pADCRegs->rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high
return ((int)v_pADCRegs->rADCDAT0 & 0x3ff);
}
void CShowDlg::Test_Adc(void)
{
int a0=0; //Initialize variables
UINT32 rADCCON_save = v_pADCRegs->rADCCON;
CString str;
preScaler = ADC_FREQ;
preScaler = 50000000/ADC_FREQ -1; //PCLK:50.7MHz
a0=ReadAdc(0);
v_pADCRegs->rADCCON = rADCCON_save;
str.Format(L"%d", a0);
SetDlgItemTextW(IDC_EDIT1,str);
m_CurPressureShow.SetPos(a0);
}
现有现象以及分析:
当按住触摸屏时,调试发现v_pADCRegs->rADCCON的值并没有被置为选择X-pos,还是自定通道。
是因为操作系统的中断优先级太高的原因吗?
附:
地址映射方法如下
v_pIOPRegs = (volatile IOPreg*)VirtualAlloc(0, sizeof(IOPreg), MEM_RESERVE, PAGE_NOACCESS);
if (v_pIOPRegs == NULL)
{
DEBUGMSG (1,(TEXT("v_pIOPRegs is not allocated\n\r")));
//return TRUE;
}
if (!VirtualCopy((PVOID)v_pIOPRegs, (PVOID)IOP_BASE, sizeof(IOPreg), PAGE_READWRITE|PAGE_NOCACHE)) {
DEBUGMSG (1,(TEXT("v_pIOPRegs is not mapped\n\r")));
//return TRUE;
}
|
|