|
int Read_ Temp(void)//启动温度转换并读取数据 Temp前 ; 丢失,大家给看看怎么回事 ?(DS18B20测温程序.C(71): error C129: missing ';' before 'Temp')
/* P1.0 作为DQ时钟线输入*/
#include
sbit DQ=P1^0;//DQ输入信号口
sbit p24=P2^4;//数码管位控制口
sbit p25=P2^5;
sbit p26=P2^6;
sbit p27=P2^7;
unsigned int d=0;//低 两位
unsigned int e=0;//高位
unsigned char code x[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//共阳字段吗
void Delay(unsigned char MSecond)//延时程序
{
int i;
for(i=0;i
}
unsigned char Rst(void) //复位DS18bxx
{
unsigned char Rly;
DQ=0;
Delay(250);
DQ=1;
Delay(10);
Rly=P1&0X01;
Delay(50);
return(Rly); //返回应答信号
}
unsigned char Read_Byte(void)//读一个字节
{
unsigned char i,temp;
unsigned char Data;
for(i=0;i<8;i++)
{
Data>>=1; //数据移位
DQ=0;
DQ=1;
Delay(10);
temp=P1&0X01;//判断引脚 电 平
if(temp)//如果为高
{
Data|=0x80;
}
Delay(40);
}
return(Data);
}
void Write_Byte(char Data)//写一个字节
{
unsigned char i,temp;
for(i=0;i<8;i++)
{
DQ=0;
temp=Data&0x01;
if(temp) //判断是否为高电平,如果为高电平
{
DQ=1;
}
else //如果为低电平
{
DQ=0;
}
Delay(20);
DQ=1;
temp=temp/2;
}
Delay(20);
}
int Read_ Temp(void)//启动温度转换并读取数据
{
char temp[2];
int Data;
unsigned char Rst_Flg;
Rst_Flg=Rst();//复位DS18B XX
if(Rst_Flg=0)//如果有复位信号标志
{
Rst_Flg=0xff;
Write_Byte(0xcc);//跳过ROM设定
Write_Byte(0x44);//启动转换
Delay(40);//等待转换完毕
Write_Byte(0xcc);
Write_Byte(0xbe);
temp[1]=Read_ Temp();//读高位数据
temp[0]=Read_ Temp();//低位数据
Rst_Flg=Rst(); //只接 收最低两位数据
while (Rst_Flg=0xff);
Rst_Flg=0xff;
e=Data/100;
d=Data%100;
Data=tmp[1]*256+temp;//合并数据
return Data;
}
}
void fun()//数码管延时
{
unsigned char i;
for(i=0;i<50;i++)
;
}
void xs()//显示程序
{
P0=x[e/10];
p24=0;
fun();
p24=1;
P0=x[e%10];
p25=0;
fun();
p25=1;
P0=x[d/10];
p26=0;
fun();
p26=1;
P0=x[d%10];
p27=0;
fun();
p27=1;
}
void main()
{
for(;;)
{
xs();
}
}
|
|