还没做出实物,在protues上仿真时采集0.5V的电压出现的却是1.71V,如图所示,[img=http://hi.csdn.net/space-3394646-do-album-picid-756407.html][/img]代码如下,
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit ST=P3^0;
sbit OE=P3^1;
sbit CLK=P3^2;
sbit EOC=P3^3;
sbit P20=P2^0;
sbit P21=P2^1;
sbit P22=P2^2;
sbit P23=P2^3;
sfr LedPort=0x90; //P1口接段码
sfr DataPort = 0x80;
void init();
float AD();
void delay(uint z);
void display(uint b);
uint jisuan(float m);
uint suhuanchong[4]={0,0,0,0};
uchar code ntable[11]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
,0x00}; //不带小数点编码表
uchar code htable[11]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef
,0x80}; //带小数点编码表
void init()
{
TMOD=0x01;
TH0=(65536-45)/256;
TL0=(65536-45)%256;
EA=1;
ET0=1;
TR0=1;
}
float AD()
{ uint getdata;
float result;
OE=0;
ST=0;
ST=1;
delay(1);
ST=0;
while(!EOC);
OE=1;
getdata=DataPort;
OE=0;
result=getdata*5/256.0;
return result;
}
uint jisuan(float m)
{ uint b;
uint shi,ge,xiao1,xiao2;
uint x;float y;
//m=m*5/256;
x=(int)m; // 整数部分
y=m-x; // 小数部分
if(x>=100)
b=1;
shi=x/10; // 求十位
ge=x%10; // 求个位
xiao1= (int)(y*10); // 求小数点后第一位
xiao2=(int)(y*100)%10; // 求小数点后第二位
if(shi==0)
{
shi=10; //如最高位为0则消隐
if(ge==0) //如最高位为0且次高位也为0则都消隐
ge=10;
}
suhuanchong[0]=shi; //把计算出来的各位存入临时数组
suhuanchong[1]=ge;
suhuanchong[2]=xiao1;
suhuanchong[3]=xiao2;
return b;
}
void display(uint b)
{ P2 = 0xff; //关所有的位选
if(b!=1)
{
LedPort = ntable[suhuanchong[0]] ; //动态扫态
P20 = 0;
delay(1);
P20 = 1;
LedPort = htable[suhuanchong[1]] ;
P21 = 0;
delay(1);
P21 = 1;
LedPort = ntable[suhuanchong[2]] ;
P22 = 0;
delay(1);
P22 = 1;
LedPort = ntable[suhuanchong[3]] ;
P23 = 0;
delay(1);
P23 = 1;
}