#include<reg51.h>
#include<intrins.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
uint temp;
uchar i;
uint a;
float v;
uint v1,v2;
uchar qian,bai,shi,ge;
void display();
void delay(uint z);
void time0_init();
void time1_init();
void AD_0809();
uchar code table1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar code table2[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1};
sbit ST=P2^6;
sbit OE=P2^5;
sbit EOC=P2^4;
sbit CLK=P2^3;
sbit ALE=P2^6;
sbit OUT=P3^6;
uint gatedate;
uchar flag;
float t;
void main()
{
flag=0; //标志位0
time1_init();
time0_init();
while(1)
{
AD_0809(); //AD转换程序
if(v>1&&v<4)
{
display();
t=(float)(14060.0/(v*v));
TR1=1;
display();//数码管显示程序
while(a>=t)
{
flag=1; //标记位改为1;数码管停止计数
display();//数码管显示程序
}
}
void time0_init()
{
TMOD=0x12;
TH0=6;
TL0=6;// TL0=(65536-20)%256;
EA=1;
ET0=1;
TR0=1;
}
void timer0()interrupt 1
{
CLK=~CLK;
}
void display()
{
P3=0xbe;
P0=table1[qian];
delay(2);
P3=0xbd;
P0=table2[bai];
delay(2);
P3=0xbb;
P0=table1[shi];
delay(2);
P3=0xb7;
P0=table1[ge];
delay(2);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--); //110
}
void timer1()interrupt 3
{
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
a++;
i++;
if(i==10)
{
i=0;
if(flag==0)temp++;
if(temp==9999)
temp=0;
if(flag==0)
{
qian=temp/1000;
bai=temp%1000/100;
shi=temp%100/10;
ge=temp%10;
}
}
}
void time1_init()
{
TMOD=0x12;
EA=1;
ET1=1;
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
TR1=0;
}
void AD_0809()
{
ST=0;
_nop_();
OE=0;
_nop_();
ST=1;
_nop_();
ST=0;
while(EOC==0);
OE=1;
gatedate=P1;
_nop_();
OE=0;
v1=gatedate*5/256;
v2=(gatedate*500/256)%100;
v=v1+(float)v2/100;
|