普中开源电子分享网

 找回密码
 立即注册
搜索
查看: 3565|回复: 1

DS18B20

 关闭 [复制链接]

2

主题

4

帖子

18

积分

新手上路

Rank: 1

积分
18
发表于 2017-4-26 21:04:18 | 显示全部楼层 |阅读模式
我是看了许多次单片机视频后,自己写程序,下面是我自己都芯片手册的疑惑。在读时序中,数据手册上有这样一句:A read time slot is initiated by the master device pulling the 1-Wire bus low for a minimum of 1μs and then releasing the bus 。
        for(j=8; j>0; j--)
        {
                DSPORT = 0;
                i++;
                DSPORT = 1;
                i++;
                i++
                bi = DSPORT;
       
                byte = (byte >> 1) | (bi << 7);                                                  
                i = 4;       
                while(i--);
        }                               

在写时序中,数据手册上有这样一句:To generate a Write 1 time slot, after pulling the 1-Wire bus low, the bus master must release the 1-Wire bus within 15μs.  

        for(j=0; j<8; j++)
        {
               DSPORT = 0;             
                i++;
                DSPORT = dat & 0x01;
                i=6;
                while(i--)
                DSPORT = 1;
                dat >>= 1;
        }

按着我的理解是:在写时序的时候先DSPORT = 0;接着DSPORT = 1; 我的理由一个是数据手册要求释放总线,(应该就是拉高吧),第二个理由感觉写时序的说法和读时序一样,所以写的顺序应该一样啊。
如果是完全按着时序图来,写时序可以解释的通,但是读时序又有问题,感觉在DSPORT = 0;就不必紧跟着DSPORT = 1;

!!!!!!!!不要忽悠,谢谢!!!!!!!!!!!!!!!






[color=rgba(0, 0, 0, 0.541176)]122/5000






回复

使用道具 举报

2

主题

4

帖子

18

积分

新手上路

Rank: 1

积分
18
 楼主| 发表于 2017-4-28 18:48:14 | 显示全部楼层
为了说清楚,在补充一下啊,我的理解 是写时序 先DSPORT = 0  然后必须接着写DSPORT = 1; 但是这样写是不对的,如果只看时序图的话,知道这样写,但是读时序感觉就不应该在DSPORT = 0;  后面马上写DSPORT = 1;
回复 支持 反对

使用道具 举报

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

本版积分规则

关闭

站长推荐上一条 /1 下一条

Archiver|手机版|小黑屋|普中开源电子分享网 粤ICP备16123577号-2

GMT+8, 2024-4-26 14:52 , Processed in 0.432949 second(s), 30 queries .

Powered by 论坛搭建 X3.4

Copyright © 2001-2021, Tencent Cloud.

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