#include<reg52.h>
#include<stdio.h>
#define Alarm 10
sbit DQ=P2^4;
sbit Beep=P3^4;
unsigned char tempL=0, tempH=0;
unsigned char flag=0;
unsigned int temperature,negtemper;
unsigned char idataaddrdat[2]= {0x0,0x0};
unsigned char tab[]= {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char
tab1[]= {0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x10} ;
unsigned char dispbuf[3]={0, 0, 0};
unsigned char warning=30;
bit on=1,off=0;
void delay (unsigned int i)
{
while(i--);
}
void beep(bit i)
{
Beep=i;
}
void Init_DS18B20(void) //?????????
{
unsigned char x=0;
DQ=1; //DQ ?????
delay(8); //?????
DQ=0; //?????λ????
delay(85); //???(>480us)
DQ=1; //??????????
delay(14); //???(15-60us)
x=DQ;
delay (20);
}
ReadOneChar (void)
{
unsigned char i=0; //????????????????????????
unsigned char dat=0; //????1ms????
for(i=8;i>0;i--) //?????????????????????
{DQ=1; //?????????????????60us
delay(1); //????????????lms ?????????????
DQ=0;
dat>>=1;
DQ=1;
if(DQ)
dat|=0x80;
delay(4);
}
return (dat);
}
WriteOreChar (unsigned char dat)
{
unsigned char i=0;
for(i=8;i>0;i--)
{
DQ=0;
DQ=dat&0x01;
delay(5);
DQ=1;
dat>>=1;
}
delay(4);
}
Read_Temperature (void)
{
Init_DS18B20();
WriteOneChar(0xcc);
WriteOneChar(0x44);
delaymm(125);
Init_DS18B20();
WriteOneChar(0xcc); 这里总 'WriteOneChar': missing function-prototype 怎么改正
WriteOneChar(0xbe);
delaymm(125);
tempL=ReadOneChar();
tempH=ReadOneChar();
temperature=(tempH*256)+tempL;
return(temperature) ;
}
voidDispbuf (unsigned int temper)
{
unsigned char temp;
dispbuf[2]=(temper>>4)/10;
dispbuf[1]= (temper>>4)%10;
temp=temper&0x0F;
dispbuf[0]=temp*625/1000;
unsigned char getkey()
{
P2=0xff;
if (P2==0xfe)
{
delay(12000) ;
if (P2!=0xfe);
else return P2;
}
if(P2==0xfd)
{
delay(12000) ;
if (P2!=0xfd) ;
else return P2;
}
if (P2-=0xfb)
{
delay (12000) ;
if (P2!=0xfb);
else return P2;
}
}
Inter0_process() interrupt 2
{
unsigned char key ;
int i;
unsigned char dis=0x01;
unsigned int j ;
for (j=5000;j>0;j--)
{
key=getkey();
if (key==0xfe)
{
warning++;
delay (80) ;
}
if (key==0xfd)
{
warning-- ;
delay (80) ;
}
if (key==0xfb)
j=1;
for(i=0;i<2;i++)
{
P1=dis;
dis<<=1;
if(i==0)
P0=tab[warning%10];
else
P0=tab[warning/10];
delay (200) ;
}
dis=0x01;
}
}
main()
{
unsigned char i,npos=0x01;
P0=0xff;
P2=0xff;
P1=0xff;
EX1=1;
IT1=1
ET1=1;
EA=1;
while(1)
{
if((temperature&0xf000)==0xf000)
{
ReadTemperature();
for(i=0;i<4;i++) //4?LED???
{
negtemper=(~temperature)+1;
Dispbuf (negtemper);
P1=npos;
npos<<=1;
if(i==1)
{
P0=tabl[dispbuf[ i]]
delay (500);
}
else if(i==3)
P0=0xhf;
else
{
P0=tab[dispbuf[ i]];
delay(500);
}
}
npos=0x01;
}
else
{
for(i=0;i<3;i++);
{
ReadTemperature();
Dpispbuf(temperature);
if(((temperature>>4)&0xff)=warning)
beep (on) ;
else beep(off)
P1=npos;
npos<<=1;
if(i==1)
P0=tabl [dispbuf[ i]];
else
P0=tab[dispbuf[ i]];
delay (100);
}
npos=0x01;
}
}
}
|