我在电脑上串口显示有时是有时八位有时十六位 有时32位
、ad采集程序
/*----------------------------
Get ADC result
----------------------------*/
u32 GetADCResult(BYTE ch)
{
u32 Result;
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ch | ADC_START;
_nop_(); //Must wait before inquiry
_nop_();
_nop_();
_nop_();
while (!(ADC_CONTR & ADC_FLAG));//Wait complete flag
ADC_CONTR &= ~ADC_FLAG; //Close ADC
Result = (ADC_DATA<<2)|(ADC_LOW2&0x03);//读取AD转换结果 10位
return Result; //Return ADC result
}
串口发送程序
/*----------------------------
Send ADC result to UART
----------------------------*/
void ShowResult(u32 DAT)
{
SendData(DAT&0xff); //Show Channel NO.
SendData((DAT>>8)&0xff); //Show ADC high 8-bit result
//if you want show 10-bit result, uncomment next line
// SendData(ADC_LOW2); //Show ADC low 2-bit result
} |