3位显示。实测电压3.39V,显示006.?
最大电压值5V 显示005、
________________________我程序也拿上来大神帮忙看看__________________________________________
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit eoc=P3^3;//转换标志 高有效
sbit wr=P3^6;
sbit rd=P3^7;
uchar code duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void smg(uchar d,w);
void adc();
void
timer();
uint getdata;
void delay(uint t)
{
uchar a;
while(t--)
{
for(a=0;a<75;a++){;}
}
}
main()
{
timer();
while(1)
{
adc();
}
}
void smg(uchar d,w)
{
P2=duan[d]; //送段数据.
// delay(1); //亮
P1=wei[w]; //送位数据
delay(1); //给1ms延时.如果延时久,跟跑马灯似的....
P1=0xff; //共阴位0开、1关
}
void adc()
{
wr=0;
wr=1;
wr=0;
rd=1;
wr=0;
while(eoc==1){;}//等待转换结束
rd=0;
// wr=0;
getdata=P0;
rd=1;
// wr=0;
}
void timer()
{
TMOD=0X01;
TH0=0XFC;
TL0=0X18;
ET0=1;
TR0=1;
EA=1;
}
void time()interrupt 1
{
TH0=0Xfc;
TL0=0X18;
smg(getdata/100,0);
getdata=getdata%10;
smg(getdata/10,1);
smg(getdata%10,2);
}
_________________________________________结束 ____________________________________________
-
一周热门 更多>