AD转换的问题
全局变量char ADC_temp;
char number={0x30,0x31,0x32,0x33,0x34,
0x35,0x36,0x37,0x38,0x39};
读模拟量的子程序
void ADC_read(void)
{
unsigned int adc_number;
double adc_value;
unsigned int adc_value_temp;
int i,k;
ADRESL=0x00;
ADRESH=0x00;
adc_number=0;
adc_value=0;
ADGO=1; // start AD conversion
while(ADGO)continue;
adc_number=ADRESH*256+ADRESL;
adc_value=5/(double)adc_number;
adc_value_temp=(int)(adc_value*1000);
for(i=4;i>0;i--) // get every number of the adc_value
{
k=adc_value_temp % 10;
ADC_temp=number;
adc_value_temp=adc_value_temp/10;
}
ADC_temp=ADC_temp;
ADC_temp=0x2E; // add a '.' in adc_value
}
找到原因
应该修改为
adc_value=(5*(double)adc_number_average)/1024;
页:
[1]