|
全局变量
char ADC_temp[5];
char number[10]={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[k];
adc_value_temp=adc_value_temp/10;
}
ADC_temp[0]=ADC_temp[1];
ADC_temp[1]=0x2E; // add a '.' in adc_value
}
|
|