|
基于單片機的熱敏電阻測溫設計完整版包含文檔、硬件電路搭建以及仿真結果。
元件清單:
P1 LCD1602液晶顯示屏+16P插座
PR1 103排阻
Q1 8550三極管
R1, R5 10K電阻
R2, R6, R7 1K電阻
R3 熱敏電阻 帶線+2P白色插頭
R4 電位器
SW1 自鎖開關
U1 TLC2543芯片+DIP20插座
U2 STC89C52單片機+DIP40插座
Y1 12M晶振
9*15板子
錫絲
導線
USB供電線或者電池盒
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei.png (18.21 KB, 下載次數(shù): 69)
下載附件
2021-3-10 18:36 上傳
Altium Designer畫的原理圖和PCB圖如下:(51hei附件中可下載工程文件)
51hei.png (30.29 KB, 下載次數(shù): 70)
下載附件
2021-3-10 17:16 上傳
51hei.png (49.37 KB, 下載次數(shù): 77)
下載附件
2021-3-10 17:16 上傳
單片機源程序如下:
- #include<reg52.h> //頭文件
- #include<intrins.h>
- #include"eeprom52.h"
- #include "math.h"
- #define uchar unsigned char //宏定義
- #define uint unsigned int
- #define LCD1602_dat P0
- sbit LCD1602_rs=P2^5;//IO 定義
- sbit LCD1602_rw=P2^6;
- sbit LCD1602_e=P2^7;
- sbit beep=P2^0;
- sbit led_1=P1^5;
- sbit led_2=P1^6;
- sbit key_1=P3^5;
- sbit key_2=P3^6;
- sbit key_3=P3^7;
- sbit TCL2543_EOC = P1^0;
- sbit TCL2543_CLK = P1^1;
- sbit TCL2543_ADIN = P1^2;
- sbit TCL2543_DOUT = P1^3;
- sbit TCL2543_CS = P1^4;
- float zhi;
- int shu;
- char temp,temp_h,temp_l;
- uchar state,ms;
- bit s1,beep1;
- void delay(uint T)
- {
- while(T--);
- }
- // 其中 port 為通道: 通道0:port = 0x01 通道1:port = 0x02 通道2:port = 0x04 ...
- uint read2543(unsigned char port)
- {
- unsigned int i;
- uint ad_value=0;
- TCL2543_CLK=0;
- TCL2543_CS=0;
- TCL2543_EOC=1;
- port<<=4;
- for(i=0;i<12;i++)
- {
- if(TCL2543_DOUT) ad_value|=0x01;
- TCL2543_ADIN=(bit)(port&0x80);
- TCL2543_CLK=1;
- _nop_();
- _nop_();
- _nop_();
- TCL2543_CLK=0;
- _nop_();
- _nop_();
- _nop_();
- port=port<<1;
- ad_value=ad_value<<1;
- }
- TCL2543_CS=1;
- ad_value=ad_value>>1;
- return ad_value;
- }
- void LCD1602_write(uchar order,dat) //1602 一個字節(jié) 處理
- {
- LCD1602_e=0;
- LCD1602_rs=order;
- LCD1602_dat=dat;
- LCD1602_rw=0;
- LCD1602_e=1;
- delay(1);
- LCD1602_e=0;
- }
- void LCD1602_writebyte(uchar *prointer) //1602 字符串 處理
- {
- while(*prointer!='\0')
- {
- LCD1602_write(1,*prointer);
- prointer++;
- }
- }
- void LCD1602_cls() //1602 初始化
- {
- LCD1602_write(0,0x01); //1602 清屏 指令
- delay(1500);
- LCD1602_write(0,0x38); // 功能設置 8位、5*7點陣
- delay(1500);
- LCD1602_write(0,0x0c); //設置 光標 不顯示開關、不顯示光標、字符不閃爍
- LCD1602_write(0,0x06);
- LCD1602_write(0,0xd0);
- delay(1500);
- }
- void show() //顯示數(shù)據(jù)
- {
- LCD1602_write(0,0x80);
- LCD1602_writebyte("Temp:");
- if(temp>=0)
- {
- if(temp>99)LCD1602_write(1,0x30+temp/100%10);
- else LCD1602_writebyte(" ");
- if(temp>9)LCD1602_write(1,0x30+temp/10%10);
- else LCD1602_writebyte(" ");
- LCD1602_write(1,0x30+temp%10);
- }else
- {
- LCD1602_writebyte("-");
- if(temp*-1>9)LCD1602_write(1,0x30+(temp*-1)/10%10);
- else LCD1602_writebyte(" ");
- LCD1602_write(1,0x30+(temp*-1)%10);
- }
- LCD1602_write(1,0xdf);
- LCD1602_writebyte("C ");
- LCD1602_write(0,0xC0);
- LCD1602_writebyte("H:");
- if(state==1&&s1==1)
- {
- LCD1602_writebyte(" ");
- }else
- {
- if(temp_h>=0)
- {
- if(temp_h>99)LCD1602_write(1,0x30+temp_h/100%10);
- else LCD1602_writebyte(" ");
- if(temp_h>9)LCD1602_write(1,0x30+temp_h/10%10);
- else LCD1602_writebyte(" ");
- LCD1602_write(1,0x30+temp_h%10);
- }else
- {
- LCD1602_writebyte("-");
- if(temp_h*-1>9)LCD1602_write(1,0x30+(temp_h*-1)/10%10);
- else LCD1602_writebyte(" ");
- LCD1602_write(1,0x30+(temp_h*-1)%10);
- }
- }
- LCD1602_write(1,0xdf);
- LCD1602_writebyte("C L:");
- if(state==2&&s1==1)
- {
- LCD1602_writebyte(" ");
- }else
- {
- // LCD1602_write(1,0x30+temp_l/10%10);
- // LCD1602_write(1,0x30+temp_l%10);
- if(temp_l>=0)
- {
- if(temp_l>99)LCD1602_write(1,0x30+temp_l/100%10);
- else LCD1602_writebyte(" ");
- if(temp_l>9)LCD1602_write(1,0x30+temp_l/10%10);
- else LCD1602_writebyte(" ");
- LCD1602_write(1,0x30+temp_l%10);
- }else
- {
- LCD1602_writebyte("-");
- if(temp_l*-1>9)LCD1602_write(1,0x30+(temp_l*-1)/10%10);
- else LCD1602_writebyte(" ");
- LCD1602_write(1,0x30+(temp_l*-1)%10);
- }
- }
- LCD1602_write(1,0xdf);
- LCD1602_writebyte("C");
-
- }
- void proc()
- {
- if(temp>temp_h)
- {
- led_1=0;
- }else
- {
- led_1=1;
- }
- if(temp<temp_l)
- {
- led_2=0;
- }else
- {
- led_2=1;
- }
- if(temp>temp_h||temp<temp_l)
- {
- beep1=1;
- }else
- {
- beep1=0;
- }
- }
- void key()
- {
- if(!key_1)
- {
- delay(888);
- if(!key_1)
- {
- state=(state+1)%3;
- while(!key_1);
- }
- }
- if(state!=0)
- {
- if(!key_2)
- {
- delay(888);
- if(!key_2)
- {
- while(!key_2) show();
- switch(state)
- {
- case 1:
- if(temp_h<99)temp_h++;
- SectorErase(0x2000); //保存上限值
- byte_write(0x2000,temp_h);
- break;
- case 2:
- if(temp_h>temp_l+1)temp_l++;
- SectorErase(0x2200); //保存上限值
- byte_write(0x2200,temp_l);
- break;
- }
- }
- }
- if(!key_3)
- {
- delay(888);
- if(!key_3)
- {
- while(!key_3) show();
- switch(state)
- {
- case 1:
- if(temp_h>temp_l+1)temp_h--;
- SectorErase(0x2000); //保存上限值
- byte_write(0x2000,temp_h);
- break;
- case 2:
- if(temp_l>-40)temp_l--;
- SectorErase(0x2200); //保存上限值
- byte_write(0x2200,temp_l);
- break;
- }
- }
- }
- }
- }
- float TempCalculate(float Rx,float B,float Revise,float BasicRx)
- {
- /*
- Rx: 熱敏電阻當前阻值
- B: 熱敏電阻參數(shù)B值
- Revise: 校正溫度
- BasicRx: 熱敏電阻25度時電阻(標稱電阻數(shù)值)
- 返回: 攝氏度
- */
- Rx = Rx / BasicRx;
-
- Rx = log(Rx);
-
- Rx = (Rx) / B;
-
- Rx = Rx + 0.003356;
- Rx = 1 / Rx;
- Rx = Rx - 273.13;
- Rx = Rx + Revise;
-
-
- return Rx;
-
- }
- void main()
- {
- float Rad;
- LCD1602_cls();
- TMOD=0x01;
- TH0=0x4c;
- TL0=0x00;
- ET0=1;
- TR0=1;
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
|
-
1.png
(18.42 KB, 下載次數(shù): 109)
下載附件
2021-3-10 15:05 上傳
-
2.png
(50.38 KB, 下載次數(shù): 119)
下載附件
2021-3-10 15:05 上傳
-
4.png
(30.36 KB, 下載次數(shù): 144)
下載附件
2021-3-10 15:05 上傳
-
-
熱敏電阻.7z
2021-3-10 19:34 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
2.86 MB, 下載次數(shù): 101, 下載積分: 黑幣 -5
評分
-
查看全部評分
|