DS18b20是热敏电阻吗

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/23 21:15:13
DS18b20是热敏电阻吗
xU[OA~1)F[(lF#d&u!V+؄j.P=Ѡ*^1vv'3;.o}83߷߹LXXJmV4scmW8(;Ē2laTQ!H*jBB7:r]7deoY{_8x߆ {mTpMҼ1,}2ajRcS7sF_ ;2*CR ^Op,va#Ȳ,ڰ  VKڤ~A%T@bH4Ud :n*2aL |VpPTEVc}cE(Tr|uW4XR9a`a\Ԓqa!1aYu%}㭭60mOː #bͯ{'$Q6Fa0R\He, z5w#|?0[8C.(%Zr'9;ehL U}KqŒMMIk9Os)UMyAҞsНW<ү~.im<{Jȥ"LգjJ6[_C| 7B EE4cD7F_$s1*Q0w_shjxCWUHW>~5)~E,C.F\KlbLTI |

DS18b20是热敏电阻吗
DS18b20是热敏电阻吗

DS18b20是热敏电阻吗
#include
#include
#define uint unsigned int
#define uchar unsigned char
sbit D=P3^5;
sbit LED_EN_PORT = P2^5;
sbit DAC_ADC_EN_PORT = P3^7;/*定义发光二极管及ADC、DAC、时钟的锁存器有效脚LE*/
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //段选
uchar code able[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
uint temp ;
void delay (uint z);
void init_ds18b20(void);
ReadOneChar();
WriteOneChar(uchar dat);
ReadTemperature(void);
void delay(unsigned int z)
{
while(z--);
}
void init_ds18b20(void) //初始化
{ unsigned char x=0;
D = 1; //DQ复位
delay(8); //稍做延时
D = 0; //单片机将DQ拉低
delay(80); //精确延时 大于 480us
D = 1; //拉高总线
delay(14);
x=D; //稍做延时后 如果x=0则初始化成功 x=1则初始化失败
delay(20);
}
ReadOneChar()
{
unsigned char i=0;
unsigned char dat = 0;
for (i=8;i>0;i--){
D = 0; // 给脉冲信号
dat>>=1;
D = 1; // 给脉冲信号
if(D) dat|=0x80;
delay(4);
}
return(dat);
}
WriteOneChar(uchar dat)
{
unsigned char i=0;
for (i=8; i>0; i--){
D = 0;
D = dat&0x01;
delay(5);
D = 1;
dat>>=1;
}
}
ReadTemperature(void)
{
unsigned char a=0;
unsigned char b=0;
unsigned int t=0;
float tt=0;
init_ds18b20();
WriteOneChar(0xCC); // 跳过读序号列号的操作
WriteOneChar(0x44); // 启动温度转换
init_ds18b20();
WriteOneChar(0xCC); //跳过读序号列号的操作
WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器) 前两个就是温度
a=ReadOneChar();
b=ReadOneChar();
t=b;
t