u8 baojing=600;float t1,t2,t3,t_zhi;
u8 a=0,b=0,c=0,d=0;
u16 flag=0;
u16 p_temp;
unsigned char code LEDCODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char code dot[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
void delay(u16 ms)
{
u16 i,j;
for(i=ms;i>0;i--)
for(j=110;j>0;j--);
}
void display(void){
u16 temp3=t_zhi*10;
if(t_zhi<1000)
{a=temp3%10000/1000;
b=temp3%1000/100;
c=temp3%100/10;
d=temp3%10;
P0=LEDCODE[a];
P2=0X01;//000000001
delay(1);
P2=0X00;
P0=LEDCODE[b];
P2=0X02;//0000 0010
delay(1);
P2=0X00;
P0=dot[c];
P2=0X04;//0000 0100
delay(1);
P2=0X00;
P0=LEDCODE[d];
P2=0X08;//0000 1000
delay(1);
P2=0X00;
}
}
u16 get_temp()
{
u8 i;
u16 temp2=0;
sck=0;
sd=0;
cs=0;
for(i=0;i<16;i++)
{sck=1;
if(sd==1)
{
temp2=temp2|0x01;
}
delay(10);
sck=0;
delay(10);
temp2<<=1;
}
cs=1;
if(temp2&0x00004)
{
normal=1;
}
temp2=(temp2&0x7fff)>>3;
return(temp2);
temp2=0;
delay(200);
}
void get_baojing(void)
{
if(t_zhi<=500&&t_zhi>=baojing)
{delay(500);
shengyin=~shengyin;
unnormal=0;
}
}
void change()
{if(key1==0)
{delay(10);
if(key1==0)
{flag=1;
}
}
if(key2==0&&flag==1)
{baojing=baojing+5;
flag=0;
}
if(key3==0&&flag==1)
{baojing=baojing-5;
flag=0;
}
}
void main (void)
{
delay(10);
normal=0;
sd=0;
while(1)
{p_temp=get_temp();
t1=0.25*p_temp;
delay(500);
p_temp=0;
p_temp=get_temp();
t2=0.25*p_temp;
delay(500);
p_temp=0;
p_temp=get_temp();
t3=0.25*p_temp;
t_zhi=((t1*t3)-(t2*t2))/((t3+t1)-(2*t2));
get_baojing();
display();
change();
t_zhi=0;
}
}
|