用PIC16F877A的一个I/O口检测电压 当检测到的电压=5V时 RE0输出高电平,帮忙看下是哪里出了问题,为什么实现不了这个功能?谢谢了
void main()
{
uint lednum,d;
d=5;
uint a1,a2,a3,a4;
init();
while(1)
{
lednum=get_ad();
a1=lednum/1000;
a2=lednum%1000/100;
a3=lednum%100/10;
a4=lednum%10;
disp(a1,a2,a3,a4);
if(a1=d)
{
RE0=1;
}
}
}
void init()
{
TRISA=0x01;
TRISD=0x00;
TRISE=0x00;
PORTA=0X00;
PORTD=0x00;
PORTE=0xFF;
ADCON0=0x41;
ADCON1=0x8E;
delay(10);
}
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
uint get_ad()
{
uint adval;
float advalf;
GO=1;
while(GO);
adval=ADRESH;
adval=adval<<8|ADRESL;
advalf=adval/1023.0*5.0;
adval=advalf*1000;
return (adval);
}
void disp(uchar num1,uchar num2,uchar num3,uchar num4)
{
PORTD=table1[num1];
PORTA=0x20; //0010 0000
delay(2);
PORTD=table[num2];
PORTA=0x10; //0001 0000
delay(2);
PORTD=table[num3];
PORTA=0x08; //0000 1000
delay(2);
PORTD=table[num4];
PORTA=0x04; //0000 0100
delay(2);
}