是想扫描四个通道,但是每次只能读到一个数据,就是AN8的数据。请大神指点一下呗,代码在下面,芯片是PIC32MX564-128H
void __ADC10SCAN()
{
uint a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0;
uint i = 0;
AD1PCFG &= 0x3CFF; // All PORTB = Digital; RB15、14、9、8 = analog
AD1CON1 = 0x00E4; // SSRC bit = 111 implies internal(自动转换)
AD1CHS &= (~BIT(23)); // 选择VR- 作为MUX A 反相输入
// In this example RB12/AN12 is the input
AD1CSSL |= BIT(15) | BIT(14) | BIT(9) | BIT(8); //扫描AN15、14、9、8
AD1CON3 = 0x0F00; // Sample time = 15 TAD
AD1CON2 &= 0x03E; //四次产生中断,总是使用MUX A多路开关,一个16字缓冲区
AD1CON2 |= BIT(10); //扫描输入
AD1CON1SET = 0x8000; // Turn ON the ADC
while (1) // Repeat continuously
{
// AD1CON1 |= 0x0002; // 启动采样
// while ( ! mAD1GetIntFlag() ) { }
while (!(AD1CON1 & 0x0001)); // Conversion done?转换是否完成
a = ADC1BUF0; // Yes, get ADC value
b = ADC1BUF1; // Yes, get ADC value
c = ADC1BUF2; // Yes, get ADC value
d = ADC1BUF3; // Yes, get ADC value
e = ADC1BUF4; // Yes, get ADC value
f = ADC1BUF5; // Yes, get ADC value
g = ADC1BUF6; // Yes, get ADC value
h = ADC1BUF7; // Yes, get ADC value
a = ADC1BUF0; // Yes, get ADC value
b = ADC1BUF1; // Yes, get ADC value
c = ADC1BUF2; // Yes, get ADC value
d = ADC1BUF3; // Yes, get ADC value
e = ADC1BUF4; // Yes, get ADC value
f = ADC1BUF5; // Yes, get ADC value
g = ADC1BUF6; // Yes, get ADC value
h = ADC1BUF7; // Yes, get ADC value
a = ADC1BUF8; // Yes, get ADC value
b = ADC1BUF9; // Yes, get ADC value
c = ADC1BUFA; // Yes, get ADC value
d = ADC1BUFB; // Yes, get ADC value
e = ADC1BUFC; // Yes, get ADC value
f = ADC1BUFD; // Yes, get ADC value
g = ADC1BUFE; // Yes, get ADC value
h = ADC1BUFF; // Yes, get ADC value
i++;
AD1CON1 & (~0x0001);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>