2021-05-04

求助,这个sbit附近哪错了 syntax error near sbit
#include “onewire.h”

sbit DQ=P1^4;
void Delay_OneWire(unsigned int t)
{
unsigned char i;
while(t–){
for(i=0;i<12;i++);
}
}

void Delay_us(void)
{
unsigned char i;

i = 30;
while (--i);

}

void Write_DS18B20(unsigned char dat)
{
unsigned char i;
for(i=0;i<8;i++)
{
DQ = 0;
DQ = dat&0x01;
Delay_OneWire(5);
DQ = 1;
dat >>= 1;
}
Delay_OneWire(5);

}

unsigned char Read_DS18B20(void)
{
unsigned char i;
unsigned char dat;
// unsigned char index = 0;

for(i=0;i<8;i++)
{
	DQ = 0;
	dat >>= 1;
	DQ = 1; 
   	Delay_us();

	if(DQ)  
	{
		dat |= 0x80;
	}	    
	Delay_OneWire(5);
}
return dat;

}

bit init_ds18b20(void)
{
bit initflag = 0;

DQ = 1;
Delay_OneWire(12);
DQ = 0;

Delay_OneWire(80); // ÑÓʱ´óÓÚ480us
DQ = 1;
Delay_OneWire(10);  // 14
initflag = DQ;     // initflagµÈÓÚ1³õʼ»¯Ê§°Ü
Delay_OneWire(5);

return initflag;

}

unsigned int rd_temperature(void)
{
unsigned char low,high;
init_ds18b20();
Write_DS18B20(0xcc);
Write_DS18B20(0x44);

init_ds18b20();
Write_DS18B20(0xCC);
Write_DS18B20(0xBE);

low = Read_DS18B20();
high = Read_DS18B20();
return (high<<8)+low;

}

上一篇:单片机综合实验报告-06 | 数字温度计设计


下一篇:MY18E20可全兼容MAXIM DS18B20,广泛应用于农业及消费电子