【正文】
es read time slots when data is to be read from the DS18B20. A read time slot is initiated when the host pulls the data line from a logic high level to logic low level. The data line must remain at a low logic level for a minimum of 1 s。 DS18B20的管腳排列如圖 2所示,DQ為數(shù)字信號輸入/輸出端; GND為 電源 地; VDD為外接供電 電源 輸入端(在寄生 電源 接線方式時(shí)接地,見圖 4)。 無 錫 職 業(yè) 技 術(shù) 學(xué) 院 畢業(yè)設(shè)計(jì)說明書(英文翻譯) 14 圖 1DS18B20的內(nèi)部結(jié)構(gòu) 圖 2DS18B20的管腳排列 ( a)初始化時(shí)序 無 錫 職 業(yè) 技 術(shù) 學(xué) 院 畢業(yè)設(shè)計(jì)說明書(英文翻譯) 15 ( b)寫時(shí)序 ( c)讀時(shí)序 圖 3DS18B20的工作時(shí)序圖 DS18B20中的溫度 傳感器 完成對溫度的測量,用 16位符號擴(kuò)展的二進(jìn)制補(bǔ)碼讀數(shù)形式提供,以 ℃ /LSB 形式表達(dá),其中 S 為符號位。 高速暫 存器是一個(gè) 9字節(jié)的存儲器。 360畢業(yè)設(shè)計(jì)網(wǎng) 4 DS18B20與單片機(jī)的典型接口設(shè)計(jì) 圖 4 以 MCS- 51 系列單片機(jī)為例,畫出了 DS18B20 與微處理器的典型連接。必須先啟動(dòng) DS18B20開始轉(zhuǎn)換,再讀出溫度轉(zhuǎn)換值。 我們已成功地將 DS18B20應(yīng)用于所開發(fā)的 “家用采暖洗浴器 ”控制系統(tǒng)中,其轉(zhuǎn)換速度快,轉(zhuǎn)換精度高,與微處理器的接口簡單,給硬件設(shè)計(jì)工作帶來了極大的方便,能有效地降低成本,縮短開發(fā)周期。 GETWD:LCALLINIT MOVA,# 0CCH LCALLWRITE;發(fā)跳過 ROM命令 MOVA,# 44H LCALLWRITE;發(fā)啟動(dòng)轉(zhuǎn)換命令 LCALLINIT MOVA,# 0CCH;發(fā)跳過 ROM命令 LCALLWRITE MOVA,# 0BEH;發(fā)讀存儲器命令 LCALLWRITE LCALLREAD MOVWDLSB,A ;溫度值低位字節(jié)送 WDLSB LCALLREAD MOVWDMSB,A ;溫度值高位字節(jié)送 WDMSB RET …… 子程序 GETWD 讀取的溫度值高位字節(jié)送 WDMSB 單元,低位字節(jié)送 WDLSB單元,再按照溫度值字節(jié)的表示格式及其符號位,經(jīng)過簡單的變換即可得到實(shí)際溫度值。 假設(shè)單片機(jī)系統(tǒng)所用的晶振頻率為 12MHz,根據(jù) DS18B20的初始化時(shí)序、寫時(shí)序和讀時(shí)序,分別編寫了 3 個(gè)子程序: INIT 為初始化子程序, WRITE 為寫(命令或數(shù)據(jù))子程序 , READ為讀數(shù)據(jù)子程序,所有的數(shù)據(jù)讀寫均由最低位開始。 無 錫 職 業(yè) 技 術(shù) 學(xué) 院 畢業(yè)設(shè)計(jì)說明書(英文翻譯) 16 3 DS18B20的工作時(shí)序 DS18B20的一線工作協(xié)議流程是:初始化 →ROM 操作指令 → 存儲器操作指令 →數(shù)據(jù)傳輸。 溫度值低字節(jié) MSBLSB 溫度值高字節(jié) 高低溫報(bào)警觸發(fā)器 TH和 TL、配置寄存器均由一個(gè)字節(jié)的 EEPROM組成,使用一個(gè)存儲器功能命令可對 TH、 TL或配置寄存器寫入。 64位 ROM 的排的循環(huán) 冗余 校驗(yàn)碼( CRC=X8+ X5+ X4+ 1)。以上特點(diǎn)使 DS18B20非常適用于遠(yuǎn)距離多點(diǎn)溫度檢測 系統(tǒng)。 it is important that each device on the bus be able to drive it at the appropriate time. To facilitate this, each device attached to the 1Wire bus must have open drain or 3state outputs. The 1Wire 無 錫 職 業(yè) 技 術(shù) 學(xué) 院 畢業(yè)設(shè)計(jì)說明書(英文翻譯) 8 port of the DS18B20 (DQ pin) is open drain with an internal circuit equivalent to that shown in Figure 9. A multidrop bus consists of a 1Wire bus with multiple slaves attached. The 1Wire bus requires a pullup resistor of approximately 5k. The idle state for the 1Wire bus is high. If for any reason a transaction needs to be suspended, the bus MUST be left in the idle state if the transaction is to resume. Infinite recovery time can occur between bits so long as the 1Wire bus is in the inactive (high) state during the recovery period. If this does not occur s, all ponents on the bus will be and the bus is left low for more than 480 reset. TRANSACTION SEQUENCE The protocol for accessing the DS18B20 via the 1Wire port is as follows: _ Initialization _ ROM Function Command _ Memory Function Command _ Transaction/Data INITIALIZATION All transactions on the 1Wire bus begin with an initialization sequence. The initialization sequence consists of a reset pulse transmitted by the bus master followed by presence pulse(s) transmitted by the slave(s). The presence pulse lets the bus master know that the DS18B20 is on the bus and is ready to operate. For more details, see the “1Wire Signaling” section. ROM FUNCTION COMMANDS Once the bus master has detected a presence, it can issue one of the five ROM function mands. All ROM function mands are 8 bits long. A list of these mands follows (refer to flowchart in Figure 5): Read ROM [33h] This mand allows the bus master to read the DS18B20’s 8bit family code, unique 48bit serial number, and 8bit CRC. This mand can only be used if there is a single DS18B20 on the bus. If more than one slave is present on the bus, a data collision will occur when all slaves try to transmit at the same time (open drain will produce a wired AND result). Match ROM [55h] The match ROM mand, followed by a 64bit ROM sequence, allows the bus master to address a specific DS18B20 on a multidrop bus. Only the DS18B20 that exactly matches the 64bit ROM sequence will respond to the following memory function mand. All slaves that do not match the 64bit ROM sequence will wait for a reset pulse. This mand can be used with a single or multiple devices on the bus. Skip ROM [CCh] This mand can save time in a single drop bus system by allowing the bus master to access the memory functions without providing the 64bit ROM code. If more than one slave is present on the bus and a Read mand is issued following the Skip ROM mand, data collision will occur on the bus as multiple slaves transmit simultaneously (open drain pulldowns will produce a wired AND result). Search ROM [F0h] When a system is initially brought up, the bus master might not know the number of devices on the 1Wire bus or their 64bit ROM codes. The search ROM mand allows the bus master to use a process of elimination to identify the 64bit ROM codes of all slave devices on the bus. Alarm Search [ECh] The flowchart of this mand is identical to the Search 無 錫 職 業(yè) 技 術(shù) 學(xué) 院 畢業(yè)設(shè)計(jì)說明書(英文翻譯) 9 ROM mand. However, the DS18B20 will respond to this mand only if a n alarm condition has been encountered at the last temperature measurement. An alarm condition is defined as a temperature higher than TH or lower than TL. The alarm condition remains set as long as the DS18B20 is powered up, or until another temperature measurement reveals a nonalarming value. For alarming, the trigger values stored in EEPROM are taken into account. If an alarm condition exists and the TH or TL settings are changed, another temperature conversion should be done to validate any alarm conditions. DS18B 20 12 of 26 Example of a ROM Search The ROM search process is the repetition of a simple threestep routine: read a bit, read the plement of the bit, then write the desired value of that bit.