【发布时间】:2014-05-06 14:35:03
【问题描述】:
我正在尝试读取 PIC16F690 上的多个模拟端口。我可以读 2,但我不能让它读 3。即在下面,AN1、AN2 工作,但 AN3 不工作。我在 TRISA、ANSEL、ADCON1 或 ADCON0 上做错了吗?
TRISA = 0b00010111; // all port A:0,1,2,4 as inputs
ANSEL = 0b11111111; // RA0->RA1 are Analog
ADCON1 = 0b01010000; // select ADC clock (500 Khz)
ADCON0 = 0b10000101; //peripheral 1 - PORT A:1 - AN1
__delay_us(250);
unsigned short nRet;
ADCON0 |= 0x02; // Start conversion
while(ADCON0 & 0x02) // wait for conversion
{
}
nRet = ADRESH;
nRet <<=8;
nRet += ADRESL;
ADCON0 = 0b10001001; //peripheral 2 - PORT A:2 - AN2
__delay_us(250);
unsigned short nRet;
ADCON0 |= 0x02; // Start conversion
while(ADCON0 & 0x02) // wait for conversion
{
}
nRet = ADRESH;
nRet <<=8;
nRet += ADRESL;
ADCON0 = 0b10001101; //peripheral 2 - PORT A:4 - AN3
__delay_us(250);
unsigned short nRet;
ADCON0 |= 0x02; // Start conversion
while(ADCON0 & 0x02) // wait for conversion
{
}
nRet = ADRESH;
nRet <<=8;
nRet += ADRESL;
return (nRet & 0x3FF);
【问题讨论】: