求一个ds18b20数字温度测量的C程序
来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/08/04 11:36:03
求一个ds18b20数字温度测量的C程序
程序比较简单,电路图已上传.P0作为段选,P2位选,希望能得到完整的程序,包括:ds18b20初始化,读字节,写字节,读温度,温度处理,和温度的4位数码管显示,
程序比较简单,电路图已上传.P0作为段选,P2位选,希望能得到完整的程序,包括:ds18b20初始化,读字节,写字节,读温度,温度处理,和温度的4位数码管显示,
#include"reg51.h"
#include"intrins.h"
unsigned char templ=0;
unsigned char temph=0;
unsigned char tempdot=0;
bit fuhao_flag=0;
float temperature=0;
unsigned char t=0;
unsigned char tab[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};
unsigned char ledbitpos=0;
sbit dq=P1^0;
sbit num_shiwei=P2^5;
sbit num_gewei=P2^4;
sbit fuhaowei=P2^3;
sbit shiwei=P2^2;
sbit gewei=P2^1;
sbit dot=P2^0;
void Delay5us(unsigned char n)
{
unsigned char i;
i=n;
do
{
_nop_();_nop_();_nop_();
i--;
}
while(i);
return;
}
void Delay5ms(unsigned char n)
{
unsigned char i;
i=n;
do
{
Delay5us(200);
Delay5us(200);
Delay5us(200);
Delay5us(200);
Delay5us(200);
i--;
}
while(i);
}
bit init_ds18b20(void)
{
bit bresult=0;
EA=0;
dq=1;
Delay5us(8);
dq=0;
Delay5us(90);
dq=1;
Delay5us(6);
bresult=dq;
Delay5us(20);
EA=1;
return bresult;
}
bit readbit()
{
bit b;
dq=0;
_nop_();
_nop_();
_nop_();
_nop_();
dq=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
b=dq;
Delay5us(4);
return b;
}
unsigned char readonechar(void)
{
unsigned char i=0;
unsigned char dat=0;
EA=0;
for(i=8;i>0;i--)
{
dat=_cror_(dat,1);
if(readbit())
dat|=0x80;
else
dat|=0x00;
}
EA=1;
return dat;
}
void writebit(bit dq1)
{
unsigned char j;
if(!dq1)
{
dq=0;
for(j=35;j>0;j--);
dq=1;
}
else
{
dq=0;
for(j=2;j>0;j--);
dq=1;
for(j=33;j>0;j--);
}
}
void writeonechar(unsigned char command)
{
unsigned char i;
EA=0;
for(i=0;i>4;
tempdot=(10*(templ & 0x0f))/16;
templ=templ>>4;
t=temph
#include"intrins.h"
unsigned char templ=0;
unsigned char temph=0;
unsigned char tempdot=0;
bit fuhao_flag=0;
float temperature=0;
unsigned char t=0;
unsigned char tab[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};
unsigned char ledbitpos=0;
sbit dq=P1^0;
sbit num_shiwei=P2^5;
sbit num_gewei=P2^4;
sbit fuhaowei=P2^3;
sbit shiwei=P2^2;
sbit gewei=P2^1;
sbit dot=P2^0;
void Delay5us(unsigned char n)
{
unsigned char i;
i=n;
do
{
_nop_();_nop_();_nop_();
i--;
}
while(i);
return;
}
void Delay5ms(unsigned char n)
{
unsigned char i;
i=n;
do
{
Delay5us(200);
Delay5us(200);
Delay5us(200);
Delay5us(200);
Delay5us(200);
i--;
}
while(i);
}
bit init_ds18b20(void)
{
bit bresult=0;
EA=0;
dq=1;
Delay5us(8);
dq=0;
Delay5us(90);
dq=1;
Delay5us(6);
bresult=dq;
Delay5us(20);
EA=1;
return bresult;
}
bit readbit()
{
bit b;
dq=0;
_nop_();
_nop_();
_nop_();
_nop_();
dq=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
b=dq;
Delay5us(4);
return b;
}
unsigned char readonechar(void)
{
unsigned char i=0;
unsigned char dat=0;
EA=0;
for(i=8;i>0;i--)
{
dat=_cror_(dat,1);
if(readbit())
dat|=0x80;
else
dat|=0x00;
}
EA=1;
return dat;
}
void writebit(bit dq1)
{
unsigned char j;
if(!dq1)
{
dq=0;
for(j=35;j>0;j--);
dq=1;
}
else
{
dq=0;
for(j=2;j>0;j--);
dq=1;
for(j=33;j>0;j--);
}
}
void writeonechar(unsigned char command)
{
unsigned char i;
EA=0;
for(i=0;i>4;
tempdot=(10*(templ & 0x0f))/16;
templ=templ>>4;
t=temph
求一个ds18b20数字温度测量的C程序
数字温度传感器DS18B20是怎么实现温度补偿的?
在运行数字温度计仿真(proteus)时,怎样初始化温度? 为什么只显示0,我的DS18B20读取温度程序应该没问题
用LCD1602和DS18B20显示温度和时间C语言程序
DS18B20温度显示的问题
关于ds18b20的温度补偿
ds18b20温度是几位的呀
ds18b20初始化程序,最后一个return
用DS18b20写温度程序!并用1602显示!我想加多一个功能!当温度超过某一直!就报警!怎么写这段程序呀?
C语言编写程序 求一个整数各位数字之和.
ds18b20温度传感器测量油料温度,怎么样保证油库安全?
c语言程序题 求输入的一个无符号整数各位数字之积.