#include<pic.h>
#define uint unsigned int
#define uchar unsigned char
__CONFIG(0x3B31);
const uchar table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//1,2,3,4,5,6,7,8,9共阳极数码管
const uchar table1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};//带小数点数字
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void chushihua()
{
uchar i;
TRISA=0X01;
PORTA=0;
TRISB=0;
TRISC=0;
PORTB=0;
PORTC=0xff;
ADCON0=0X85;
ADRESH=0;
ADRESL=0;
ADCON1=0X10;
NOP();NOP();
for (i=0;i<3;i++);
NOP();NOP();
}
uint getad()
{
uint adval,aa;
float advalf;
GO=1;//启动转换
while(GO);
adval=ADRESH;
adval=adval<<8|ADRESL;
advalf=adval/1023*5000;
aa=(int)advalf;
return(aa);
}
void xianshi(uchar num1,uchar num2,uchar num3,uchar num4)
{
PORTC=table[num1];
PORTB=0x10;
delay(2);
PORTC=table[num2];
PORTB=0x20;
delay(2);
PORTC=table1[num3];
PORTB=0x40;
delay(2);
PORTC=table[num4];
PORTB=0x80;
delay(2);
}
void main()
{
uint lednum;
uchar a1,a2,a3,a4;
chushihua();
while(1)
{
lednum=getad();
a1=lednum/1000;
a2=lednum%1000/100;
a3=lednum%100/10;
a4=lednum%10;
xianshi(a1,a2,a3,a4);
}
}
有谁知道这段代码写进芯片16F690之后,使用AN1端口只是在测试5V的时候有显示数字500,小于5V没有显示是什么原因
|
老哥还在用吗?我现在是正常3.7v供电,我现在用3.5v供电也是500多,正常来说采样精度是10位,不是1024么