找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4749|回复: 5
收起左侧

protues仿真DS18b20温度显示失败,一直显示0,请各位帮忙看看(程序与仿真见附件)?

[复制链接]
ID:319568 发表于 2019-12-24 20:21 | 显示全部楼层 |阅读模式
//Ds18b20初始化,
bit Ds18b20Init()
{
  bit i;
  DSPORT=1;
  _nop_();  
  DSPORT=0;//拉低总线
  Delaylms(500); //拉低500秒,拉低480秒~960秒即可
  DSPORT=1;//释放总线
  Delaylms(68);//延时68秒。等待DS18b20响应
  i=DSPORT;
  Delaylms(150);
  DSPORT=1;
  _nop_();
  return (i);
}
//写函数
void Ds18b20WriteByte(uchar dat)
{
        uchar i,j;
        for(i=0;j<8;j++)
        {
                DSPORT=0;
                Delaylms(1); //延时1us
                DSPORT=dat&0x01;
                Delaylms(77);//延时77us
                DSPORT=1;
                _nop_();
                dat>>=1;
        }
}
//读函数
uchar Ds18b20ReadByte()
{
        uint i,j;
        uchar bi,byte;
        for(i=8;j>0;j--)
        {
                DSPORT=0;
                i++;
                DSPORT=1;
                i++;
                i++;
                bi=DSPORT;
                Delaylms(77);
                DSPORT=1;
                _nop_();
                byte=(byte>>1)|(bi<<7);       
        }
        return byte;
}

//温度转换指令
void Ds18b20Changetemp()
{
        Ds18b20Init();
        Delaylms(1);
        Ds18b20WriteByte(0xcc);
        Ds18b20WriteByte(0x44);                       
}
//温度读取指令
void Ds18b20ReadTempcom()
{
        Ds18b20Init();
        Delaylms(1);
        Ds18b20WriteByte(0xcc);
        Ds18b20WriteByte(0xbe);//读取RAM
}
//读取温度数据
int Ds18b20ReadTemp()
{
        int temp=0;
        uchar tmh,tml;
        Ds18b20Changetemp();
        Ds18b20ReadTempcom();
        tml= Ds18b20ReadByte();
        tmh= Ds18b20ReadByte();
        temp=tmh;
        temp<<=8;
        temp|=tml;
        return temp;               
}


捕获.PNG

程序和仿真.zip

143.48 KB, 下载次数: 34

回复

使用道具 举报

ID:213173 发表于 2019-12-24 22:58 | 显示全部楼层
无标题.jpg
给你改好了
DS18b20+仿真.zip (107.65 KB, 下载次数: 231)
回复

使用道具 举报

ID:420055 发表于 2019-12-25 09:30 | 显示全部楼层
你这个晶振多大的
回复

使用道具 举报

ID:319568 发表于 2019-12-26 17:00 | 显示全部楼层
小黎 发表于 2019-12-25 09:30
你这个晶振多大的

11.0925的,我的延时好像写错了,上次发的程序延时是错的,但我改了之后还是不显示,我去看看一楼给我改好的
回复

使用道具 举报

ID:319568 发表于 2019-12-26 18:39 | 显示全部楼层

谢谢你,我去看看
回复

使用道具 举报

ID:1075970 发表于 2023-5-27 01:09 | 显示全部楼层

改时延了?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表