PIC16F877使用MPLAB用C语言在LED上显示ADC的结果
我使用 PIC16F877,目的是选择通道 4 在 PortD LED 上显示模拟输入 AN4 值。近似值约为1V。我写了一个代码,但是无论我如何运行我的代码,GPIO 监视器都没有反应。 顺便问一下,我是否在 while(1){} 循环中编写 ReadADC1() ?我尝试过,但没有任何帮助。谢谢。
#include <xc.h>
#define LEDs PORTD
#include "prologue.c"
unsigned char ReadADC1(void) {
ADCON0 |= 0b00000010;
while ( (ADCON0 & 0b00000010) );
return ADRESH;
}
main ()
{
// declare variables if any required
TRISA= 0B00100000;
ANSEL=0B00010000;
ADCON0 = 0b11010001;
ADCON1 = 0b10000000;
LEDs=ReadADC1();
//*** your code for initialisation if required
//*** end of your initialisation
//*** your code for the superloop
while (1) {
}
//*** end of the superloop
}
GPIO 引脚监视器没有反应。我多次重启IDE。
I used PIC16F877 and my purpose is to choose CHANNEL 4 to display the analogue input AN4 value on PortD leds. The approximate value is about 1V. I wrote a code and however, no matter how I ran my code, there're not reaction with the GPIO monitor.
By the way, do I write ReadADC1() in the while(1){} loop? I tried that, but there's no help. Thanks.
#include <xc.h>
#define LEDs PORTD
#include "prologue.c"
unsigned char ReadADC1(void) {
ADCON0 |= 0b00000010;
while ( (ADCON0 & 0b00000010) );
return ADRESH;
}
main ()
{
// declare variables if any required
TRISA= 0B00100000;
ANSEL=0B00010000;
ADCON0 = 0b11010001;
ADCON1 = 0b10000000;
LEDs=ReadADC1();
//*** your code for initialisation if required
//*** end of your initialisation
//*** your code for the superloop
while (1) {
}
//*** end of the superloop
}
There's no reaction with the GPIO pins monitor. I restarted the IDE many times.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,所有端口都配置为输入。如果您想使用端口作为输出,则必须更改配置:
另一个问题:
该控制器中没有 ANSEL 寄存器,您必须使用 ADCON1 寄存器进行选择(数字或模拟输入)。
By default all ports are configured as an input. If you want want use a port as an output you had to change the configuration:
Another issue:
There is no
ANSEL
register in this controller, you had to do the selection (digital or analog input) withADCON1
register.