每次返回的result的值都不变
unsigned int ADC_Convert(void)
{ unsigned int result,temp1,temp2;
ADCDH=0;
ADCDL=0;
ADCON0= 0x80;
delayms(1);
ADCFG0 = 0x12; /*全速模式*/
ADCON0|= 0x08;
while ((ADCON0 & 0x10) == 0 ); /*转换完成,ADC硬件会自动清除ADCS并且ADCI置位。ADCS或ADCI为”1”时将不会开始新的A/D转换。 */
ADCON0 &= 0xE7;
temp1=ADCDH;
temp2=ADCDL;
result = (temp1<<8) + temp2;
return(result);
}
|