#include<reg51.h
#include<math.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P2^0;
sbit rw=P2^1;
sbit lcden=P2^2;
uchar table1[4]="flow";
uchar table2[8]=" .L/s";
sbit TX=P1^7;
sbit RX=P3^3;
sbit K0=P3^0;
uchar H;
uchar a;
/****************************/
void DATE_DEAL(uchar date)
{
double a,b;
uchar Q,m;
a=1.84 ; b=1.5;
m=a*pow(H,b);
Q=m*1000;
table2[0]=Q/100+0x30;
table2[1]=(Q%100)/10+0x30;
table2[2]=Q%10+0x30;
table2[4]=Q*10%10+0x30;
}
/***************************/
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=112;j>0;j--);
}
/***************************/
void write_com(uchar com)
{
delay(10);
rs=0;
rw=0;
P0=com;
delay(10);
lcden=1;
delay(10);
lcden=0;
}
void write_date(uchar date)
{
delay(10);
rs=1;
rw=0;
P0=date;
delay(10);
lcden=1;
delay(10);
lcden=0;
}
void init()
{
write_com(0x38);
delay(5);
write_com(0x38);
delay(5);
write_com(0x38);
delay(5);
write_com(0x38);
write_com(0x08);
write_com(0x01);
write_com(0x06);
delay(5);
write_com(0x0C);
}
/******************************/
void main()
{ uchar a;
uchar table3[11]=" welcome";
uchar table4[15]="start measuring";
init();
{
write_com(0x80+0);
delay(20);
for(a=0;a<11;a++)
{
write_date(table3[a]);
delay(20);
}
write_com(0xC0+0);
delay(20);
for(a=0;a<15;a++)
{
write_date(table4[a]);
delay(20);
}
while(1);
if(K0==0) {
TMOD=0x11;
TH0=0;
TL0=0;
ET0=1;
TX=0;
RX=1;
IT0=0;
EX0=1;
EA=1;
while(1)
{
TR0=1;
TX=1;
delay(1);
TX=0;
}}
}}
/*********ía2¿ÖD¶ÏÄ£¿é*****************/
void int0() interrupt 2 {
uchar time,jsh,jsl;
while(!RX){
TR0=0;EX0=0;EA=0;
jsh=TH0;jsl=TL0;
time=jsh*256+jsl;
TH0=0;
TL0=0;
H=150-170*time*0.0001;
delay(100);
TH0=2;
TL0=2; }
DATE_DEAL(H);
write_com(0x80+0);
delay(20);
for(a=0;a<8;a++)
{
write_date(table2[a]);
delay(20);
}
write_com(0xc0+0);
delay(20);
for(a=0;a<4;a++)
{
write_date(table1[a]);
delay(20);
}
}
|