请教ds18b20 点击:22383 | 回复:415



gongkongedit

    
  • 精华:1099帖
  • 求助:0帖
  • 帖子:14392帖 | 54470回
  • 年度积分:0
  • 历史总积分:622
  • 注册:2008年9月08日
发表于:2004-02-26 09:29:00
楼主
我正在做ds18b20的多点测量实验,但是输出的温度有时正确有时错误(为85度),不知道是什么原因?另外我采用外接电源的方法,没有mos强的上拉,不知道会不会有影响?



华安4

  • 精华:1帖
  • 求助:0帖
  • 帖子:15帖 | 99回
  • 年度积分:0
  • 历史总积分:160
  • 注册:2006年11月30日
发表于:2007-08-16 16:46:00
381楼
一根线上挂了3个18B20,然后在数据线和GND之间挂BAT85和100的电阻。在线路中起起什么作用丫。请教强人

swsnycb

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 1回
  • 年度积分:0
  • 历史总积分:1
  • 注册:2007年8月31日
发表于:2007-08-31 01:52:00
382楼
哪们朋友可以告诉我18b20的序列号是怎么读出来的。
我的邮箱:xywanysy@163.com

华安4

  • 精华:1帖
  • 求助:0帖
  • 帖子:15帖 | 99回
  • 年度积分:0
  • 历史总积分:160
  • 注册:2006年11月30日
发表于:2007-08-31 17:23:00
383楼
自己慢慢试验。按照说明手册上着

yinxiaojing

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 3回
  • 年度积分:0
  • 历史总积分:3
  • 注册:2007年7月05日
发表于:2007-09-20 22:30:00
384楼
为什么我读出来的问题,在35度之前还是在增加的,但是随着温度的上升,温度传感器的值固定的35度不变了呢?我没有设置过其他的阿?

浅醉闲眠

  • [版主]
  • 精华:3帖
  • 求助:3帖
  • 帖子:218帖 | 13148回
  • 年度积分:152
  • 历史总积分:116149
  • 注册:2002年6月21日
发表于:2007-09-27 16:29:00
385楼
这个帖子很好!

wendi_fwy

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 1回
  • 年度积分:0
  • 历史总积分:1
  • 注册:2007年11月29日
发表于:2007-11-29 10:19:00
386楼
digi,你好
我想问个问题,我用51单片机的4个I/O引脚去控制两组DS18B20,外部供电,每组挂9个DS18B20,可看了资料老是分不清流程应该怎么走,我看了资料上的一个存储器操作,感觉不适合我的方案,你帮我看下
复位--存在--发55h--发64位ROM编码--发44h--IO线高电平--复位--存在--发55h--发64位ROM编码--发BEh--接收9个数据字节--复位--存在

不知道这样的流程对不对?恳请回答一下,万分感谢

digi

  • 精华:19帖
  • 求助:0帖
  • 帖子:52帖 | 797回
  • 年度积分:0
  • 历史总积分:1171
  • 注册:2001年9月19日
发表于:2007-12-03 16:14:00
387楼
不好意思,我不熟悉18B20的多点测量

梦游雨中

  • 精华:0帖
  • 求助:0帖
  • 帖子:2帖 | 176回
  • 年度积分:0
  • 历史总积分:474
  • 注册:2007年10月27日
