|
void ADC_Init(void)
{
ADC1_Init(ADC1_CONVERSIONMODE_SINGLE, ADC1_CHANNEL_0,
ADC1_PRESSEL_FCPU_D2, ADC1_EXTTRIG_TIM, DISABLE,
ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL0, DISABLE);
}
void ADConvert(void)
{
unsigned char count=0;
ADC1->CR1|=0x02;
ADC1_StartConversion();
while(count<10)
{
while(ADC1_GetConversionValue()==RESET);
ADC1_ClearFlag(ADC1_FLAG_AWS2);
ADCValue[count]=ADC1_GetConversionValue();
count++;
}
ADC1->CR1&=~0x02;
}
void Digutal(void)
{
unsigned char i,j;
unsigned int temp;
for(i=10;i>=1;i--)
{
for(j=0;j<=(i-1);j++)
{
if(ADCValue[j]>ADCValue[j+1])
{
temp=ADCValue[j];
ADCValue[j]=ADCValue[j+1];
ADCValue[j+1]=temp;
}
}
}
voltageADC=0;
for(i=2;i<=7;i++)
voltageADC+=ADCValue[i];
voltageADC/=6;
voltage=(unsigned int)((unsigned long)voltageADC*3240UL/1023UL);
}
|
|