#include"STC89C51RC.H"
#include<absacc.h>
#include"ds18b20.h"
#include"lcd1602.h"
#include"ds1302.h"
#include"2402.h"
uchar data datadis[]={0x00,0x00,0x00,0x00,0x00};
uint temp=0;
sbit K1=P3^5;
sbit K2=P3^4;
sbit K3=P3^3;
sbit K4=P3^2;
sbit K5=P3^0;
sbit L1=P1^6;
sbit speaker=P1^0;
uchar keynum=1,flag,flag1,flag2,adder,q;
uint k,count,th,tl;
uchar th1=8;
uchar th2=5;
uchar th3=2;
uchar th4=0;
uchar tab,w;
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
uchar key4()
{
if(K4==0)
{
delay(5);
if(K4==0)
{
while(!K4);
keynum++;
if(keynum==5)keynum=1;
}
}
return keynum;
}
void key_lcd()
{
if(flag1==1&&k==3) //k一定不能掉,不然会在其他菜单里出现乱码
{
if(K3==0) //按键判断,选择设置温度的光标
{
delay(5);
if(K3==0)
{
while(!K3);
flag++; //按键标识位
if(flag==5)flag=1;
}
}
switch(flag)
{
case 1:
{
if(K1==0)
{
delay(5);
if(K1==0)
{
th1++;
while(!K1);
if(th1==10)th1=0;
}
}
if(K2==0)
{
delay(5);
if(K2==0)
{
th1--;
while(!K2);
if(th1==-1)th1=9;
}
}
write_cmd(0xc3);
write_dat(th1+0x30);
}break;
case 2:
{
if(K1==0)
{
delay(5);
if(K1==0)
{
th2++;
while(!K1);
if(th2==10)th2=0;
}
}
if(K2==0)
{
delay(5);
if(K2==0)
{
th2--;
while(!K2);
if(th2==-1)th2=9;
}
}
write_cmd(0xc4);
write_dat(th2+0x30);
}break;
case 3:
{
if(K1==0)
{
delay(5);
if(K1==0)
{
th3++;
while(!K1);
if(th3==10)th3=0;
}
}
if(K2==0)
{
delay(5);
if(K2==0)
{
th3--;
while(!K2);
if(th3==-1)th3=9;
}
}
write_cmd(0xcb);
write_dat(th3+0x30);
}break;
case 4:
{
if(K1==0)
{
delay(5);
if(K1==0)
{
th4++;
while(!K1);
if(th4==10)th4=0;
}
}
if(K2==0)
{
delay(5);
if(K2==0)
{
th4--;
while(!K2);
if(th4==-1)th4=9;
}
}
write_cmd(0xcc);
write_dat(th4+0x30);
}break;
default:break;
}
}
else flag1=0; //m一定不能掉,否则在调节温度的时候会影响其他菜单
th=th1*10+th2; //获取设置温度的高位
tl=th3*10+th4; //获取设置温度的低位
}
void alarm_speaker() //报警系统与当前温度进行比较并处理
{
if(temp>(th*10)||temp<(tl*10))
{
speaker=~speaker;
L1=0;
adder++;
tab=temp/10;
write_add(adder,tab);
}
else
{
speaker=1;
L1=1;
}
}
void main()
{
systemtime realtime;
init_18b20();
init_lcd();
init_2402();
speaker=1;
while(1)
{
k=key4();
get_ds1302(&realtime);//取时间
temp=read_temp(); //取温度
delay(200); //延时 保持数据稳定 避免数据刷新
switch(k)
{
case 1: //菜单一,显示时间
{
write_cmd(0x80);
print(" Time: ");
print(realtime.TimeString);
write_cmd(0xc0);
print(" Date: ");
print(realtime.DateString);
} break;
case 2: //菜单二,显示温度
{
write_cmd(0x80);
print(" DS18B20 is OK ");
write_cmd(0xc0);
print("NOW TEMP: . C ");
if(flagt==1)datadis[0]=0x2d;
else datadis[0]=temp/1000+0x30;
datadis[1]=temp/100%10+0x30;
datadis[2]=temp/10%10+0x30;
datadis[3]=0x2e;
datadis[4]=temp%10+0x30;
write_cmd(0xca);
print(datadis);
}break;
case 3: //菜单三,显示温度设置值
{
write_cmd(0x80);
print(" change temp: ");
write_cmd(0xc0);
print("TH= TL= ");
write_cmd(0xc3);
write_dat(th1+0x30);
write_cmd(0xc4);
write_dat(th2+0x30);
write_cmd(0xc5);
write_dat(0xdf); //摄氏度远点
write_cmd(0xc6);
write_dat(0x43);
write_cmd(0xcb);
write_dat(th3+0x30);
write_cmd(0xcc);
write_dat(th4+0x30);
write_cmd(0xcd); //摄氏度符号
write_dat(0xdf);
write_cmd(0xce);
write_dat(0x43);
flag1=1;
}break;
case 4: //菜单四,记录报警温度
{
write_cmd(0x80);
print(" ALARM TEMP ");
write_cmd(0xc0);
print(" RECORD: ");
write_cmd(0xcb);
write_dat(0xdf);
write_cmd(0xcc);
write_dat(0x43);
flag2=1;
}break;
default:break;
}
key_lcd(); //菜单三中温度设置的按键扫描
alarm_speaker(); //报警系统通过2402存储超出的温度,并记录
if(K5==0) //按下K5,就显示当前报警的温度
{
delay(5);
if(K5==0)
{
while(!K5);
q=read_add(adder);
}
};
if(flag2==1&&k==4) //k一定不能掉,不然会在其他菜单里出现乱码,菜单四中需要显示存储的报警数据
{
write_cmd(0xc9);
write_dat(q/10%10+0x30);
write_cmd(0xca);
write_dat(q%10+0x30);
}
}
}
单片机可设置温度上下限的温控
5星 · 超过95%的资源 需积分: 21 194 浏览量
2013-03-12
13:35:23
上传
评论 6
收藏 123KB RAR 举报
四夕立羽
- 粉丝: 1w+
- 资源: 275
最新资源
- 数据库建设基本流程.doc
- 基于 C 的冒泡排序和选择排序两种基础的算法
- 数据库系统概论——实体联系模型、ER图-PPT.ppt
- 用文字描述一个典型的卷积神经网络(Convolutional Neural Network, CNN)的结构图.txt
- 冒泡排序(Bubble Sort)是一种简单的排序算法,它重复地遍历要排序的数列.txt
- 基于android5.1适配Rk3288系统的人脸声纹识别系统源码.zip
- 基于Tensorflow架构深度学习声纹识别系统python源码+预训练模型.zip
- 自定义用于读取matlab数据的类,仿照pytorch设计.zip
- 使用Matlab来对通信系统和通信信号进行仿真 对相关算法进行验证 .zip
- 使用Matlab对单频激光倍频的仿真.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页