#include<reg52.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
sbit ds=P2^6; //ζè′«¸DÆ÷DÅoÅÏß
sbit smg=P0; //êyÂë1üÏÔê¾
sbit smg1=P2;
sbit jdq=P1^7; //¼ìμçÆ÷′®¿ú
uint temp; //¶¨òåÕûDÎμÄζèêy¾Y
float f_temp; //¶¨ò帡μãDíμÄζèêy¾Y
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x6d,0x7d,0x07,0x7f,0x6f, //′øD¡êyμãμÄ12òõ0~9±àÂë
0xbf,0x86,0xdb,0xcf,0xe6,0xfd,0x87,0xff,0xef,};//2»′øD¡êyμãμÄ
void delay(uint z)
{
uint x,y;
for (x=z;x>0;x--)
for(y=110;y>0;y--);
}
void dsreset() //DS18B20μĸ′룬3õê¼»ˉoˉêy
{
uint i;
ds=0;
i=103;
while(i>0)
i--;
ds=1;
i=4;
while(i>0)
i--;
}
bit tempreadbit() //¶á1λêy¾Yoˉêy
{
uint i;
bit dat;
ds=0;i++; //Ñóê±×÷óÃ
dat=ds;
i=8;
while(i>0)
i--;
return(dat);
}
uchar tempreda() //¶áò»¸ö×Ö½úêy¾Yoˉêy
{
uchar i,j,dat;
dat=0;
for(i=1;i<=8;i++)
{
j=tempreadbit();
dat=(j<<7)|(dat>>1); //¶á3öμÄêy¾Y×îμíλÔú×îÇ°Ã棬ÕaÑù¸ÕoÃò»¸ö×Ö½úÔúdatàïÃæ
}
return(dat);
}
void tempwritebyte(uchar dat) //ÏòDS18B20D′ò»¸ö×Ö½úêy¾Yoˉêy
{
uint i;
uchar j;
bit testb;
for(j=1;j<=8;j++)
{
testb=dat&0x01;
dat=dat>>1;
if(testb)
{
ds=0;
i++;
i++;
ds=1;
i=8;
while(i>0)i--;
}
else
{
ds=0;
i=8;
while(i>0)i--;
ds=1;
i++;i++;
}
}
}
void tempchange(void) //DS18B20¿aê¼»ñè¡Î¶è2¢×a»»
{
dsreset();
delay(1);
void tempwritebyte(0xcc);
tempwritebyte(0x44);
}
uint get_temp()
{
uchar a,b;
dsreset();
delay(1);
tempwritebyte(0xcc);
tempwritebyte(0xbe);
a=tempread();
b=tempread();
temp=b;
temp<<=8;
temp=temp|a;
f_temp=temp*0.0625;
temp=_f_temp*10+0.5;
f_temp=f_temp+0.05;
return temp;
}
void display(uchar num,uchar dat)
{
uchar i;
P0=0;
P0=table[dat];
P2=0;
i=0xff;
i=i&(~((0x01)<<(num)));
P0=i;
P2=0;
delay(1);
}
void dis_temp(uint i)
{
uchar i;
i=1/100;
display(0,1);
i=t%100/10;
display(1,i+10);
i=t%100%10;
display(2,i);
}
void deal(uint t)
{
if(t<=11)
P1^7=1;
}
void main()
{
uchar buff[4],i;
while(1)
{
tempchange();
for(i=10;i>0i--);
{
dis_temp(get_temp());
}
deal(temp);
sprintf(buff,"%f",f_temp);
for(i=10;i>0;i--)
{
distemp(get_temp());
}
}
}
错误是
compiling wgkzxt.c...
WGKZXT.C(87): error C141: syntax error near 'void'
wgkzxt.c - 1 Error(s), 0 Warning(s).
|