TQ2440 WINCE6.0 ADC驱动ADC_Read与ADC_Write
本帖最后由 langlangzhengtu2010 于 2011-09-05 20:31:49 编辑 如题,大大们,我从天嵌论坛找的ADC驱动只实现了ADC_Read的功能,而ADC_Write没有实现。
我觉得这两个程序应该差不多,但是不知该怎么写ADC_Write,请指教!谢谢!
DWORD ADC_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
int i;
Count=sizeof(nADC_Value);
dwADCCON_Save=v_pADCregs->ADCCON;
for(i=0;i<4;i++)
{
nADC_Value[i]=0;
if(!bADC_Enable[i])continue;
nADC_Value[i] = ReadADC(i);
Sleep(10);
}
v_pADCregs->ADCCON = dwADCCON_Save;
Sleep(20);
memcpy(pBuffer,&nADC_Value[0],Count);
RETAILMSG(1,(TEXT("ADC_Control: ADC_Read\r\n")));
return TRUE;
}
int ReadADC(int ch)
{
v_pADCregs->ADCCON = (1<<14)|(cbytPreScalerValue<<6)|(ch<<3); //setup channel
v_pADCregs->ADCCON|=0x1;//start ADC
while(v_pADCregs->ADCCON & 0x1);//check if Enable_start is low
while(!(v_pADCregs->ADCCON & 0x8000));//check if EC(End of Conversion) flag is high
RETAILMSG(1,(TEXT("NO: %d Data: %d\r\n"),ch,(int)v_pADCregs->ADCDAT0 & 0x3ff));
return ( (int)v_pADCregs->ADCDAT0 & 0x3ff ); //此处返回读数据,改为写数据怎么做呢?
}
DWORD ADC_Write(DWORD hOpenContext, LPCVOID pSourceBytes, DWORD NumberOfBytes)
{
RETAILMSG(1,(TEXT("ADC_Control: ADC_Write\r\n")));
return 0;
}