【正文】
/輸出腳,與 TTL 電平兼容。配置寄存器的內容用于確定溫度值的數字轉換率。 寄生電源供電模式如圖 所示:從圖中可知, DS18B20 的 GND 和 VDD 均直接接地,DQ 與單總線相連,單片機其中一個 I/O 口與 DS18B20 的 DQ 端相連。命令代碼為 55H,若總線上有多個從設備時,適用該命令可選中某一指定的 DS18B20,即只有和 64 位二進制 ROM 代碼完全匹配的 DS18B20 才能響應其操作。若主機在該命令之后又發(fā)出讀操作,而 DS18B20 又忙于將暫存器中的內容復制到 EEPROM 時, DS18B20 就會輸出一個“ 0” ,若復制結束,則 DS18B20 13 輸出一個“ 1”。它很簡單并且能夠實現遠距離通信。如何設置取決于你想傳送的信息。例如,如果數據是 011,那么對于偶校驗,校驗位為 0,保證邏輯高的位數是偶數個。 程序 核心部分的 設計 LCD1602 驅動程序 部分 //寫指令 void writecmd(uchar ) //寫指令 { E=0。 } //初始化 void init(void) { delay_1ms(15)。 } DS18B20 驅動程序部分 void init_DS18B20(void) //對 DS18B20 進行初始化 { uchar n。 DQ=1。 //啟動溫度測量 delay(300)。 UART_Send_Byte(dat%10 + 39。 24 附錄 1:電路原理圖 25 附錄 2:源程序 文件程序: include typedef unsigned char uint8。 while(1)。 } /** * 將數據轉換成 ASC 碼并通過 UART 發(fā)送出去 */ void UART_Send_Dat(uint8 dat) { UART_Send_Byte(dat/10%10 + 39。 delay_1ms(2)。 delay_1ms(5)。k=168。i6。 } } void temp_display() //溫度顯示函數 { uint i。 delay_50us(50)。 DQ=0。 } uchar read_byte(void) //讀一個字節(jié) { uchar i,value。 write_byte(0xbe)。 init_DS18B20()。 dat=1。 //采樣 DQ=1。 writecmd(0x80+0x0C)。 delay_1ms(2)。 writecmd(0x80+0x45)。ji。 delay_1ms(5)。 RW=0。 while (TI == 0)。 TL1 = 0xFD。 同時,在論文寫作過程中,我還參考了有關的書籍和論文,在這里一并向有關的作者表示謝意。039。 write_byte(0xcc)。0x01。 writecmd(0x0c)。 delay_1ms(2)。 格式形式第二行: normal 若溫度不正常,則顯示: 液晶 1602 顯示 格式形式第一行: The temp is: 30’ C。當然沒有校驗位也是可以的。高波特率常常用于放置的很近的儀器間的通信,典型的例子就是 GPIB 設備的通信。 串口通信的概念非常簡單,串口按位( bit)發(fā)送和接收字節(jié)。 Copy scratchpad(復制暫存器 )。 表 溫度數據關系 溫度 ℃ 數據輸出(二進制) 數據輸出(十六進制) +125 00000000 11111010 00FA +25 00000000 00110010 0032 + 00000000 00000001 0001 0 00000000 00000000 0000 11111111 11111111 FFFF 25 11111111 11001110 FFCE 12 55 11111111 10010010 FF92 S18B20 遵循單總線協議,每次測溫時都必須有 4 個過程 [6]: ? 初始化; ? 傳送 ROM 操作命令; ? 傳送 ROM 操作命令; ? 數據交換; DS18B20 的 ROM 命令 read ROM(讀 ROM) .命令代碼為 33H,允許主設備讀出 DS18B20 的 64 位二進制 ROM代碼。外部電源供電模式是將DS18B20 的 GND 直接接地, DQ 與但單總線相連 作為信號線, VDD 與外部電源正極相連。非易失性可點擦除 EEPROM 用來存放高溫觸發(fā)器 TH、低溫觸發(fā)器 TL 和配置寄存器中的信息。 LCD1602 的時序: 6 溫度傳感器 DS18B20 的選擇 DS18B20 是 Dallas 公司繼 DS1820 后推出的一種改進型智能數字溫度傳感器,與傳統的熱敏電阻相比,只需一根線就能直接讀出被測溫度值,并可根據實際需求來編程實現 9~12 位數字值的讀數方式 [3]。 abstract As the progress and development of The Times, temperature test has impact to our life, work, scientific research, each domain, has bee a very important thing, so the design of a temperature testing system is imperative. This paper introduces a detection system based on liquid crystal 1602 single chip microputer intelligent in detail using digital temperature sensor DS18B20 temperature measurement and control system in the development process, focusing on sensor under the single chip microputer hardware connection, software programming and the flow diagram of each module system are analyzed in detail, on the part of the circuit are introduced one by one, the system can easily realize the collection of temperature and alarm, and can according to need any upper and lower alarm temperature, it is quite convenient to use and has high precision, wide range, high sensitivity, small volume, low power consumption, suitable for our daily life and the temperature measurement in industrial and agricultural production, also can treat as temperature processing module into other systems, as an aid in the extension of other main with AT89S51 realize the minimalist temperature alarm system, the system structure is simple, strong antijamming capability, suitable for harsh environments onsite temperature measurement, have broad application prospects. Key words: single chip microputer。 液晶 LCD1602 的選擇 如圖所示為 LCD 顯示模塊: 本模塊采用的是 LCD1602 液晶。 VDD:可接電源,也可接地。 DS18B20 工作是按此寄存器的分辨率將溫度轉換為相應精度的數值,它是高速緩存器的第 5 個字節(jié),該字節(jié)定義如表 所示: 表 匹配寄存器 TM R0 R1 1 1 1 1 1 TM 是測試模式位,用于設置 DS18B20 在工作模式還是在測試模式,在 DS18B20 出廠時該位被設置為 0,用戶不要去改動; R1 和 R0 用來設置分辨率;其余 5 位均固定為 1。 DS18B20 的測溫原理 DS18B20 的測溫原理如圖 所示 , 其主要由斜率累加器、溫度系數振蕩器、減法計數器、溫度存儲器等功能部件組成。 Skip ROM(跳過 ROM)。 Convert T(溫度轉換 )。比如 IEEE488 定義并行通行狀態(tài)時,規(guī)定設備線總常不得超過 20 米,并且任意兩