#include <bsp.h>
volatile S3C2416_ADC_REG *v_pADCregs;
static int Get_Adc(void)
{
int Buffer = 0;
unsigned int temp_adccon,temp_adcmux;
v_pADCregs = (S3C2416_ADC_REG *)OALPAtoVA(S3C2416_BASE_REG_PA_ADC, FALSE);
temp_adccon = v_pADCregs->ADCCON;
temp_adcmux = v_pADCregs->ACDMUX;
//使用通道1
v_pADCregs->ACDMUX = v_pADCregs->ACDMUX & ~(0xf) | 0x0<<0;
//
//v_pADCregs->ADCCON = (0x1<<14) | (66<<6) | (1<<3) | (0x0<<2) | (0x0<<1) | (0x1<<0);
v_pADCregs->ADCCON = (0x1<<14) | (66<<6) | (1<<3);
Delayms(30);
//v_pADCregs->ADCCON |= (0x1<<1);
v_pADCregs->ADCCON |= (0x1<<0); //start ADC
while (v_pADCregs->ADCCON & 0x1); //check if enable_start is low
while (!(v_pADCregs->ADCCON & 0x8000)); //check if EC(End of Conversion)
Buffer = (int)v_pADCregs->ADCDAT0 & 0xFFF;
v_pADCregs->ADCCON = temp_adccon;
v_pADCregs->ACDMUX = temp_adcmux;
return Buffer;
}
static int Get_Adc_Average(int times)
{
int i;
int temp_val = 0;
for(i=0;i<times;i++)
{
temp_val += Get_Adc();
Delayms(5);
}
return temp_val/times;
}
double Battery_Vary_Get(void)
{
int Battery_Adc;
double Battery_vary;
Battery_Adc = Get_Adc_Average(10);
Battery_vary = (double)Battery_Adc * (3.3/4096);
return Battery_vary;
}