#include <SH79F6488.H>
#include"periphral.h"
ulong data ADC_Data;
unsigned long data ADCData;
uchar data Temp;
unsigned long data ADvalue;
void ad_init(void)
{
REGCON=0x01; //2.7V
//ADCON=0x80; //AN2-AIN0 基准电压vref1,和VDDR同源
//ADCON=0xa0; //AN2-AIN0 基准电压vref2=1.19 ,和VDDR不同源
ADCON=0xC4; //AN0单端输入,VREF=2.7
//ADCON=0x85; //AN1单端输入,VREF=2.7
//ADCON=0x86; //AN2单端输入,VREF=2.7
//ADCON=0x87; //AN3单端输入,VREF=2.7
//ADCON=0x80; //差分输入AIN0+和AIN0-
//ADCON=0x87; //差分输入AIN1+和AIN1-
//ADCON=0x87; //差分输入AIN2+和AIN2-
//ADT=0xFC; //ADC=XXXHz@12MHz
//ADT=0xFD; //ADC=500Hz@12MHz
//ADT=0xFB; //ADC=300Hz@12MHz
//ADT=0xF9; //ADC=214Hz@12MHz
ADT=0xF1; //ADC=100Hz@12MHz
//ADT=0xE2; //ADC=50Hz@12MHz
//ADT=0xA0; //ADC=10Hz@12MHz
//ADCH=0x3F; //VREF=0.15*VDDR,AIN0
//ADCH=0x7F; //VREF=0.22*VDDR,AIN0
//ADCH=0xBF; //VREF=0.3*VDDR,AIN0
ADCH=0xFF; //VREF=0.4*VDDR,AIN0
//ADCDS=0x03; //VINOS=1,ADCDF=1
PGAM=0x04; //PGA Gain=1,chop=1K
//PGAM=0x14; //PGA Gain=2,chop=1K
//PGAM=0x24; //PGA Gain=4,chop=1K
//PGAM=0x64; //PGA Gain=8,chop=1K
//PGAM=0x84; //PGA Gain=16,chop=1K
//PGAM=0x94; //PGA Gain=32,chop=1K
//PGAM=0xA4; //PGA Gain=64,chop=1K
//PGAM=0xE4; //PGA Gain=128,chop=1K
}
unsigned long ScanADCData(void)
{
while(1)
{
Temp=ADCON&0x40;
if(Temp==0x40)break;
}
ADCON&=0xBF;
ADCData=ADDH;
ADCData=ADCData*256;
ADCData=ADCData+ADDM;
ADCData=ADCData*16;
ADCData=ADCData+ADDL;
return ADCData;
}
void main()
{
ad_init();
{
ADvalue=ScanADCData();
}
}
|