#include <reg52.h>
#include <stdlib.h> //°üo¬rand()Ëæ»úoˉêyμÄí·Îļt
#include "DS18B20.H"
//o궨òå
#define N 2
#define wenduh 3000 //±¨¾ˉζ跶Χé趨
#define wendul 0
//붨òå
sbit k1=P1^1; //ὸö°′Å¥¶¨òå P1^0òѾ-±»DS18b20Õ¼óÃ
sbit k2=P1^2;
sbit Rlight=P1^7;
sbit Glight=P1^6;
sbit Ylight=P1^5;
sbit speaker=P2^3;
sbit E=P3^4;
sbit F=P3^5;
sbit G=P3^7;
sbit H=P3^6;
char mode=0; //Ä£ê½ÇD»»±äá¿
unsigned int num;
unsigned int smgdata=0;
unsigned int code SMG[20]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
void delay(uint z)
{
int x,y;
for(x=115;x>0;x--)
for(y=z;y>0;y--);
}
void shortdelay(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=10;y>0;y--);
}
void kdeal()
{
if((k1==0)&&(k2==1))
{
delay(3);
if((k1==0)&&(k2==1))
{
mode++;
if(mode==3)
mode=0;
}
}
}
void display(int a,int b,int c,int d)
{
P0=SMG[a]; E=0;shortdelay(15);E=1;
P0=SMG[b]; F=0;shortdelay(15);F=1;
P0=SMG[c]; G=0;shortdelay(15);G=1;
P0=SMG[d]; H=0;shortdelay(15);H=1;
}
void temperaturedatasolve(unsigned int temp)
{
unsigned int x,a,b,c,d;
x=temp/10000;
a=temp/10000;
b=temp/1000-a*10;
c=temp/100-a*100-b*10;
d=temp/10-a*1000-b*100-c*10;
display(a,b,c+10,d);
}
void SMGdhdatasolve(unsigned int shijian)
{
int qian,bai,shi,ge; char i;
for(i=0;i<4;i++)
{
qian=shijian/1000; P0=SMG[qian]; E=0; shortdelay(10); E=1;
bai=shijian%1000/100; P0=SMG[bai]; F=0; shortdelay(10); F=1;
shi=shijian%100/10; P0=SMG[shi]; G=0; shortdelay(10); G=1;
ge=shijian%10; P0=SMG[ge]; H=0; shortdelay(10); H=1;
}
}
void main()
{
unsigned int count=0;
unsigned int wendu;
TMOD=0x10; EA=1; ET1=1;
while(1)
{
TH1=(65536-45872)/256;
kdeal();
if(mode==0)
{
wendu=ReadTemperature();
temperaturedatasolve(wendu);
if((wendu<wendul)||(wendu>wenduh))
{
TR1=1;
if((num%10)==0)
{
count++;
if(count==5)
{
Rlight=~Rlight;
speaker=~speaker;
}
if(count==10)
{
count=0;
Rlight=~Rlight;
speaker=~speaker;
}
}
}
else
{
Rlight=1;
speaker=1;
}
}
if(mode==1)
{
TR1=1;
SMGdhdatasolve(smgdata);
}
}
}
void T1_time() interrupt 3
{
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
num++;
if((num%20)==0)
{
smgdata++;
}
}
|