【正文】
smg3=1。 } if(100=zs)//當溫度值大于 100 是顯示 P. {P0=0x11。 smg1=1。 smg3=1。0x7f。 smg2=1。//點亮小數位數碼管 LED0 28 delay_1ms()。//送小數百分位代碼 smg0=0。//熄滅高位數碼管 LED3 delay_1ms()。 smg0=1。 smg1=1。//點亮小數位數碼管 LED1 delay_1ms()。//送小數十分位代碼 smg0=1。 smg2=1。amp。 smg2=1。 smg3=1。 } } return (i)。//調顯示程序延時,消抖 i=key_data()。 i=key_data()。//調顯示程序延時,消抖 i=key_data()。 i=key_data()。 i=iamp。0x0f)*)/1。0xf0)/16+b*16。//跳過 ROM write_byte(0xbe)。//跳過 ROM write_byte(0x44)。//延時等待讀下一位數據 } return d。// 拉低數據總線 d=1。//延時等待寫下一位數據 } /*****************************讀字節(jié) 函數 ****************************/ uchar read_byte(void) { uchar i,d。//讀低位數據(延時大于 1us) delay(4)。i8。 n=DQ。//穩(wěn)定數據 DQ=0。 } } /*****************************延時 函數 ******************************/ void delay(uint t) { while(t)。t0。break。break。 BZ=0xff。//聲明延時函數 void delay_1ms(void)。//聲明 18b20 寫一字節(jié)函數 uchar read_byte(void)。BZ。//接數碼管 LED1 sbit smg2=P2^1。 14 致 謝 通過這次 課程 設計我對單片機有了系統(tǒng)的了解,對單片機也有了新的認識,從以前的知其然到現在的知其所以然是這次 課程 設計最大的收獲。系統(tǒng) 上電或按鍵復位后能自動顯示系統(tǒng)提示符 “ P.” ,進入測溫準備狀態(tài)。我覺得這點非常好,不僅活躍了課堂,在而且快快樂樂的學到了知識,還學回了做人。挫折是一份財富,經歷是一份擁有。 我想說,設計確實有些辛苦,但苦中也有樂,在如今單一的理論學習中,很少有機會能有實踐的機會 。從開始時滿富盛激情到最后汗水背后的復雜心情,點點滴滴無不令我回味無長。同時 我 覺 得做課程設計同時也是對課本知識的鞏固和加強,由于課本上的 知識太多,平時課間的學習并不能很好的理解和運用各 指令 的功能,而且考試內容有限,所以在這次課程設計過程中,我們 加深的對單片機指令系統(tǒng)和內部資源的 了解 。 實物結果 ( 1) 數字溫度計 上 電時, 溫度計進入準備狀態(tài), 數碼管顯示器顯示“ P.”如圖9 所示。 ( 2) 使用說明: 1)該數字溫度計測量 溫度范圍 0℃~ 99℃,測量精度小數點后兩位 ,應 用于對溫度比較準確的場所, 工業(yè)生產、醫(yī)療 或科研實驗室使用 。 11 4 設計結論、 實物 結果、教學建議 設計結論及使用說明 ( 1)設計結論: 本系統(tǒng)就是充分利用了 AT89S52 芯片的 I/O 引腳。 調 延 時 1 m s 函 數d i s p l a yB Z = 0 ?送 P . 段 控 碼送 低 位 位 控 碼調 延 時 1 m s 函 數送 百 分 位 段 控 碼送 百 分 位 位 控 碼 調 延 時 1 m s 函 數送 十 分 位 段 控 碼送 十 分 位 位 控 碼調 延 時 1 m s 函 數送 個 位 及 小 數 點 段 控 碼送 個 位 位 控 碼調 延 時 1 m s 函 數送 十 段 控 碼送 十 位 位 控 碼返 回YN 圖 8 顯示函數流程圖 10 顯示 函數執(zhí)行過程: 1)判斷標志位,當標志位不為 0,送 , 然后 調延時延時 1ms 函數。 ( 2) DS18B20 初始化 函數 流程圖 如圖 5( a)所示, 讀一字節(jié) 函數 流程圖 如圖 5( b)所示, 寫 一字節(jié)函數 流程圖 如圖 5( c)所示。 溫度計 上電 數碼管 顯示“ P.”,按 S0 鍵 啟動溫度計 ,數碼管顯示 當前溫度 , 再次按 S0 鍵關閉溫度計,數碼管顯示“ P.”。 系 統(tǒng) 初 始 化 模 塊按 鍵 模 塊數 碼 顯 示 模 塊測 溫 模 塊 圖 3 軟件系統(tǒng)結構圖 ( 1) 按鍵模塊 其中用到了 key_data ( 取鍵值函數 ) 、 display(顯示函數延時進行按鍵消抖) 和 key( 判鍵函數 )。 ( 3) 一個獨立鍵盤 S0, 按鍵的結果存貯在單片機的內部數據存儲器里面。 電路原理圖、 PCB 圖、 元件布局圖 Protel原理圖、 元器件布局圖、 PCB 圖 分別見 附錄 A、 附錄 B 與 附錄 C。 DS18B20 在三線制應用時,應將其三線焊接牢固;在兩線應用時,應將 VCC與 GND接在一起,焊接牢 5 固。編制程序時必須嚴格按芯片數據手冊提供的有關操作順序進行,讀 、寫時間片程序要嚴格按要求編寫。其工作電源既可在遠端引入,也可采用寄生電源方式產生。本設計只有四位,所以滿足要求。因此,同一時刻,如果各位的位選線都處于選通狀態(tài)的話,四位 LED 將顯示相同的字符。其作用是開啟與關畢溫度計。 MCS51 單片機通常采用上電 自動復位 、 按鍵復位 、以及上電加按鍵復位等,我們采用的是上電加按鍵復位方式,這樣做的優(yōu)點是上電后可以直接進入復位狀態(tài),當程序出現錯誤時,可以隨時使電路復位。二是對振蕩器的頻率進行微調 , C C2的值為 33pF。各模塊的功能如下: ( 1)時鐘電路設計 單片機必須在時鐘的驅動下才能工作 , 在單片機內部有一個時鐘振蕩電路 ,只需要外接一個振蕩源就能產生一定的時鐘信號送到單片機內部的各個單元 ,決定單片機的工作速度。如果在硬件電路設計就預留出一些 I/O 端口,雖然當時空著沒用,那么用的時候就派上用場了。因為很少有一錘定音的電路設計,如果現在不留余地,將來可能要為一點小小的修改或擴展而被迫進行全面返工。 3)可以通過開始和結束鍵控制數字溫度計的工作狀態(tài)。 關鍵詞: 數字溫度計, 單片機, 溫度傳感器 II ABSTRACT The temperature detection and control is the process of industrial production is one of the typical applications, with the sensor in the life of a more extensive application, using a new digital temperature sensor to realize the temperature measurement and control get faster development, the curriculum design based on the design of a AT89S52 digital thermometer. The system can facilitate the realization of temperature acquisition and display. The system is posed of the hardware system and software system, the hardware system is posed of MCU minimum system, temperature measurement circuit and display circuit。 該系統(tǒng)可以方便的實現溫度采集和顯示 。系統(tǒng)由硬件系統(tǒng)和軟件系統(tǒng)組成,硬件系統(tǒng)由單片機最小系統(tǒng)、測溫電路以及顯示電路組成;軟件系統(tǒng)由主函程序、測溫程序、判鍵程序和顯示程序組成。 the software system is posed of a main function procedures, measurement procedures, convicted of key procedures and display program. It is very convenient to use, has high accuracy, wide measuring range, high sensitivity, small volume, low power consumption, suitable for our daily life and industrial and agricultural production, temperature measurement, but also can be used as a temperature processing module embedded in other systems, as the other main system auxiliary extension. The system design and layout is simple, pact structure, strong antiinterference ability, in large warehouses, factories, construction and other areas of intelligent temperature detection has a wide application prospect in the. Key words digital thermometer; MCU; temperature sensor III 目 錄 1 設計任務 、功能要求及總體方案 ...............