我用 AD1_GetValue16(pAD); AD1_GetChanValue16(7,pAD1); 俩个函数去获得结果,竟然是一样的! ad.h里有这一段宏 #define AD1_GetChanValue16(Ch,V) PE_AD1_GetChanValue16(V) 他把ch给消除了,然后PE_AD1_GetChanValue16()函数体里也没有处理我传过去的ch值(7),这样读出来的也同样是0通道,(事实也是这样,我在0通道上接了光敏电阻读取和亮度成正比) byte PE_AD1_GetChanValue16(word *Value) { register word *pValue=(word*)Value; /* Temporary pointer to the user buffer */ if (!OutFlg) /* Is output flag set? */ return ERR_NOTAVAIL; /* If no then error */ *Value = (ADCA_ADRSLT0 + 0) << 1; /* Store value from result register of device to user buffer */ return ERR_OK; /* OK */ } byte AD1_GetValue16(word *Values) { if (!OutFlg) /* Is output flag set? */ return ERR_NOTAVAIL; /* If no then error */ *Values = (getReg(ADCA_ADRSLT0) + 0) << 1; /* Store value from result register of device to user buffer */ return ERR_OK; /* OK */ } unsigned int *pAD,*pAD1; //float SamData; unsigned int SamData,kk; unsigned int ADC12Data; void SendFloat(float Float); void delay(int i); void main(void) { /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ pAD1=&kk; /* Write your code here */ for(;;) { int mm; if(AD1_Measure(TRUE)==ERR_OK) //AD转换完成 { AD1_GetValue16(pAD); AD1_GetChanValue16(7,pAD1); } //SamData=(3.0*(*pAD))/32760; SamData=((*pAD))/256; PortB_PutVal(SamData); SendFloat(SamData); for(mm=0;mm<200;mm++) delay(10000);
} } |