DS18B20溫度傳感器64位ROM地址讀?。⊿TC89C52)
程序代碼:
#include
#define
#define
sbit
sbit
sbit
sbit
uchar
uchar
uchar
int
float
uchar
//*****************LCD1602*******************************
void
{
uint
for(x
for(y
}
void
{
lcdrs
P0
delay(5);
lcden
delay(5);
lcden
}
void
{
lcdrs
P0
delay(5);
lcden
delay(5);
lcden
}
void
{
uchar
lcdrw
lcden
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(i
{
write_date(table[i]);
delay(5);
}
write_com(0x80+0x40);
for(i
{
write_date(table1[i]);
delay(5);
}
write_com(0x80+11);
write_date(0xdf);
write_com(0x80+0x40+11);
write_date(0xdf);
}
//*******************DS18B20****************************
void
{
uint
ds
i
while(i>0)
i--;
ds
i
while(i>0)
i--;
}
bit
{
uint
bit
ds
i++;
ds
i++;
i++;
dat
i
while(i>0)
i--;
return
}
uchar
{
uchar
dat
for(i
{
j
dat
}
return
}
void
{
uint
uchar
bit
for(j
{
testb
dat
if(testb)//寫1
{
ds
i++;i++;
ds
i
while(i>0)
i--;
}
else
{
ds
i
while(i>0)
i--;
ds
i++;i++;
}
}
}
void
{
dsreset();
delay(1);
tempwrite(0x44);
}
uint
{
uchar
dsreset();
delay(1);
tempwrite(0xcc);
tempwrite(0xbe);
a
b
temp
temp<<=8;
temp
if(temp<0x0fff)
temp=~temp+1;
tflag=1;//負值標識符
f_temp
temp
//f_temp
return
}
void
{
write_com(address);
write_date(date);
}
void
{
uint
w1
w2
w3
w4
if(tflag==0)
write_wendu(0x80+5,0x20);
else
write_wendu(0x80+5,0x2d);
if(w1==0)
{
write_wendu(0x80+6,0x20);//百位為0,不顯示
if((w1==0)&&(w2==0))
write_wendu(0x80+7,0x20);
else
write_wendu(0x80+7,0x30+w2);
write_wendu(0x80+8,0x30+w3);
}
else
{
write_wendu(0x80+6,0x30+w1);
write_wendu(0x80+10,0x30+w4);
}
}
void
{
uint
dsreset();
delay(1);
{
fCode[i]=tempread();
}
write_com(0x80+0x40);
for
{
xulie
xulie
}
}
//************************************************
void
{
DispCode();
while(1)
{//searchrom();
tempchange();
display();
}
}
評論