#include "public.h"
#include "lcd.h"
#include "temp.h"
#include "i2c.h"
sbit k3=P3^2; //设置温度上下限
sbit k1=P3^4; //加
sbit k2=P3^5; //减
sbit ledL=P1^0;
sbit ledH=P1^1;
sbit led=P2^4; //电源指示灯
sbit beep=P1^5; //蜂鸣器报警
sbit relay=P1^4; //加热或散热设备
char set_templ=22,set_temph=40; //设定温度上下限默认值
u16 temp_val; //检测的实际温度
u8 mode; //温度模式
void Temp_DataPros()
{
short temp;
u8 temp_buf[5];
temp=Ds18b20ReadTemp();
temp_val=temp;
if(temp<0)
{
temp=-temp;
LCD_Dispstring(2+5,0,"-");
}
else
{
LCD_Dispstring(2+5,0," ");
}
temp_buf[0]=temp/100+0x30;
temp_buf[1]=temp%100/10+0x30;
temp_buf[2]='.';
temp_buf[3]=temp%100%10+0x30;
temp_buf[4]='\0';
LCD_Dispstring(2+6,0,temp_buf); //显示检测的温度xx.x
temp_buf[0]=set_temph/10+0x30;
temp_buf[1]=set_temph%10+0x30;
temp_buf[2]='\0';
LCD_Dispstring(5,1,temp_buf); //显示设定的温度上限值xx
temp_buf[0]=set_templ/10+0x30;
temp_buf[1]=set_templ%10+0x30;
temp_buf[2]='\0';
LCD_Dispstring(14,1,temp_buf); //显示设定的温度下限值xx
}
#define K1_MODE 1
#define K2_ADD 2
#define K3_DEC 3
//mode: 0-单次扫描 1-连续扫描
u8 KEY_Scan(u8 mode)
{
static u8 key=1;
if(key&&(k1==0||k2==0||k3==0))
{
delay(1000); //消抖
key=0;
if(k3==0)
{
return K1_MODE;
}
else if(k1==0)
{
return K2_ADD;
}
else if(k2==0)
{
return K3_DEC;
}
}
else if(k1==1&&k2==1&&k3==1)
{
key=1;
}
if(mode)
{
key=1;
}
return 0;
}
void KEY_Pros()
{
u8 key;
u8 temph_buf[3];
key=KEY_Scan(0);
if(key==K1_MODE) //模式选择
{
mode++;
LCD_Clear();
if(mode==1)
{
LCD_Dispstring(0,0,"SETH: C");
}
else if(mode==2)
{
LCD_Dispstring(0,1,"SETL: C");
}
else
{
mode=0;
LCD_Dispstring(2,0,"Temp: C");
LCD_Dispstring(0,1,"SETH: ");
LCD_Dispstring(9,1,"SETL: ");
}
}
if(mode==1) //温度上限设置
{
switch(key)
{
case K2_ADD: //加
set_temph++;
if(set_temph>=80)set_temph=80;
break;
case K3_DEC: //减
set_temph--;
if(set_temph<=0)set_temph=0;
break;
}
temph_buf[0]=set_temph/10+0x30;
temph_buf[1]=set_temph%10+0x30;
temph_buf[2]='\0';
LCD_Dispstring(6,0,temph_buf);
At24c02Write(0,set_temph);
}
else if(mode==2) //温度下限设置
{
switch(key)
{
case K2_ADD: //加
set_templ++;
if(set_templ>=80)set_templ=80;
break;
case K3_DEC: //减
set_templ--;
if(set_templ<=0)set_templ=0;
break;
}
temph_buf[0]=set_templ/10+0x30;
temph_buf[1]=set_templ%10+0x30;
temph_buf[2]='\0';
LCD_Dispstring(6,1,temph_buf);
At24c02Write(2,set_templ);
}
}
void sound()
{
u8 i=50;
while(i--)
{
beep=!beep;
delay(10);
}
}
void TempData_Compare()
{
if(temp_val>set_temph*10) //实际温度高于上限值 报警
{
relay=0;
ledH=0;
ledL=1;
sound();
}
else if(temp_val<set_templ*10) //实际温度低于下限值 报警
{
relay=0;
ledH=1;
ledL=0;
sound();
}
else //实际温度在下限值和上限值之间 取消报警 取消加热 取消散热
{
ledH=1;
ledL=1;
relay=1;
}
}
void kai_display()
{
if(At24c02Read(255)!=18)
{
At24c02Write(0,set_temph);
At24c02Write(2,set_templ);
At24c02Write(255,18);
}
else
{
set_temph=At24c02Read(0);
set_templ=At24c02Read(2);
}
LCD_Dispstring(2,0,"Temp: C");
LCD_Dispstring(0,1,"SETH: ");
LCD_Dispstring(9,1,"SETL: ");
}
void main()
{
ledH=1;
ledL=1;
relay=1;
led=0;
LCD_Init();
kai_display();
while(1)
{
if(mode==0)
Temp_DataPros();
KEY_Pros();
TempData_Compare();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温度报警工程文件免费下载
共30个文件
obj:5个
c:5个
lst:5个
需积分: 0 59 下载量 10 浏览量
2022-04-07
16:27:35
上传
评论 4
收藏 36KB 7Z 举报
温馨提示
温度报警工程文件免费下载
资源详情
资源评论
资源推荐
收起资源包目录
温度报警.7z (30个子文件)
main.OBJ 12KB
public.c 62B
project.uvopt 6KB
lcd.c 3KB
main.c 4KB
lcd.h 460B
i2c.c 2KB
project.M51 35KB
main.LST 9KB
project.hex 7KB
temp.c 2KB
project.uvgui.Lenovo 85KB
project.plg 3KB
i2c.OBJ 6KB
i2c.LST 5KB
lcd.OBJ 7KB
temp.h 312B
i2c.h 322B
project 27KB
project_uvopt.bak 56KB
temp.OBJ 6KB
public.LST 898B
lcd.LST 7KB
project_uvproj.bak 14KB
public.h 152B
public.OBJ 1KB
project.lnp 80B
temp.LST 5KB
project.uvproj 14KB
project.build_log.htm 1KB
共 30 条
- 1
快乐学习的每一天
- 粉丝: 7722
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0