发表于:2007-12-03 16:22:00
388楼
学习拉`!辛苦

我的阿

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 1回
  • 年度积分:0
  • 历史总积分:1
  • 注册:2007年12月09日
发表于:2007-12-09 13:56:00
389楼
搂住你能给我发一个DS1820利用74LS244来驱动的程序吗,或许一个单原的也可以,我自己走了一个,可是结果总是不对阿

华安4

  • 精华:1帖
  • 求助:0帖
  • 帖子:15帖 | 99回
  • 年度积分:0
  • 历史总积分:160
  • 注册:2006年11月30日
发表于:2008-01-04 10:28:00
390楼
zui hao yong 74ls245

sman忘记花香

  • 精华:0帖
  • 求助:0帖
  • 帖子:1帖 | 3回
  • 年度积分:0
  • 历史总积分:6
  • 注册:2008年1月13日
发表于:2008-01-13 13:01:00
391楼
我用汇编写了一段程序来读1820的序列号,用示波器来看数据线上的波形.在下拉300us后释放总线,过了15us1820响应复位信号,将总线下拉200us.之后程序延时300us发送读取rom的"33h"指令.指令时序为0(15us)1(80us)0(15us)1(80us)0(80us)1(15us)0(80us)1(15us)0(15us)1(80us)0(15us)1(80us)0(15us)0(80us)1(15us)0(80us)1(15us),各位可以按照0和1的时间长短画出时序图,但是此时1820没有任何响应,请问是怎么回事?盼望有经验者给出解答!

sman忘记花香

  • 精华:0帖
  • 求助:0帖
  • 帖子:1帖 | 3回
  • 年度积分:0
  • 历史总积分:6
  • 注册:2008年1月13日
发表于:2008-01-16 11:40:00
392楼
顶一下,盼有大侠回复

坤弟

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 25回
  • 年度积分:0
  • 历史总积分:140
  • 注册:2006年5月27日
发表于:2008-01-22 23:52:00
393楼
 
谢鸣:
  给你一段我用过的程序,89C51单片机,12MHZ晶振,程序正常.
  请注意,发送33H后,短暂延时后读取就是了. 
  getmp:setb dq
bcd:  acall b20rst
      jb flag1,s22
      mov d2,#4
      setb flag2
      ret
s22:  clr flag1
      acall delay1
      MOV A,#33H         ;发送读取ROM码命令
      ACALL WRITE        ;写入
      acall delay1       ;延时
      acall read0        ;读取返回的ROM码
      ret
WRITE:    MOV R2,#8
          CLR C
WR1:      CLR DQ
          MOV R3,#6
          DJNZ R3,$
          RRC A
          MOV DQ,C
          MOV R3,#23
          DJNZ R3,$
          SETB DQ
          NOP
          DJNZ R2,WR1
          SETB DQ
          RET
   READ0: mov r4,#9
          mov r1,#36h
   read1: MOV R2,#8
   READL: CLR C
          SETB DQ
          NOP
          NOP
          CLR DQ
          NOP
          NOP
          NOP
          SETB DQ
          MOV R3,#7
          DJNZ R3,$
          MOV C,DQ
          MOV R3,#23
          DJNZ R3,$
          RRC A
          DJNZ R2,READL
          mov @r1,a
          inc r1
          djnz r4,read1
          RET

坤弟

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 25回
  • 年度积分:0
  • 历史总积分:140
  • 注册:2006年5月27日
发表于:2008-01-22 23:54:00
394楼
 
谢鸣:
  给你一段我用过的程序,89C51单片机,12MHZ晶振,程序正常.
  请注意,发送33H后,短暂延时后读取就是了. 
  getmp:setb dq
bcd:  acall b20rst
      jb flag1,s22
      mov d2,#4
      setb flag2
      ret
s22:  clr flag1
      acall delay1
      MOV A,#33H         ;发送读取ROM码命令
      ACALL WRITE        ;写入
      acall delay1       ;延时
      acall read0        ;读取返回的ROM码
      ret
WRITE:    MOV R2,#8
          CLR C
WR1:      CLR DQ
          MOV R3,#6
          DJNZ R3,$
          RRC A
          MOV DQ,C
          MOV R3,#23
          DJNZ R3,$
          SETB DQ
          NOP
          DJNZ R2,WR1
          SETB DQ
          RET
   READ0: mov r4,#9
          mov r1,#36h
   read1: MOV R2,#8
   READL: CLR C
          SETB DQ
          NOP
          NOP
          CLR DQ
          NOP
          NOP
          NOP
          SETB DQ
          MOV R3,#7
          DJNZ R3,$
          MOV C,DQ
          MOV R3,#23
          DJNZ R3,$
          RRC A
          DJNZ R2,READL
          mov @r1,a
          inc r1
          djnz r4,read1
          RET

坤弟

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 25回
  • 年度积分:0
  • 历史总积分:140
  • 注册:2006年5月27日
发表于:2008-01-23 00:09:00
395楼
 wendi_fwy:
  正确的流程应是复位-存在-发CCH-发44H-延时0.75秒以上-复位-存在-发55H-发送64位ROM码-发送0BEH-读取.我有完整的程序,经过实际运行一年以上.

digi

  • 精华:19帖
  • 求助:0帖
  • 帖子:52帖 | 797回
  • 年度积分:0
  • 历史总积分:1171
  • 注册:2001年9月19日
发表于:2008-01-24 15:23:00
396楼
顺便提示一下,读写过程不要有中断,容易死机;显示、通讯等操作可以留到延时750ms这个时序去做

huaqiuzhang

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 2回
  • 年度积分:0
  • 历史总积分:2
  • 注册:2005年4月03日
发表于:2008-01-24 18:45:00
397楼
我用的是DS18S20Z,独立3.3V供电,使用CPLD作为主控制器。现在序列号和温度能够读出,且校验都通过,只是温度明显比环境温度高出太多。譬如:环境温度5度,测到的温度确是72度;使用取暖器加热芯片,测到的温度随环境温度上升,大概到40度左右时,测到的温度为0x00FF。请各位大拿帮忙分析一下,谢谢!

huaqiuzhang

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 2回
  • 年度积分:0
  • 历史总积分:2
  • 注册:2005年4月03日
发表于:2008-01-24 18:50:00
398楼
程序如下:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity oneWireController is
port
(
rst,clk : in std_logic;

oneWireDQ : inout std_logic;

oneWireLaseredRomCode : out std_logic_vector(63 downto 0);
oneWireLaseredRomCodeEn : out std_logic;

oneWireScratchPadData : out std_logic_vector(63 downto 0);
oneWireScratchPadDataEn : out std_logic;
TestPoint : out std_logic
);
end oneWireController;

architecture behave of oneWireController is
constant oneWireCmdSeachROM : std_logic_vector(7 downto 0) := "11110000";
constant oneWireCmdReadROM : std_logic_vector(7 downto 0) := "00110011";
constant oneWireCmdMatchROM : std_logic_vector(7 downto 0) := "01010101";
constant oneWireCmdSkipROM : std_logic_vector(7 downto 0) := "11001100";
constant oneWireCmdAlarmSearch : std_logic_vector(7 downto 0) := "11101100";

constant oneWireCmdConvertT : std_logic_vector(7 downto 0) := "01000100";
constant oneWireCmdWriteScratchPad : std_logic_vector(7 downto 0) := "01001110";
constant oneWireCmdReadScratchPad : std_logic_vector(7 downto 0) := "10111110";
constant oneWireCmdCopyScratchPad : std_logic_vector(7 downto 0) := "01001000";
constant oneWireCmdRecallEEPROM : std_logic_vector(7 downto 0) := "10111000";
constant oneWireCmdReadPowerSupply : std_logic_vector(7 downto 0) := "10110100";


constant oneWireCommandLength : std_logic_vector(5 downto 0) := "000111";
constant oneWireRomLength : std_logic_vector(5 downto 0) := "111111";
constant oneWireRomDataLength : std_logic_vector(5 downto 0) := "110111";
constant oneWireRomCrcLength : std_logic_vector(5 downto 0) := "000111";
constant oneWireWriteScratchPadLength : std_logic_vector(5 downto 0) := "001111";
constant oneWireScratchPadDataLength : std_logic_vector(5 downto 0) := "111111";
constant oneWireScratchPadCrcLength : std_logic_vector(5 downto 0) := "000111";

constant oneWireResetT : std_logic_vector(15 downto 0) := "0001001100000000";--"0000000000001000";--486.4us
constant oneWirePresenceWaitTmin : std_logic_vector(15 downto 0) := "0000000010010110";--"0000000000001000";--15us
constant oneWirePresenceWaitTmax : std_logic_vector(15 downto 0) := "0000001001011000";--"0000000000010000";--60us
constant oneWirePresencePulseTmin : std_logic_vector(15 downto 0) := "0000001001011000";--"0000000000001000";--60us
constant oneWirePresencePulseTmax : std_logic_vector(15 downto 0) := "0000100101100000";--"0000000000010000";--240us
constant oneWirePresenceT : std_logic_vector(15 downto 0) := "0001001100000000";--"0000000000110000";--486.4us
constant oneWireRWnIntT : std_logic_vector(15 downto 0) := "0000000000010000";--"0000000000001000";--1.6us
constant oneWireRWnSampleT : std_logic_vector(15 downto 0) := "0000000010001100";--"0000000000001000";--14us
constant oneWireRWnSlotT : std_logic_vector(15 downto 0) := "0000001010000000";--"0000000000001000";--64us
constant oneWireRWnRecT : std_logic_vector(15 downto 0) := "0000000000100000";--"0000000000001000";--3.2us

constant oneWireConvertTT : std_logic_vector(23 downto 0) := "100110001001011010000000";--"000111101000010010000000";--"011100100111000011100000";

constant oneWireTh : std_logic_vector(7 downto 0) := "01111101"; -- +125
constant oneWireTl : std_logic_vector(7 downto 0) := "11001001"; -- -55
constant oneWireConf : std_logic_vector(7 downto 0) := "00011111";

constant IdleStatus : std_logic_vector(5 downto 0) := "000000";
constant ResetStatus : std_logic_vector(5 downto 0) := "000001";
constant WriteStatus : std_logic_vector(5 downto 0) := "010000";
constant ReadStatus : std_logic_vector(5 downto 0) := "100000";
constant CrcStatus : std_logic_vector(5 downto 0) := "110000";

signal BasicFuncStatus : std_logic_vector(5 downto 0);
signal BasicFuncCmd : std_logic_vector(3 downto 0);
signal BasicTimingCNT : std_logic_vector(15 downto 0);
signal BasicFuncBitNum : std_logic_vector(5 downto 0);
signal BasicFuncOpNum : std_logic_vector(5 downto 0);
signal BasicFuncBufferIn : std_logic_vector(63 downto 0);
signal BasicFuncBufferOut : std_logic_vector(63 downto 0);
signal BasicFuncBuffer : std_logic_vector(63 downto 0);
signal BasicFuncEnd : std_logic;

signal oneWireRom : std_logic_vector(63 downto 0);
signal ScratchPadData : std_logic_vector(63 downto 0);
signal ScratchPadCRC : std_logic_vector(7 downto 0);

signal MainStatus : std_logic_vector(5 downto 0);

signal oneWireConvertWaitTimeCNT : std_logic_vector(25 downto 0);

signal oneWireDQ_RWn : std_logic;
signal oneWireDQ_IN : std_logic;
signal oneWireDQ_OUT : std_logic;

signal CRC_Reg : std_logic_vector(7 downto 0);
signal CRC_RegMSB : std_logic;
begin
--Main Process
process(rst,clk)
begin
if rst = '1' then
MainStatus <= (others => '0');
BasicFuncCmd <= "0000";
oneWireLaseredRomCodeEn <= '0';
TestPoint <= '0';
elsif rising_edge(clk) then
case MainStatus is
--Reset
when "000000" =>
MainStatus <= "000001";
BasicFuncCmd <= "0001";
when "000001" =>
if BasicFuncEnd = '1' then
MainStatus <= "000010";
end if;
BasicFuncCmd <= "0000";
when "000010" =>
if BasicFuncEnd = '0' then
MainStatus <= "000011";
end if;

--Read ROM
---Send read rom command
when "000011" =>
MainStatus <= "000100";
BasicFuncBitNum <= oneWireCommandLength;
BasicFuncBufferIn(7 downto 0) <= oneWireCmdReadROM;
BasicFuncCmd <= "0010";
when "000100" =>
if BasicFuncEnd = '1' then
MainStatus <= "000101";
end if;
BasicFuncCmd <= "0000";
when "000101" =>
if BasicFuncEnd = '0' then
MainStatus <= "000110";
end if;

---Read ROM Content
when "000110" =>
MainStatus <= "000111";
BasicFuncBitNum <= oneWireRomLength;
BasicFuncCmd <= "0100";
when "000111" =>
if BasicFuncEnd = '1' then
MainStatus <= "001000";
end if;
BasicFuncCmd <= "0000";
when "001000" =>
if BasicFuncEnd = '0' then
MainStatus <= "001001";
oneWireRom <= BasicFuncBufferOut;
end if;
when "001001" =>
if oneWireRom(7 downto 0) = "00010000" then
MainStatus <= "001010";
else
MainStatus <= "000000";
end if;
---CRC ROM
when "001010" =>
MainStatus <= "001011";
BasicFuncBitNum <= oneWireRomDataLength;
BasicFuncBufferIn <= oneWireRom;
BasicFuncCmd <= "1000";
when "001011" =>
if BasicFuncEnd = '1' then
MainStatus <= "001100";
end if;
BasicFuncCmd <= "0000";
when "001100" =>
if BasicFuncEnd = '0' then
MainStatus <= "001101";
end if;
when "001101" =>
if BasicFuncBufferOut(7 downto 0) = oneWireRom(63 downto 56) then
MainStatus <= "001110";
-- MainStatus <= "010100"; --Goto Loop
oneWireLaseredRomCode <= oneWireRom;
oneWireLaseredRomCodeEn <= '1';
else
MainStatus <= "000000";
oneWireLaseredRomCodeEn <= '0';
end if;

--Write Scratch PAD
---Send Write Scratch PAD Command
when "001110" =>
MainStatus <= "001111";
BasicFuncBitNum <= oneWireCommandLength;
BasicFuncBufferIn(7 downto 0) <= oneWireCmdWriteScratchPad;
BasicFuncCmd <= "0010";
when "001111" =>
if BasicFuncEnd = '1' then
MainStatus <= "010000";
end if;
BasicFuncCmd <= "0000";
when "010000" =>
if BasicFuncEnd = '0' then
MainStatus <= "010001";
end if;
---Write Scratch Pad-----Th = 55;Tl = -10;
when "010001" =>
MainStatus <= "010010";
BasicFuncBitNum <= oneWireWriteScratchPadLength;
BasicFuncBufferIn(23 downto 0) <= oneWireConf & oneWireTl & oneWireTh;
BasicFuncCmd <= "0010";
when "010010" =>
if BasicFuncEnd = '1' then
MainStatus <= "010011";
end if;
BasicFuncCmd <= "0000";
when "010011" =>
if BasicFuncEnd = '0' then
MainStatus <= "010100";
end if;


--Loop

--Reset
when "010100" =>
MainStatus <= "010101";
BasicFuncCmd <= "0001";
when "010101" =>
if BasicFuncEnd = '1' then
MainStatus <= "010110";
end if;
BasicFuncCmd <= "0000";
when "010110" =>
if BasicFuncEnd = '0' then
MainStatus <= "010111";
end if;

--Match ROM Command
---Send Match ROM Command
-----Send Skip Rom Command
when "010111" =>
MainStatus <= "011000";
BasicFuncBitNum <= oneWireCommandLength;
-- BasicFuncBufferIn(7 downto 0) <= oneWireCmdMatchROM;
BasicFuncBufferIn(7 downto 0) <= oneWireCmdSkipROM;
BasicFuncCmd <= "0010";
when "011000" =>
if BasicFuncEnd = '1' then
MainStatus <= "011001";
end if;
BasicFuncCmd <= "0000";
when "011001" =>
if BasicFuncEnd = '0' then
MainStatus <= "011010";
end if;
when "011010" =>
-- MainStatus <= "011011";
MainStatus <= "011110"; --Goto Convert T

---Send ROM Content
when "011011" =>
MainStatus <= "011100";
BasicFuncBitNum <= oneWireRomLength;
BasicFuncBufferIn <= oneWireROM;
BasicFuncCmd <= "0010";
when "011100" =>
if BasicFuncEnd = '1' then
MainStatus <= "011101";
end if;
BasicFuncCmd <= "0000";
when "011101" =>
if BasicFuncEnd = '0' then
MainStatus <= "011110";
end if;
--Convert T Command
---Send Convert T Command
when "011110" =>
MainStatus <= "011111";
BasicFuncBitNum <= oneWireCommandLength;
BasicFuncBufferIn(7 downto 0) <= oneWireCmdConvertT;
BasicFuncCmd <= "0010";
when "011111" =>
if BasicFuncEnd = '1' then
MainStatus <= "100000";
end if;
BasicFuncCmd <= "0000";
when "100000" =>
if BasicFuncEnd = '0' then
MainStatus <= "100001";
end if;
oneWireConvertWaitTimeCNT <= (others => '0');

---Wait for 800ms for AD Convert

---Exam Convert's End 
when "100001" =>
-- if oneWireConvertWaitTimeCNT(25) = '1' then--oneWireConvertTT then
MainStatus <= "100010";--"100101";
BasicFuncBitNum <= "000000";
BasicFuncCmd <= "0100";
-- else
-- oneWireConvertWaitTimeCNT <= oneWireConvertWaitTimeCNT + "00000000000000000000000001";
-- end if;
when "100010" =>
if BasicFuncEnd = '1' then
MainStatus <= "100011";
end if;
BasicFuncCmd <= "0000";
when "100011" =>
if BasicFuncEnd = '0' then
MainStatus <= "100100";
oneWireRom <= BasicFuncBufferOut;
end if;
when "100100" =>
if BasicFuncBufferOut(63) = '1' then
MainStatus <= "100101";
else
MainStatus <= "100001";

end if;

--Reset
when "100101" =>
MainStatus <= "100110";
BasicFuncCmd <= "0001";
when "100110" =>
if BasicFuncEnd = '1' then
MainStatus <= "100111";
end if;
BasicFuncCmd <= "0000";
when "100111" =>
if BasicFuncEnd = '0' then
MainStatus <= "101000";
end if;

--Match ROM Command
---Send Match Rom Command
-----Send Skip Rom Command
when "101000" =>
MainStatus <= "101001";
BasicFuncBitNum <= oneWireCommandLength;
-- BasicFuncBufferIn(7 downto 0) <= oneWireCmdMatchROM;
BasicFuncBufferIn(7 downto 0) <= oneWireCmdSkipROM;
BasicFuncCmd <= "0010";
when "101001" =>
if BasicFuncEnd = '1' then
MainStatus <= "101010";
end if;
BasicFuncCmd <= "0000";
when "101010" =>
if BasicFuncEnd = '0' then
-- MainStatus <= "101011";
MainStatus <= "101111"; --Goto Read ScratchPAD 
end if;
---Send ROM Content
when "101011" =>
MainStatus <= "101100";
BasicFuncBitNum <= oneWireRomLength;
BasicFuncBufferIn <= oneWireROM;
BasicFuncCmd <= "0010";
when "101100" =>
if BasicFuncEnd = '1' then
MainStatus <= "101101";
end if;
BasicFuncCmd <= "0000";
when "101101" =>
if BasicFuncEnd = '0' then
MainStatus <= "101111";
end if;

--Read ScratchPAD Command
---Send Read ScratchPAD Command
when "101111" =>
MainStatus <= "110000";
BasicFuncBitNum <= oneWireCommandLength;
BasicFuncBufferIn(7 downto 0) <= oneWireCmdReadScratchPAD;
BasicFuncCmd <= "0010";
when "110000" =>
if BasicFuncEnd = '1' then
MainStatus <= "110001";
end if;
BasicFuncCmd <= "0000";
when "110001" =>
if BasicFuncEnd = '0' then
MainStatus <= "110010";
end if;

---Read ScratchPAD Content
when "110010" =>
MainStatus <= "110100";
BasicFuncBitNum <= oneWireScratchPadDataLength;
BasicFuncCmd <= "0100";
when "110100" =>
if BasicFuncEnd = '1' then
MainStatus <= "110101";
end if;
BasicFuncCmd <= "0000";
when "110101" =>
if BasicFuncEnd = '0' then
MainStatus <= "110110";
ScratchPadData <= BasicFuncBufferOut;
end if;

---Read ScratchPAD CRC
when "110110" =>
MainStatus <= "110111";
BasicFuncBitNum <= oneWireScratchPadCrcLength;
BasicFuncCmd <= "0100";
when "110111" =>
if BasicFuncEnd = '1' then
MainStatus <= "111000";
end if;
BasicFuncCmd <= "0000";
when "111000" =>
if BasicFuncEnd = '0' then
MainStatus <= "111001";
ScratchPadCrc <= BasicFuncBufferOut(63 downto 56);
end if;

---CRC ScratchPAD
when "111001" =>
MainStatus <= "111010";
BasicFuncBitNum <= oneWireScratchPadDataLength;
BasicFuncBufferIn <= ScratchPadData;
BasicFuncCmd <= "1000";
when "111010" =>
if BasicFuncEnd = '1' then
MainStatus <= "111011";
end if;
BasicFuncCmd <= "0000";
when "111011" =>
if BasicFuncEnd = '0' then
MainStatus <= "111100";
end if;
when "111100" =>
if BasicFuncBufferOut(7 downto 0) = ScratchPadCrc then
MainStatus <= "111101";
oneWireScratchPadDataEn <= '0';
TestPoint <= '1';
else
MainStatus <= "010100";
oneWireScratchPadDataEn <= '0';
TestPoint <= '0';
end if;
when "111101" =>
MainStatus <= "111110";
oneWireScratchPadData <= ScratchPadData;
oneWireScratchPadDataEn <= '0';
when "111110" =>
MainStatus <= "111111";
oneWireScratchPadDataEn <= '1';
--Goto Loop
when "111111" =>
MainStatus <= "010100";
oneWireScratchPadDataEn <= '0';

when others =>
end case;
end if;
end process;

--Basic Function Process
----BasicTimingCNT
----Port
------BasicFuncCmd(3 downto 0)
--------Bit0 : Reset
--------Bit1 : Write
--------Bit2 : Read
--------Bit3 : CRC
------BasicFuncBitNum(5 downto 0)
------BasicFuncBufferIn(63 downto 0)
------BasicFuncBufferOut(63 downto 0)
------BasicFuncEnd
----Work Register
--BasicFuncOpNum(5 downto 0)
--BasicFuncBuffer(63 downto 0)
process(rst,clk)
begin
if rst = '1' then
BasicFuncStatus <= (others => '0');
BasicFuncEnd <= '0';
elsif rising_edge(clk) then
case BasicFuncStatus is
when "000000" =>
if BasicFuncCmd(0) = '1' then
BasicFuncStatus <= ResetStatus;
elsif BasicFuncCmd(1) = '1' then
BasicFuncStatus <= WriteStatus;
elsif BasicFuncCmd(2) = '1' then
BasicFuncStatus <= ReadStatus;
elsif BasicFuncCmd(3) = '1' then
BasicFuncStatus <= CrcStatus;
end if;
BasicFuncEnd <= '0';

-------------------------------------------------------------------------------------------------------------------
--Reset Function
when "000001" =>
BasicFuncStatus <= "000010";
BasicTimingCNT <= (others => '0');
oneWireDQ_RWn <= '1';
when "000010" =>
BasicFuncStatus <= "000011";
BasicTimingCNT <= (others => '0');
oneWireDQ_RWn <= '0';
oneWireDQ_OUT <= '0';
when "000011" =>
if BasicTimingCNT = oneWireResetT then
BasicFuncStatus <= "000100";
oneWireDQ_RWn <= '1';
else
BasicTimingCNT <= BasicTimingCNT + "0000000000000001";
BasicFuncStatus <= "000011";
end if;
when "000100" =>
BasicFuncStatus <= "000101";
BasicTimingCNT <= (others => '0');
oneWireDQ_RWn <= '1';
---Presence
when "000101" =>
BasicFuncStatus <= "000110";
oneWireDQ_RWn <= '1';
when "000110" =>
if oneWireDQ_IN = '1' then
BasicFuncStatus <= "000111";
end if;
---wait
when "000111" =>
if oneWireDQ_IN = '1' then
if BasicTimingCNT = oneWirePresenceWaitTmin then
BasicFuncStatus <= "001000";
else
BasicTimingCNT <= BasicTimingCNT + "0000000000000001";
end if;
else
BasicFuncStatus <= ResetStatus;
end if;
when "001000" =>
if oneWireDQ_IN = '1' then
if BasicTimingCNT = oneWirePresenceWaitTmax then
BasicFuncStatus <= ResetStatus;
else
BasicTimingCNT <= BasicTimingCNT + "0000000000000001";
end if;
else
BasicFuncStatus <= "001001";
end if;
---Presence pulse
when "001001" =>
BasicFuncStatus <= "001010";
BasicTimingCNT <= (others => '0');
when "001010" =>
if oneWireDQ_IN = '0' then
if BasicTimingCNT = oneWirePresencePulseTmin then
BasicFuncStatus <= "001011";
else
BasicTimingCNT <= BasicTimingCNT + "0000000000000001";
end if;
else
BasicFuncStatus <= ResetStatus;
end if;
when "001011" =>
if oneWireDQ_IN = '0' then
if BasicTimingCNT = oneWirePresencePulseTmax then
BasicFuncStatus <= ResetStatus;
else
BasicTimingCNT <= BasicTimingCNT + "0000000000000001";
end if;
else
BasicFuncStatus <= "001100";
end if;
---wait for presence end
when "001100" =>
if oneWireDQ_IN = '1' then
if BasicTimingCNT = oneWirePresenceT then
BasicFuncStatus <= "001101";
BasicFuncEnd <= '1';
else
BasicTimingCNT <= BasicTimingCNT + "0000000000000001";
end if;
else
BasicFuncStatus <= ResetStatus;
end if;
when "001101" =>
BasicFuncStatus <= IdleStatus;
BasicFuncEnd <= '1';
BasicTimingCNT <= (others => '0');


-------------------------------------------------------------------------------------------------------------------
--Write Function
when "010000" =>
BasicFuncStatus <= "010001";
BasicTimingCNT <= (others => '0');
oneWireDQ_RWn <= '1';
BasicFuncOpNum <= BasicFuncBitNum;
BasicFuncBuffer <= BasicFuncBufferIn;
---Int
when "010001" =>
BasicFuncStatus <= "010010";
oneWireDQ_RWn <= '0';
oneWireDQ_OUT <= '0';
when "010010" =>
if BasicTimingCNT = oneWireRWnIntT then
BasicFuncStatus <= "010011";
else
BasicTimingCNT <= BasicTimingCNT + "0000000000000001";
end if;
when "010011" =>
BasicFuncStatus <= "010100";
oneWireDQ_OUT <= BasicFuncBuffer(0);
---Sample
when "010100" =>
if BasicTimingCNT = oneWireRWnSampleT then
BasicFuncStatus <= "010101";
else
BasicTimingCNT <= BasicTimingCNT + "0000000000000001";
end if;
---Wait for Slot End
when "010101" =>
if BasicTimingCNT = oneWireRWnSlotT then
BasicFuncStatus <= "010110";
else
BasicTimingCNT <= BasicTimingCNT + "0000000000000001";
end if;
when "010110" =>
BasicFuncStatus <= "010111";
BasicTimingCNT <= (others => '0');
oneWireDQ_RWn <= '1';
---Wait for Rec End
when "010111" =>
if BasicTimingCNT = oneWireRWnRecT then
BasicFuncStatus <= "011000";
else
BasicTimingCNT <= BasicTimingCNT + "0000000000000001";
end if;
---Return
when "011000" =>
BasicFuncStatus <= "011001";
BasicTimingCNT <= (others => '0');
BasicFuncBuffer <= '1' & BasicFuncBuffer(63 downto 1);
when "011001" =>
if BasicFuncOpNum = "000000" then
BasicFuncStatus <= "011010";
BasicFuncEnd <= '1';
else
BasicFuncStatus <= "010001";
BasicFuncOpNum <= BasicFuncOpNum - "000001";
end if;
when "011010" =>
BasicFuncStatus <= IdleStatus;
BasicFuncEnd <= '1';

-------------------------------------------------------------------------------------------------------------------
--Read Function
when "100000" =>
BasicFuncStatus <= "100001";
oneWireDQ_RWn <= '1';
BasicFuncBuffer <= (others => '0');
BasicFuncOpNum <= BasicFuncBitNum;
BasicTimingCNT <= (others => '0');
---Int
when "100001" =>
BasicFuncStatus <= "100010";
oneWireDQ_RWn <= '0';
oneWireDQ_OUT <= '0';
when "100010" =>
if BasicTimingCNT = oneWireRWnIntT then
BasicFuncStatus <= "100011";
oneWireDQ_RWn <= '1';
else
BasicTimingCNT <= BasicTimingCNT + "0000000000000001";
end if;
when "100011" =>
BasicFuncStatus <= "100100";
oneWireDQ_RWn <= '1';
---Sample
when "100100" =>
if BasicTimingCNT = oneWireRWnSampleT then
BasicFuncStatus <= "100101";
else
BasicTimingCNT <= BasicTimingCNT + "0000000000000001";
end if;
when "100101" =>
BasicFuncStatus <= "100110";
BasicFuncBuffer <= oneWireDQ_IN & BasicFuncBuffer(63 downto 1);
---Wait for Slot End
when "100110" =>
if BasicTimingCNT = oneWireRWnSlotT then
BasicFuncStatus <= "100111";
else
BasicTimingCNT <= BasicTimingCNT + "0000000000000001";
end if;
oneWireDQ_RWn <= '1';
when "100111" =>
BasicFuncStatus <= "101000";
BasicTimingCNT <= (others => '0');
---Wait for Rec End
when "101000" =>
if BasicTimingCNT = oneWireRWnRecT then
BasicFuncStatus <= "101001";
else
BasicTimingCNT <= BasicTimingCNT + "0000000000000001";
end if;
oneWireDQ_RWn <= '1';
---Return
when "101001" =>
BasicFuncStatus <= "101010";
BasicTimingCNT <= (others => '0');
BasicFuncBufferOut <= BasicFuncBuffer;
when "101010" =>
if BasicFuncOpNum = "000000" then
BasicFuncStatus <= "101011";
BasicFuncEnd <= '1';
else
BasicFuncStatus <= "100001";
BasicFuncOpNum <= BasicFuncOpNum - "000001";
end if;
when "101011" =>
BasicFuncStatus <= IdleStatus;
BasicFuncEnd <= '1';

-------------------------------------------------------------------------------------------------------------------
--Crc Function
when "110000" =>
BasicFuncStatus <= "110001";
BasicFuncOpNum <= BasicFuncBitNum;
BasicFuncBuffer <= BasicFuncBufferIn;
CRC_Reg <= "00000000";
when "110001" =>
BasicFuncStatus <= "110010";
CRC_RegMSB <= BasicFuncBuffer(0) xor CRC_Reg(0);
when "110010" =>
BasicFuncStatus <= "110011";
CRC_Reg(7) <= CRC_RegMSB;
CRC_Reg(6) <= CRC_Reg(7);
CRC_Reg(5) <= CRC_Reg(6);
CRC_Reg(4) <= CRC_Reg(5);
CRC_Reg(3) <= CRC_Reg(4) xor CRC_RegMSB;
CRC_Reg(2) <= CRC_Reg(3) xor CRC_RegMSB;
CRC_Reg(1) <= CRC_Reg(2);
CRC_Reg(0) <= CRC_Reg(1);
when "110011" =>
BasicFuncStatus <= "110100";
BasicFuncBuffer <= '0' & BasicFuncBuffer(63 downto 1);
when "110100" =>
BasicFuncStatus <= "110101";
when "110101" =>
if BasicFuncOpNum = "000000" then
BasicFuncStatus <= "110110";
BasicFuncBufferOut(7 downto 0) <= CRC_Reg;
else
BasicFuncStatus <= "110001";
BasicFuncOpNum <= BasicFuncOpNum - "000001";
end if;
when "110110" =>
BasicFuncStatus <= "110111";
BasicFuncEnd <= '1';
when "110111" =>
BasicFuncStatus <= IdleStatus;
BasicFuncEnd <= '1';
-------------------------------------------------------------------------------------------------------------------
when others =>
BasicFuncStatus <= IdleStatus;
end case;
end if;
end process;

process(rst,clk)
begin
if rst = '1' then
oneWireDQ <= 'Z';
oneWireDQ_IN <= '1';
elsif rising_edge(clk) then
if oneWireDQ_RWn = '0' then
oneWireDQ <= oneWireDQ_OUT;
else
oneWireDQ <= 'Z';
end if;
oneWireDQ_IN <= oneWireDQ;
end if;
end process;
end behave;

medav

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 1回
  • 年度积分:0
  • 历史总积分:1
  • 注册:2008年2月27日
发表于:2008-02-27 01:49:00
399楼
最近做测温实验,DS18B20和cc2430,但DS18B20不能初始化,请问时序是否和系统晶振有关??按照手册上的时序设置始终不通,请教各位了,知道的指点一下!

能否麻烦digi发个通过的单点汇编程序参考一下!我的邮箱xbirk@163.com

digi

  • 精华:19帖
  • 求助:0帖
  • 帖子:52帖 | 797回
  • 年度积分:0
  • 历史总积分:1171
  • 注册:2001年9月19日
发表于:2008-02-27 15:47:00
400楼
请查收

热门招聘
相关主题

官方公众号

智造工程师