#include<reg51.h>
#include<stdio.h>
#define uint unsigned int
#define uchar unsigned char
sbit temp_oper=P3^0;
sbit temp_up=P3^1;
sbit temp_down=P3^2;
sbit temp_sure=P3^3;
sbit beep=P2^5;
sbit DQ=P1^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
uchar buf[4];
void delayms(uint xms)
{uint i,j;
for(i=0;i=xms;i++)
{for(j==0;j==110;j++);
}
}
void delay(uint t)
{
for (;t>0;t--);
}
void display()
{
uchar i,j;
j=0x07;
for(i=0;i<4;i++)
{P0=table[buf];
P2=j;
j=j>>1;
}
}
void key()
{
uchar flag_key,temp;
flag_key=0 ;
temp=0 ;
if(temp_oper==0)
{
delayms(10);
if(temp_oper==0)
flag_key=1;
}
while(flag_key)
{
if(temp_up==0)
{
delayms(10);
if(temp_up==0)
temp++;
}
if(temp_down==0)
{
delayms(10);
if(temp_down==0)
temp--;
}
if(temp_sure==0)
{
delayms(10);
if(temp_sure==0)
flag_key=0;
}
}
}
void BEEP(uchar temp,temprature)
{
if(temprature>=temp)
{beep=1;
while(1);
}
else
beep=0;
}
void ds18b20rst()
{
uchar x=0;
DQ=1;
delay(4)//从高拉倒低
DQ=0;
delay(50); //550 us
DQ=1;
delay(6);
} //66 us
void ds18b20wr(uchar wdata)
{
uchar i=0;
for(i=8;i>0;i--)
{
DQ=0;
DQ=wdata&0x01;
delay(5);
DQ=1;
wdata>>=1;
}
}
uchar ds18b20rd()
{
uchar i=0;
uchar dat=0;
for(i=8;i>0;i--)
{
DQ=0;
dat>>=1;
DQ=1;
if(DQ)
dat|=0x80;
delay(5);
}
return(dat);
}
read_temp()
{
uchar a,b,symbol,temprature;
ds18b20rst();
ds18b20wr(0xcc);
ds18b20wr(0x44);
ds18b20rst();
ds18b20wr(0xcc);
ds18b20wr(0xbe);
a=ds18b20rd();
b=ds18b20rd();
temprature=b;
temprature<<=8;
temprature=temprature|a;
if(temprature<0x0fff)
symbol=0;
else
{
temprature=~temprature+1;
symbol=1;
}
temprature=temprature*(0.625);
return(temprature);
}
void main()
{
uchar temp,temprature;
uchar buf[4];
buf[0]=temp%10;
buf[1]=temp/10;
buf[2]=temprature%10;
buf[3]=temprature/10;
P0=0 ;
P2=0 ;
read_temp();
ds18b20wr(0xcc);
ds18b20wr(0x44);
while(1)
{
key();
read_temp();
display();
BEEP();
}
}
显示设计1.C(86): error C141: syntax error near 'DQ'
不知如何改正,求帮忙 |