我在 PIC18F 微控制器中工作,为差动模拟输入配置的代码,
在读取00:根据输入 MSB 值转换寄存器时,MSB 值将更新,但 LSB 值常量0xFF 我尝试了不同的配置 AN0到 AN3,但结果没有变化,下面我给出了我的代码。
int main()
{
unsigned char lsb、msb、a = 0;
unsigned int adcdata;
I2C_init();
I2C_Master_Start (A);
I2C_Master_Write (0x90);
while (SSP1CON2bits.ACKSTAT1);
I2C_Master_Write (0x01);
while (SSP1CON2bits.ACKSTAT1);
I2C_Master_Write (0x22); /AN1和 AN3 /0x74、0x84
while (SSP1CON2bits.ACKSTAT1);
I2C_Master_Write (0x83);/0x83
while (SSP1CON2bits.ACKSTAT1);
I2C_Master_Stop ();
while (1)
{
// delay_ms (1);
I2C_Master_Start (A);
I2C_Master_Write (0x90);
while (SSP1CON2bits.ACKSTAT1);
I2C_Master_Write (0x00);
while (SSP1CON2bits.ACKSTAT1);
I2C_Master_Stop ();
// delay_ms (1);
I2C_Master_Start (A);
I2C_Master_Write (0x91);
while (SSP1CON2bits.ACKSTAT1);
MSB = I2C_Master_read ();
while (SSP1CON2bits.ACKDT);
LSB = I2C_Master_read ();
while (SSP1CON2bits.ACKDT);
I2C_Master_Stop ();
adcdata = lsb;
adcdata +=((int) msb)<< 8;
delay_ms (1);
}
返回(EXIT_SUCCESS);
}
此致、
Murali