本帖最后由 rc201004 于 2014-11-7 17:58 编辑
void Initial(void)
{
TRISA=0b00001111;
PORTA=0;
ADCON1=0x83;
ADCON0=0x41;//0100 0001
}
void MeasureCV(void)
{
unsigned int adval;
if(1)
{
GO=1;
while(!GO);
ADIF=0;
adval=ADRESH; //00000000 00000011读取转换值
adval=adval<<8|ADRESL; //00000011 11111111
ADTimes++;
ADChannel&=0x03;//0000 0011
(ADChannel==0) //AN0
{
MeaC=adval;
ACC[0]=MeaC/1000+48;
ACC[1]=MeaC%1000/100+48;
ACC[2]=MeaC%100/10+48;
ACC[3]=MeaC%10+48;
}
if(ADChannel==1) //AN1
{
MeaV=adval;
ACV[0]=MeaV/1000+48;
ACV[1]=MeaV%1000/100+48;
ACV[2]=MeaV%100/10+48;
ACV[3]=MeaV%10+48;
}
if(ADChannel==2) //AN2
{
MeaI=adval;
ACI[0]=MeaI/1000+48;
ACI[1]=MeaI%1000/100+48;
ACI[2]=MeaI%100/10+48;
ACI[3]=MeaI%10+48;
}
ADChannel++;
if(ADChannel==3)
{ADChannel=0;}
ADCON0&=0b11000111; //0100 0001
ADCON0|=(ADChannel<<3);
delaynms(10);
}
}
void main(void)
{
unsigned char i;
Initial();
lcdinit();
while(1)
{
MeasureCV();
display();
}
}
用调试模式看到每次通道正常切换,ADRESH,与ADRESL值正常,可MeaV没有值?为什么?怎么改?求助,谢谢 |