主要是我感觉量程选择的程序有问题,要不你给我看看?
#include
#define uchar unsigned char
#define uint unsigned int
***it wela=P2^7;
***it dula=P2^6;
***it kzd=P2^5;//第三个锁存器;
***it key=P3^5;
void jishu();
uchar code table[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f, //0~9
0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0x80 //0.~9.
};
void delay(uint);
void display(uchar,uchar,uchar,uchar);
long t=0;
uchar count,a,b,c,d;
double y,r;
void jishu()
{
TMOD=0x51;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=0xff;
TL1=0xff;
EA=1;
ET0=1;
TR1=1;
TR0=1;
while(1);
}
void display(uchar a,uchar b,uchar c,uchar d)
{
dula=1;
P0=table[a];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=table[b];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
P0=table[c];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(1);
dula=1;
P0=table[d];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(1);
}
void delay(uint x)
{
uint i,j;
for (i=x;i>0;i--)
for(j=110;j>0;j--);
}
void T0_time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==10)
{
TR1=0;
TR0=0;
t=TH1*256+TL1;
a=t/1000;
b=(t/100)%10;
c=t/10%10;
d=t%10;
TH1=0xff;
TL1=0xff;
t=0;
count=0;
TR1=1;
TR0=1;
}
}
//电阻;
void dianz()
{
y=0.6931471805599453941723212145818;
P0=0x03;
jishu();
if(t>35888/100)
{a=b=c=d=0;}
else if(t>34350/100) ///
{
r=10e8/(t*2*y)-(2*10^3);
b=b+10;
}
else if(t>24045/100) ///
{
r=10e8/(t*2*y)-(2*10^3);
c=c+10;
}
else
{
P0=0x17;
jishu();
if(t>24045/100) ////
{
r=10e6/(t*2*y)-20;
a=a+10;
}
else if(t>6011/100)//////
{
r=10e6/(t*2*y)-20;
b=b+10;
}
else
{
P0=0x2b;
jishu();
if(t>6011/100) ///////
{
r=10e7/(t*2*y)-200;
c=c+10;
}
else
{
r=10e4/(t*2*y)-0.2;
a=a+10;
}
}
}
}
void main ()
{
dianz();
while(1)
{
display(a,b,c,d);
}
}
|