|
|
ds18b20溫度顯示于數(shù)碼管,包含程序和仿真
0.png (50.18 KB, 下載次數(shù): 11)
下載附件
2018-3-8 20:48 上傳
單片機(jī)源程序如下:
- /*-----------------------------------------------
- 名稱:DS18b20數(shù)碼管顯示溫度
- 編寫:林雁翔
- 日期:2013.6.16
- 修改:無(wú)
- 內(nèi)容:顯示格式 符號(hào) xxx C
- 可以顯示負(fù)溫度
- ------------------------------------------------*/
- #include <reg52.h>
- #include "delay.h"
- #include "ds18b20.h"
- #define uint unsigned int
- #define uchar unsigned char
- #define duanMa P0
- #define weiMa P2
- uchar code disCode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,
- 0x82,0xf8,0x80,0x90,0xff,0xBF,0xc6}; //共陽(yáng)極數(shù)碼管顯示字符編碼
- uchar code disBit[]={0x01,0x02,0x04,0x08,0x10,0x20}; //數(shù)碼管顯示位碼
- uchar disBuf[]={6,6,6,9,9,9}; //準(zhǔn)備顯示的數(shù)字
- uint tempNum=0,tempH,tempL;
- bit tempFlag=0;
- void Init();
- void Display();
- void main()
- {
- Init();
- while(1)
- {
- tempNum=ReadTemperature();
- if(tempNum&(1<<15)) //如果溫度為負(fù)數(shù),則取原碼
- {
- tempNum=~tempNum;
- tempNum+=1;
- tempFlag=1; //標(biāo)志為負(fù)數(shù)
- }
- //tempL=tempNum|0x0F; //獲取低四位的小數(shù)溫度位
- tempH=tempNum>>4; //獲取整數(shù)位溫度位
- if(tempFlag==1)
- {
- tempFlag=0;
- disBuf[0]=11; //顯示負(fù)號(hào)
- }
- else
- {
- disBuf[0]=10; //不顯示任何數(shù)據(jù)
- }
- disBuf[1]=tempH/100;
- disBuf[2]=tempH%100/10;
- disBuf[3]=(tempH%10);
- disBuf[4]=10; //不顯示小數(shù)
- disBuf[5]=12; //顯示C
- Display();
- }
- }
- void Init()
- {
- duanMa=0xFF; //初始化數(shù)碼管斷碼
- weiMa=0x00; //初始化數(shù)碼管位碼
- }
- void Display()
- {
- uchar i=0;
- for(i=0;i<6;i++)
- {
- duanMa=disCode[disBuf[i]];
- weiMa=disBit[i];
- DelayMs(1);
- weiMa=0x00;
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
在數(shù)碼管上顯示.rar
(68.87 KB, 下載次數(shù): 46)
2018-3-8 13:32 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|