基于热敏电阻的温度传感器
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
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);//保存上限值
{
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);
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(" ");
sbit LCD1602_rs=P1^6;//IO定义
//sbit LCD1602_rw=P2^6;
sbit LCD1602_e=P1^7;
sbit beep=P1^0;
sbit led_1=P2^5;
sbit led_2=P2^6;
sbit key_1=P1^1;
sbit key_2=P1^2;
sbit key_3=P1^3;
Rx = Rx + Revise;
return Rx;
}
void main()
{
float Rad;
LCD1602_cls();
TMOD=0x01;
TH0=0x4c;
TL0=0x00;
ET0=1;
TR0=1;
EA=1;
temp_h=byte_read(0x2000);
temp_l=byte_read(0x2200);
sbit TCL2543_EOC = P3^3;
sbit TCL2543_CLK = P3^4;
sbit TCL2543_ADIN = P3^5;
sbit TCL2543_DOUT = P3^6;
sbit TCL2543_CS = P3^7;
float zhi;
int shu;
char temp,temp_h,temp_l;
{
/*
Rx:热敏电阻当前阻值
B:热敏电阻参数B值
Revise:校正温度
BasicRx:热敏电阻25度时电阻(标称电阻数值)
返回:摄氏度
*/
Rx = Rx / BasicRx;
Rx = log(Rx);
Rx = (Rx) / B;
Rx = Rx + 0.003356;
Rx = 1 / Rx;
Rx = Rx - 273.13;
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(" ");
show();//显示函数
key();//按键处理程序
proc();//超限处理程序
}
}
void UART_1() interrupt 1
{
TH0=0x4c;
TL0=0x00;
ms++;
if(ms%5==0)
{
s1=!s1;
if(beep1==1) beep=!beep;
elsebeep=1;
}
if(ms>19)
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);//保存上限值
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);
delay(1500);
LCD1602_write(0,0x0c); //设置光标不显示开关、不显示光标、字符不闪烁
LCD1602_write(0,0x06);
LCD1602_write(0,0xd0);
delay(1500);
}
//-40到105
void show()//显示数据
{
LCD1602_write(0,0x80);
{
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点阵
#include<reg52.h>//头文件
#include<intrins.h>
#include"eeprom52.h"
#include "math.h"
#define uchar unsigned char//宏定义
#define uint unsigned int
#define LCD1602_dat P0
}
}
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)
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);
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(" ");
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)
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)
{
ms=0;
}
}
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);
if(temp_h>99||temp_l>99||temp_l>=temp_h)
{
temp_h=30;
temp_l=10;
}
while(1)
{
zhi=(float)read2543(0)/819.0;
Rad=zhi/((5.0-zhi)/10000.0);
temp=(int)(temp * 0.5) + (TempCalculate(Rad,3950.0,0,10000.0) * 0.5);
}
}
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);
{
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();
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一个字节处理
{
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字符串处理
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);//保存上限值
{
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);
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(" ");
sbit LCD1602_rs=P1^6;//IO定义
//sbit LCD1602_rw=P2^6;
sbit LCD1602_e=P1^7;
sbit beep=P1^0;
sbit led_1=P2^5;
sbit led_2=P2^6;
sbit key_1=P1^1;
sbit key_2=P1^2;
sbit key_3=P1^3;
Rx = Rx + Revise;
return Rx;
}
void main()
{
float Rad;
LCD1602_cls();
TMOD=0x01;
TH0=0x4c;
TL0=0x00;
ET0=1;
TR0=1;
EA=1;
temp_h=byte_read(0x2000);
temp_l=byte_read(0x2200);
sbit TCL2543_EOC = P3^3;
sbit TCL2543_CLK = P3^4;
sbit TCL2543_ADIN = P3^5;
sbit TCL2543_DOUT = P3^6;
sbit TCL2543_CS = P3^7;
float zhi;
int shu;
char temp,temp_h,temp_l;
{
/*
Rx:热敏电阻当前阻值
B:热敏电阻参数B值
Revise:校正温度
BasicRx:热敏电阻25度时电阻(标称电阻数值)
返回:摄氏度
*/
Rx = Rx / BasicRx;
Rx = log(Rx);
Rx = (Rx) / B;
Rx = Rx + 0.003356;
Rx = 1 / Rx;
Rx = Rx - 273.13;
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(" ");
show();//显示函数
key();//按键处理程序
proc();//超限处理程序
}
}
void UART_1() interrupt 1
{
TH0=0x4c;
TL0=0x00;
ms++;
if(ms%5==0)
{
s1=!s1;
if(beep1==1) beep=!beep;
elsebeep=1;
}
if(ms>19)
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);//保存上限值
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);
delay(1500);
LCD1602_write(0,0x0c); //设置光标不显示开关、不显示光标、字符不闪烁
LCD1602_write(0,0x06);
LCD1602_write(0,0xd0);
delay(1500);
}
//-40到105
void show()//显示数据
{
LCD1602_write(0,0x80);
{
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点阵
#include<reg52.h>//头文件
#include<intrins.h>
#include"eeprom52.h"
#include "math.h"
#define uchar unsigned char//宏定义
#define uint unsigned int
#define LCD1602_dat P0
}
}
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)
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);
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(" ");
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)
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)
{
ms=0;
}
}
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);
if(temp_h>99||temp_l>99||temp_l>=temp_h)
{
temp_h=30;
temp_l=10;
}
while(1)
{
zhi=(float)read2543(0)/819.0;
Rad=zhi/((5.0-zhi)/10000.0);
temp=(int)(temp * 0.5) + (TempCalculate(Rad,3950.0,0,10000.0) * 0.5);
}
}
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);
{
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();
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一个字节处理
{
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字符串处理