|
這是一個很詳細(xì)的基于51單片機(jī)的數(shù)字溫度計課程設(shè)計用數(shù)碼管顯示溫度,包含Altium Designer畫的pcb文件,原理圖,還有仿等等。資料僅供參考學(xué)習(xí),任何商業(yè)用途概不負(fù)責(zé)。
單片機(jī)數(shù)字溫度計原理圖仿真圖:
pcb文件:
基于51單片機(jī)的數(shù)字溫度計詳細(xì)原理圖
本數(shù)字溫度計設(shè)計的所有資料下載:
數(shù)字溫度計資料.zip
(3.67 MB, 下載次數(shù): 748)
2016-5-12 07:55 上傳
點(diǎn)擊文件名下載附件
壇友修改的版本:
修改后的溫度計程序 Proteus7.5版本工程.7z
(40.52 KB, 下載次數(shù): 72)
2021-4-15 05:40 上傳
點(diǎn)擊文件名下載附件
相關(guān)試驗(yàn)文檔下載:
DS18B20數(shù)字溫度計設(shè)計實(shí)驗(yàn)文檔(數(shù)碼管顯示的).doc
(4.23 MB, 下載次數(shù): 246)
2021-4-15 05:40 上傳
點(diǎn)擊文件名下載附件
單片機(jī)數(shù)字溫度計設(shè)計.doc
(395.09 KB, 下載次數(shù): 254)
2021-4-15 05:40 上傳
點(diǎn)擊文件名下載附件
/*****溫度計的元件清單如下*****/
1、四位一體共陽數(shù)碼管;
2、三極管8550 5個;
3、雙孔接線端子 1個;
4、繼電器 1個;
5、LED 1個;
6、470電阻 9個;
7、空心三孔插針 1個;
8、蜂鳴器 1個;
9、單片機(jī) 1個;
11、4.7K電阻 10個;
12、DIP40 1個;
13、自鎖開關(guān) 1個;
14、10Uf電解電容 1個;
15、10K電阻 1個;
16、12M晶振 1個;
17、30P瓷片電容 2個;
18、輕觸按鍵 3個;
19、USB接口 1個;
20、二極管IN4148 1個;
21、10K排阻103 1個;
22、7*9萬用板 1個;
23、溫度傳感器DS18B20 1個;
24、USB數(shù)據(jù)線 1條;
25、電路圖紙 1張。
/*****共:25種元件*****/
單片機(jī)數(shù)字溫度計設(shè)計的程序源代碼:
- #include "reg51.h"
- #include "intrins.h" //_nop_();延時函數(shù)用
- #define dm P0 //段碼輸出口
- #define uchar unsigned char
- #define uint unsigned int
- sbit DQ=P2^7; //溫度輸入口
- sbit w0=P2^0; //數(shù)碼管4
- sbit w1=P2^1; //數(shù)碼管3
- sbit w2=P2^2; //數(shù)碼管2
- sbit w3=P2^3; //數(shù)碼管1
- sbit LED=P1^6; //指示燈
- sbit beep=P1^7; //蜂鳴器
- sbit set=P2^6; //溫度設(shè)置切換鍵
- sbit add=P2^4; //溫度加
- sbit dec=P2^5; //溫度減
- int temp1=0; //顯示當(dāng)前溫度和設(shè)置溫度的標(biāo)志位為0時顯示當(dāng)前溫度
- uint h;
- uint temp;
- uchar r;
- uchar high=30,low=15; //溫度范圍設(shè)置為15-30度
- uchar sign;
- uchar q=0;
- uchar tt=0;
- uchar scale;
- //**************溫度小數(shù)部分用查表法***********//
- uchar code ditab[16]={0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09}; //小數(shù)斷碼表
- uchar code table_dm[12]={~0x3f,~0x06,~0x5b,~0x4f,~0x66,~0x6d,~0x7d,~0x07,~0x7f,~0x6f,~0x00,~0x40};
- //共陽極數(shù)碼管LED段碼表 "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "不亮" "-"
- uchar table_dm1[]={~0xbf,~0x86,~0xdb,~0xcf,~0xe6,~0xed,~0xfd,~0x87,~0xff,~0xef}; //個位帶小數(shù)點(diǎn)的斷碼表
-
- uchar data temp_data[2]={0x00,0x00}; //讀出溫度暫放
- uchar data display[5]={0x00,0x00,0x00,0x00,0x00}; //顯示單元數(shù)據(jù),共4個數(shù)據(jù)和一個運(yùn)算暫用
- /*****************11us延時函數(shù)*************************/
- void delay(uint t)
- {
- for (;t>0;t--);
- }
- void scan()
- {
- int j;
- for(j=0;j<4;j++)
- {
- switch (j)
- {
- case 0: dm=table_dm[display[0]];w0=0;delay(50);w0=1;//xiaoshu
- case 1: dm=table_dm1[display[1]];w1=0;delay(50);w1=1;//gewei
- case 2: dm=table_dm[display[2]];w2=0;delay(50);w2=1;//shiwei
- case 3: dm=table_dm[display[3]];w3=0;delay(50);w3=1;//baiwei
- // else{dm=table_dm[b3];w3=0;delay(50);w3=1;}
- }
- }
- }
- //***************DS18B20復(fù)位函數(shù)************************/
- ow_reset(void)
- {
- char presence=1;
- while(presence)
- {
- while(presence)
- {
- DQ=1;_nop_();_nop_();//從高拉倒低
- DQ=0;
- delay(50); //550 us
- DQ=1;
- delay(6); //66 us
- presence=DQ; //presence=0 復(fù)位成功,繼續(xù)下一步
- }
- delay(45); //延時500 us
- presence=~DQ;
- }
- DQ=1; //拉高電平
- }
- /****************DS18B20寫命令函數(shù)************************/
- //向1-WIRE 總線上寫1個字節(jié)
- void write_byte(uchar val)
- {
- uchar i;
- for(i=8;i>0;i--)
- {
- DQ=1;_nop_();_nop_(); //從高拉倒低
- DQ=0;_nop_();_nop_();_nop_();_nop_(); //5 us
- DQ=val&0x01; //最低位移出
- delay(6); //66 us
- val=val/2; //右移1位
- }
- DQ=1;
- delay(1);
- }
- /****************DS18B20讀1字節(jié)函數(shù)************************/
- //從總線上取1個字節(jié)
- uchar read_byte(void)
- {
- uchar i;
- uchar value=0;
- for(i=8;i>0;i--)
- {
- DQ=1;_nop_();_nop_();
- value>>=1;
- DQ=0;_nop_();_nop_();_nop_();_nop_(); //4 us
- DQ=1;_nop_();_nop_();_nop_();_nop_(); //4 us
- if(DQ)value|=0x80;
- delay(6); //66 us
- }
- DQ=1;
- return(value);
- }
- /*****************讀出溫度函數(shù)************************/
- read_temp()
- {
- ow_reset(); //總線復(fù)位
- delay(200);
- write_byte(0xcc); //發(fā)命令
- write_byte(0x44); //發(fā)轉(zhuǎn)換命令
- ow_reset();
- delay(1);
- write_byte(0xcc); //發(fā)命令
- write_byte(0xbe);
- temp_data[0]=read_byte(); //讀溫度值的第字節(jié)
- temp_data[1]=read_byte(); //讀溫度值的高字節(jié)
- temp=temp_data[1];
- temp<<=8;
- temp=temp|temp_data[0]; // 兩字節(jié)合成一個整型變量。
- return temp; //返回溫度值
- }
- /****************溫度數(shù)據(jù)處理函數(shù)************************/
- //二進(jìn)制高字節(jié)的低半字節(jié)和低字節(jié)的高半字節(jié)組成一字節(jié),這個
- //字節(jié)的二進(jìn)制轉(zhuǎn)換為十進(jìn)制后,就是溫度值的百、十、個位值,而剩
- //下的低字節(jié)的低半字節(jié)轉(zhuǎn)化成十進(jìn)制后,就是溫度值的小數(shù)部分
- /********************************************************/
- work_temp(uint tem)
- {
- uchar n=0;
- if(tem>6348) // 溫度值正負(fù)判斷
- {tem=65536-tem;n=1;} // 負(fù)溫度求補(bǔ)碼,標(biāo)志位置1
- display[4]=tem&0x0f; // 取小數(shù)部分的值
- display[0]=ditab[display[4]]; // 存入小數(shù)部分顯示值
- display[4]=tem>>4; // 取中間八位,即整數(shù)部分的值
- display[3]=display[4]/100; // 取百位數(shù)據(jù)暫存
- display[1]=display[4]%100; // 取后兩位數(shù)據(jù)暫存
- display[2]=display[1]/10; // 取十位數(shù)據(jù)暫存
- display[1]=display[1]%10; //個位數(shù)據(jù)
- r=display[1]+display[2]*10+display[3]*100;
- /////符號位顯示判斷/////
- if(!display[3])
- {
- display[3]=0x0a; //最高位為0時不顯示
- if(!display[2])
- {
- display[2]=0x0a; //次高位為0時不顯示
- }
- }
- if(n){display[3]=0x0b;} //負(fù)溫度時最高位顯示"-"
- }
- void BEEP()
- {
- if((r>=high&&r<129)||r<low)
- {
- beep=!beep;
- LED=0;
- }
- else
- {
- beep=1;
- LED=1;
- }
- }
- //*********設(shè)置溫度顯示轉(zhuǎn)換************//
- void xianshi(int horl)
- {
- int n=0;
- if(horl>128)
- {
- horl=256-horl;n=1;
- }
- display[3]=horl/100;
- display[3]=display[3]&0x0f;
- display[2]=horl%100/10;
- display[1]=horl%10;
- display[0]=0;
- if(!display[3])
- {
- display[3]=0x0a; //最高位為0時不顯示
- if(!display[2])
- {
- display[2]=0x0a; //次高位為0時不顯示
- }
- }
- if(n)
- {
- display[3]=0x0b; //負(fù)溫度時最高位顯示"-"
- }
- }
- //*********按鍵查詢程序**************//
- void keyscan()
- {
- int temp1; //最高溫度和最低溫度標(biāo)志位
- if(set==0)
- {
- while(1)
- {
- delay(500);//消抖
- if(set==0)
- {
- temp1++;
- while(!set)
- scan();
- }
- if(temp1==1)
- {
- xianshi(high);
- scan();
- if(add==0)
- {
- while(!add)
- scan();
- high+=1;
- }
- if(dec==0)
- {
- while(!dec)
- scan();
- high-=1;
- }
- }
-
- if(temp1==2)
- {
- xianshi(low);
- if(add==0)
- {
- while(!add)
- scan();
- low+=1;
- }
- if(dec==0)
- {
- while(!dec)
- scan();
- low-=1;
- }
- scan();
- }
- if(temp1>=3)
- {
- temp1=0;
- break;
- }
- }
- }
- }
- /****************主函數(shù)************************/
- void main()
- {
-
- dm=0x00; //初始化端口
- w0=1;
- w1=1;
- w2=1;
- w3=1;
- for(h=0;h<4;h++) //開機(jī)顯示"0000"
- {
- display[h]=0;
- }
- ow_reset(); //開機(jī)先轉(zhuǎn)換一次
- write_byte(0xcc); //Skip ROM
- write_byte(0x44); //發(fā)轉(zhuǎn)換命令
- for(h=0;h<100;h++) //開機(jī)顯示"0000"
- {
- scan();
- }
- while(1)
- {
- if (temp1==0)
- {
- work_temp(read_temp()); //處理溫度數(shù)據(jù)
- BEEP();
- scan(); //顯示溫度值
- keyscan();
- }
- else
- keyscan();
- }
- }
復(fù)制代碼
|
評分
-
查看全部評分
|