DS18B20匹配ROM地址單總線多點(diǎn)測(cè)溫(STC89C52)
程序代碼:
#include
#define
#define
sbit
sbit
sbit
sbit
uchar
uchar
//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(table1[i]);
delay(5);
}
write_com(0x80+0x41);
for(i
{
write_date(0x2d);
delay(100);
}
write_com(0x80);
for(i
{
write_date(table[i]);
delay(5);
}
write_com(0x80+0x40);
for(i
{
write_date(table[i]);
delay(5);
}
}
//*******************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
{
char
tempwrite(0x55);
if(a==1)
{
for(j=0;j<8;j++)
tempwrite(rom1[j]);//發(fā)送18B20的序列號(hào),先發(fā)送低字節(jié)
}
if(a==2)
{
for(j=0;j<8;j++)
tempwrite(rom2[j]);//發(fā)送18B20的序列號(hào),先發(fā)送低字節(jié)
}
}
uint
{
uchar
dsreset();
delay(1);
//tempwrite(0xcc);
//dsreset();
if(z==1)
matchrom(1);
if(z==2)
matchrom(2);
tempwrite(0x44);
delay(5);
dsreset();
delay(1);
//tempwrite(0xcc);
//tempwrite(0xcc);
//dsreset();
if(z==1)
matchrom(1);
if(z==2)
matchrom(2);
tempwrite(0xbe);
a
b
temp
temp<<=8;
temp
if(temp<0x0fff)
temp=~temp+1;
tflag=1;//負(fù)值標(biāo)識(shí)符
f_temp
temp
f_temp
return
}
void
{
write_com(address);
write_date(date);
}
void
{
write_wendu(0x80,N);
write_wendu(0x81,O);
write_wendu(0x82,.);
write_wendu(0x84,:);
write_wendu(0x89,.);
write_wendu(0x8b,0xdf);
write_wendu(0x8c,C);
write_wendu(0x80+0x40,N);
write_wendu(0x81+0x40,O);
write_wendu(0x82+0x40,.);
write_wendu(0x84+0x40,:);
write_wendu(0x89+0x40,.);
write_wendu(0x8b+0x40,0xdf);
write_wendu(0x8c+0x40,C);
}
void
{
uint
w1
w2
w3
w4
if(z==1)
{
}
if(z==2)
{
addr=0x40;
write_com(0x80+0x40+3);
write_date(0x30+2);
}
if(tflag==0)
write_wendu(0x80+addr+5,0x20);
else
write_wendu(0x80+addr+5,0x2d);
if(w1==0)
{
write_wendu(0x80+addr+6,0x20);//百位為0,不顯示
if((w1==0)&&(w2==0))
write_wendu(0x80+addr+7,0x20);
else
write_wendu(0x80+addr+7,0x30+w2);
write_wendu(0x80+addr+8,0x30+w3);
}
else
{
write_wendu(0x80+addr+6,0x30+w1);
write_wendu(0x80+addr+10,0x30+w4);
}
}
//************************************************
void
{
while(1)
{
init_1602wendu();
tempchange(1);
display_wendu(1);
tempchange(2);
display_wendu(2);
}
}
評(píng)論