void delay(unsigned int x)
{
unsigned int a,b;
for(a=x;a>0;a–)
for(b=30;b>0;b–);
}
void ad() //收集函数
{
INTCON=0X00;
TRISA=0XFF;
ADCON1=0B00000000;
ADCON0=0B10000001;//AN1,RA0
delay(1);
ADGO=1;
delay(1);
i=ADRESH; //收集到的AD值
ADRESH=0x00;
}
void Vad() //求AD平均值函数
{
ad();
delay(1);
j1=i;
ad();
delay(1);
j2=i;
ad();
delay(1);
j3=i;
j=(j1+j2+j3)/3;
}