求大神帮我看下程序!一直困扰了我几天。
//18b20操作
void delay1 (unsigned char q)
{
while(q--)
for(i=0;i<5;i++)
_nop_();
}
void init_18b20()
{unsigned char x=0;
dp=1;
delay1(1); //dp为
通信总线
dp=0;
delay1(140);
dp=1;
delay1(13);
x=dp;
delay1(87);
dp=1;
}
void write_18b20( char d)
{unsigned char i=0;
for(i=0;i<8;i++)
{dp=1;
delay1(1);
dp=0;
//delay1(1);
dp=d&0x01;
delay1(12);
dp=1;
d>>=1;
}
}
unsigned char read_18b20()
{unsigned char i=0;
unsigned char d=0;
for(i+0;i<8;i++)
{
dp=0;
d >>= 1;
dp = 1;
delay1(1);
if(dp)
d|=0x80;
delay1(13);
dp=1;
}
return(d);
}
void read_temp()
{
unsigned char low;
unsigned char high;
c=0;
init_18b20();
write_18b20(0xcc);
write_18b20(0x44);
init_18b20();
write_18b20(0xcc);
write_18b20(0xbe);
low=read_18b20();
high=read_18b20();
tem=high;
tem<<=8;
tem=tem|low; //tem为long型
if(tem%32==0x1f)
{value=~(tem/32)+1; //value为float型
c=value*0.0625; //c为int型
}
else
value=tem/32;
c=value*0.0625;
}
void display()
{
read_temp();
wei[0]=c/100; //百位
wei[1]=c%100/10; //十位
wei[2]=c%100%10; //个位
//wei[4]=c%100%10%10; //小数位
write_command(0x80+0x40+0x07);
write_data(wei[0]+0x30);
write_command(0x80+0x40+0x08);
for(i=1;i<3;i++)
{write_data(wei
+0x30);
}
write_command(0x80+0x40+0x0a);
write_data(wei[10]);
write_data(wei[2]+0x30);
}
改变温度一直这样
此话怎么讲 是楼主注释的少吗
一周热门 更多>