我试图构建一个从电位器到Arduino的AD转换器。我正在尝试同时在MPLAB中学习MCC。到目前为止,我已经生成了一个适合我PIC的代码(我想......)。我的问题是我的位表示输出不正确。这是锄我的PIC16F1827配置(se图片)
RA0 =输入,RB1和RB2 = EUSART和RB0,RB3,RA7,RA6,RB7,RB6,RB5,RB4 =输出。
我的主文件看起来像这样(se代码)。我得到一个输出,但它代表错误,我不知道为什么...
char ADC_temp_in;
while (1) //Infinite Loop
{
// Add your application code
printf("pot_value =%d\r\n", ADC_GetConversion(channel_AN0_ADC));
ADC_temp_in = ADC_GetConversion(channel_AN0_ADC); // temp
PORTB = ADC_temp_in; //Write Lower bits to PORTB
PORTA = ADC_temp_in>>6; //Write Higher 2 bits to PORTA
__delay_ms(100); //Delay
}
VREF + = 5V,直接连接到VDD。
我的目标是将RB0作为LSB,RA7作为MSB,电位差为0-5 V。
两件事情:
ADC_temp_in
必须通过16位值来保持大于8位的值。
所以试试:uint16_t ADC_temp_in;
当然你的函数ADC_GetConversion
必须返回uint_16
值。
另一件事是,要获得MSB,你必须将你的价值转移8倍。
PORTA = ADC_temp_in>>8;