【发布时间】:2021-09-01 19:45:31
【问题描述】:
我试图读取 PIC16F15325 上引脚 RC3 上的模拟电压。我的电位器上有 3.23V 电压,它的输出接近 1.65V,连接到 PIC 微控制器的 RC3 引脚。对于配置和库,我使用了 MPLAB Code Cofigurator。代码如下:
#include "mcc_generated_files/mcc.h"
void main(void)
{
// initialize the device
SYSTEM_Initialize();
EUSART1_Initialize();
ADC_Initialize();
adc_result_t val1 = 0;
// When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
// Use the following macros to:
// Enable the Global Interrupts
//INTERRUPT_GlobalInterruptEnable();
// Enable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptEnable();
// Disable the Global Interrupts
//INTERRUPT_GlobalInterruptDisable();
// Disable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptDisable();
while (1)
{
// Add your application code
val1 = ADC_GetConversion(19); // selected channel RC3
printf("Value - %hu \n",val1);
DELAY_milliseconds(1000);
}
}
对于我上面提到的电压,我期望值接近“511”。任何超过 1023 [即(2^10) - 1] 很奇怪,因为 PIC 有 10 位 ADC。但是我得到的 uotput 是:
请帮我解决这个问题。
【问题讨论】:
-
如果您需要帮助,您必须展示您的完整程序,而不仅仅是主循环。你真的认为 RC3 是 19 频道吗?
-
请不要发布文本截图,将其作为文本插入。是的,您可以从 TeraTerm 复制粘贴。
标签: c microcontroller pic adc