【正文】
如果一線上掛接多個 DS18B采用寄生 電源 連接方式、需要進(jìn)行轉(zhuǎn)換精度配置、高低限報警等,則子程序 GETWD的編寫就要復(fù)雜一些,限于篇幅,這一部分不再詳述,請參閱相關(guān)內(nèi)容。 …… INIT:CLREA INI10:SETBDAT MOVR2,# 200 ( a)寄生 電源 工作方式 ( b)外接 電源 工作方式 圖 4DS18B20與微處理器的典型連接圖 INI11:CLRDAT DJNZR2,INI11;主機(jī)發(fā)復(fù)位脈沖持續(xù) 3μs200=600μs SETBDAT;主機(jī)釋放總線,口線改為輸入 MOVR2,# 30 IN12:DJNZR2,INI12; DS18B20等待 2μs30=60μs CLRC ORLC,DAT; DS18B20 數(shù)據(jù)線變低(存在脈沖)嗎? JCINI10; DS18B20 未準(zhǔn)備好重新初始化 MOVR6,# 80 INI13:ORLC,DAT JCINI14; DS18B20數(shù)據(jù)線變高,初始化成功 DJNZR6,INI13;數(shù)據(jù)線低電平可持續(xù) 3μs80=240μs SJMPINI10;初始化失敗,重來 INI14:MOVR2,# 240 IN15:DJNZR2,INI15; DS18B20應(yīng)答最少 2μs240=480μs RET ;------------------------ 無 錫 職 業(yè) 技 術(shù) 學(xué) 院 畢業(yè)設(shè)計說明書(英文翻譯) 17 WRITE:CLREA MOVR3,# 8;循環(huán) 8次,寫一個字節(jié) WR11:SETBDAT MOVR4,# 8 RRCA;寫入位從 A中移到 CY CLRDAT WR12:DJNZR4,WR12;等待16μs MOVDAT,C;命令字按位依次送給 DS18B20 MOVR4,# 20 WR13:DJNZR4,WR13 ;保證寫過程持續(xù) 60μs DJNZR3,WR11;未送完一個字節(jié)繼續(xù) SETBDAT RET ;------------------------ READ:CLREA MOVR6,# 8;循環(huán) 8次,讀一個字節(jié) RD11:CLRDAT MOVR4,# 4 NOP;低電平持續(xù) 2μs SETBDAT;口線設(shè)為輸入 RD12:DJNZR4,RD12 ;等待 8μs MOVC,DAT ;主機(jī)按位依次讀入 DS18B20的數(shù)據(jù) RRCA;讀取的數(shù)據(jù)移入 A MOVR5,# 30 RD13:DJNZR5,RD13 ;保證讀過程持續(xù) 60μsDJNZR6,RD11 ;讀完一個字節(jié)的數(shù)據(jù),存入 A中 SETBDAT RET ;------------------------ 主機(jī)控制 DS18B20完成溫度轉(zhuǎn)換必須經(jīng)過三個步驟:初始化、 ROM操作指令、存儲器操作指令。其工作時序包括初始化時序、寫時序和讀時序,如圖 3( a)( b)( c)所示。其中配置寄存器的格式如下: MSBLSB R R0 決定溫度轉(zhuǎn)換的精度位數(shù): R1R0=“00”, 9 位精度,最大轉(zhuǎn)換時間為; R1R0=“01”, 10位精度,最大轉(zhuǎn)換時間為 ; R1R0=“10”, 11 位精度,最大轉(zhuǎn)換時間為 375ms; R1R0=“11”, 12 位精度,最大轉(zhuǎn)換時間為 750ms;未編程時默認(rèn)為 12位精度。 ROM 的作用是使每一個 DS18B20都各不相同,這樣就可以實(shí)現(xiàn)一根總線上掛接多個 DS18B20的目的。 2 DS18B20的內(nèi)部結(jié)構(gòu) DS18B20內(nèi)部結(jié)構(gòu)如圖 1所示,主要由 4部分組成: 64位 ROM、溫度 傳感器 、非揮發(fā)的溫度報警觸發(fā)器 TH和 TL、配置寄存器。 it will return a 1 when the copy process is plete. If parasitepowered, the bus master has to enable a strong pullup for at least 10 ms immediately after issuing this mand. Convert T [44h] This mand begins a temperature conversion. No further data is required. The temperature conversion will be performed and then the DS18B20 will remain idle. If the bus master issues read time slots following this mand, the DS18B20 will output 0 on the bus as long as it is busy making a temperature conversion。C to +85176。C to+125176。C. Fahrenheit equivalent is 67176。C _ Thermometer resolution is programmablefrom 9 to 12 bits _ Converts 12bit temperature to digital word in750 ms (max.) _ Userdefinable, nonvolatile temperature alarmsettings _ Alarm search mand identifies andaddresses devices whose temperature is outside of programmed limits (temperature alarm condition) _ Applications include thermostatic controls, industrial systems, consumer products,thermometers, or any thermally sensitive system PIN DESCRIPTION GND Ground DQ Data In/Out VDD Power Supply Voltage NC No Connect DESCRIPTION The DS18B20 Digital Thermometer provides 9 to 12bit (configurable) temperature readings which indicate the temperature of the device. Information is sent to/from the DS18B20 over a 1Wire interface, so that only one wire (and ground) needs to be connected from a central microprocessor to a DS18B20. 無 錫 職 業(yè) 技 術(shù) 學(xué) 院 畢業(yè)設(shè)計說明書(英文翻譯) 3 Power for reading, writing, and performing temperature conversions can be derived from the data line itself with no need for an external power source. Because each DS18B20 contains a unique silicon serial number, multiple DS18B20s can exist on the same 1Wire bus. This allows for placing temperature sensors in many different places. Applications where this feature is useful include HVAC environmental controls, sensing temperatures inside buildings, equipment or machinery, and process monitoring and control. DETAILED PIN DESCRIPTION Table 1 DS18B20Z (8pin SOIC) and DS18P20P (TSOC): All pins not specified in this table are not to be connected. OVERVIEW The block diagram of Figure 1 shows the major ponents of the DS18B20. The DS18B20 has four main data ponents: 1) 64bit lasered ROM, 2) temperature sensor, 3) nonvolatile temperature alarm triggers TH and TL, and 4) a configuration register. The device derives its power from the 1Wire munication line by storing energy on an internal capacitor during periods of time when the signal line is high and continues to operate off this power source during the low times of the 1Wire line until it returns high to replenish the parasite (capacitor) supply. As an alternative, the DS18B20 may also be powered from an external 3V supply. Communication to the DS18B20 is via a 1Wire port. With the 1Wire port, the memory and control functions will not be available before the ROM function protocol has been established. The master must first provide one of five ROM function mands: 1) Read ROM, 2) Match ROM, 3) Search ROM, 4) Skip ROM, or 5) Alarm Search. These mands operate on the 64bit lasered ROM portion of each device and can single out a specific device if many are present on the 1Wire line as well as indicate to the bus master how many and what types of devices are present. After a ROM function sequence has been successfully executed, the memory and control functions are accessible and the master may then provide any one of the six memory and control function mands. One control function mand instructs the DS18B20 to perform a temperature measurement. The result of this measurement will be placed in the DS18B20’s scratchpad memory, and may be read by issuing a memory function mand which reads the contents of the scratchpad memory. The temperature alarm triggers TH and TL consist of 1 byte EEPROM each. If the alarm search mand is not applied to the DS18B20, these registers may be used as general purpose user memory. The scratchpad also contains a configuration byte to set the desired resolution of the 無 錫 職 業(yè) 技 術(shù) 學(xué) 院 畢業(yè)設(shè)計說明書(英文翻譯)