代码拉取完成,页面将自动刷新
#include<reg52.h>
#include"1602.h"
#include"ds18b20.h"
#define uint unsigned int
#define uchar unsigned char
sbit speaker=P2^0; //定义蜂鸣器
sbit key1=P1^0; //L
sbit key2=P1^1; //H
//定义时间按键
uint tem; //定义采集温度
int htem,htem2,time,time2,x,y,z,dot,dot2; //定义温度、时间
int cnt1=1,cnt2=1,cnt3=1,cnt4=1,cnt5=1,cnt6=1; //定义计数变量
int i;
uchar mode=0; //定义模式变量
uchar code t3[]={" H/L=0/1: C"};
uchar code t4[]={"O/D: C"};
//延时函数
void delay1(uint i)
{
while(i--);
}
//显示函数1
void display(uint dat,uchar add)
{
uchar bai,shi ,ge;
bai=dat/100;
shi=dat%100/10;
ge=dat%10;
writelcd_cmd(add);
writelcd_dat(bai+0x30);
writelcd_dat(shi+0x30);
writelcd_cmd(add+3);
writelcd_dat(ge+0x30);
}
//显示函数2
void display2(uint dat,uchar add)
{
uchar bai,shi ;
bai=dat/100;
shi=dat%100/10;
//ge=dat%10;
writelcd_cmd(add);
writelcd_dat(shi+0x30);
writelcd_dat(bai+0x30);
writelcd_cmd(add+3);
//writelcd_dat(ge+0x30);
}
//显示函数3
void display3(uint dat,uchar add)
{
uchar ge;
//bai=dat/100;
//shi=dat%100/10;
ge=dat%10;
writelcd_cmd(add);
//writelcd_dat(shi+0x30);
//writelcd_dat(bai+0x30);
//writelcd_cmd(add+3);
writelcd_dat(ge+0x30);
}
//按键扫描函数
void keyscan()
{ uchar i,j;
writelcd_cmd(0x80);
for(i=0;i<16;i++)
{writelcd_dat(t3[i]);}
writelcd_cmd(0xc0);
for(j=0;j<16;j++)
{writelcd_dat(t4[j]);}
while(mode!=0)
{
display2(htem,0x8b);
display3(time,0xca);
while(mode!=0)
{
switch(mode)
{
case 1:writelcd_cmd(0xc0+10);writelcd_cmd(0x0f);break;
case 2:writelcd_cmd(0x80+11);writelcd_cmd(0x0f);break;
case 3:writelcd_cmd(0xc0+10);writelcd_cmd(0x0f);break;
default:mode=0;break;
}
if(key2==0&&mode==1)
{
delay(50);
y=0;display3(y,0x80);writelcd_cmd(0xca+11); //max one
if(key2==0)
{
delay(10);
cnt1++;
while(key2==0);
switch(cnt1%11)
{
case 1:time=0;display3(time,0xca);writelcd_cmd(0xca+11);break;
case 2:time=1;display3(time,0xca);writelcd_cmd(0xca+11);break;
case 3:time=2;display3(time,0xca);writelcd_cmd(0xca+11);break;
case 4:time=3;display3(time,0xca);writelcd_cmd(0xca+11);break;
case 5:time=4;display3(time,0xca);writelcd_cmd(0xca+11);break;
case 6:time=5;display3(time,0xca);writelcd_cmd(0xca+11);break;
case 7:time=6;display3(time,0xca);writelcd_cmd(0xca+11);break;
case 8:time=7;display3(time,0xca);writelcd_cmd(0xca+11);break;
case 9:time=8;display3(time,0xca);writelcd_cmd(0xca+11);break;
case 10:time=9;display3(time,0xca);writelcd_cmd(0xca+11);break;
default:break;
}
}
}
if(key1==0&&mode==1)
{
delay(50);
y=1;display3(y,0x80);writelcd_cmd(0xca+11); //min one
if(key1==0)
{
delay(10);
cnt4++;
while(key1==0);
switch(cnt4%11)
{
case 1:time2=0;display3(time2,0xca);writelcd_cmd(0xca+11);break;
case 2:time2=1;display3(time2,0xca);writelcd_cmd(0xca+11);break;
case 3:time2=2;display3(time2,0xca);writelcd_cmd(0xca+11);break;
case 4:time2=3;display3(time2,0xca);writelcd_cmd(0xca+11);break;
case 5:time2=4;display3(time2,0xca);writelcd_cmd(0xca+11);break;
case 6:time2=5;display3(time2,0xca);writelcd_cmd(0xca+11);break;
case 7:time2=6;display3(time2,0xca);writelcd_cmd(0xca+11);break;
case 8:time2=7;display3(time2,0xca);writelcd_cmd(0xca+11);break;
case 9:time2=8;display3(time2,0xca);writelcd_cmd(0xca+11);break;
case 10:time2=9;display3(time2,0xca);writelcd_cmd(0xca+11);break;
default:break;
}
}
}
if(key2==0&&mode==2)
{
delay(10);
x=00;display2(x,0x80);writelcd_cmd(0x80+11); //max ten
if(key2==0)
{
cnt2++;
while(key2==0);
switch(cnt2%11)
{
case 1:htem=00;display2(htem,0x8b);writelcd_cmd(0x80+11);break;
case 2:htem=10;display2(htem,0x8b);writelcd_cmd(0x80+11);break;
case 3:htem=20;display2(htem,0x8b);writelcd_cmd(0x80+11);break;
case 4:htem=30;display2(htem,0x8b);writelcd_cmd(0x80+11);break;
case 5:htem=40;display2(htem,0x8b);writelcd_cmd(0x80+11);break;
case 6:htem=50;display2(htem,0x8b);writelcd_cmd(0x80+11);break;
case 7:htem=60;display2(htem,0x8b);writelcd_cmd(0x80+11);break;
case 8:htem=70;display2(htem,0x8b);writelcd_cmd(0x80+11);break;
case 9:htem=80;display2(htem,0x8b);writelcd_cmd(0x80+11);break;
case 10:htem=90;display2(htem,0x8b);writelcd_cmd(0x80+11);break;
default:break;
}
}
}
if(key1==0&&mode==2)
{
delay(10);
x=10;display2(x,0x80);writelcd_cmd(0x80+11); //min ten
if(key1==0)
{
cnt3++;
while(key1==0);
switch(cnt3%11)
{
case 1:htem2=00;display2(htem2,0x8b);writelcd_cmd(0x80+11);break;
case 2:htem2=10;display2(htem2,0x8b);writelcd_cmd(0x80+11);break;
case 3:htem2=20;display2(htem2,0x8b);writelcd_cmd(0x80+11);break;
case 4:htem2=30;display2(htem2,0x8b);writelcd_cmd(0x80+11);break;
case 5:htem2=40;display2(htem2,0x8b);writelcd_cmd(0x80+11);break;
case 6:htem2=50;display2(htem2,0x8b);writelcd_cmd(0x80+11);break;
case 7:htem2=60;display2(htem2,0x8b);writelcd_cmd(0x80+11);break;
case 8:htem2=70;display2(htem2,0x8b);writelcd_cmd(0x80+11);break;
case 9:htem2=80;display2(htem2,0x8b);writelcd_cmd(0x80+11);break;
case 10:htem2=90;display2(htem2,0x8b);writelcd_cmd(0x80+11);break;
default:break;
}
}
}
if(key2==0&&mode==3)
{
delay(50);
z=00;display2(z,0x80);writelcd_cmd(0x80+11); //max dot
if(key2==0)
{
delay(10);
cnt5++;
while(key2==0);
switch(cnt5%11)
{
case 1:dot=0;display3(dot,0xca);writelcd_cmd(0xca+11);break;
case 2:dot=1;display3(dot,0xca);writelcd_cmd(0xca+11);break;
case 3:dot=2;display3(dot,0xca);writelcd_cmd(0xca+11);break;
case 4:dot=3;display3(dot,0xca);writelcd_cmd(0xca+11);break;
case 5:dot=4;display3(dot,0xca);writelcd_cmd(0xca+11);break;
case 6:dot=5;display3(dot,0xca);writelcd_cmd(0xca+11);break;
case 7:dot=6;display3(dot,0xca);writelcd_cmd(0xca+11);break;
case 8:dot=7;display3(dot,0xca);writelcd_cmd(0xca+11);break;
case 9:dot=8;display3(dot,0xca);writelcd_cmd(0xca+11);break;
case 10:dot=9;display3(dot,0xca);writelcd_cmd(0xca+11);break;
default:break;
}
}
}
if(key1==0&&mode==3)
{
delay(50);
z=10;display2(z,0x80);writelcd_cmd(0x80+11); //min dot
if(key1==0)
{
delay(10);
cnt6++;
while(key1==0);
switch(cnt6%11)
{
case 1:dot2=0;display3(dot2,0xca);writelcd_cmd(0xca+11);break;
case 2:dot2=1;display3(dot2,0xca);writelcd_cmd(0xca+11);break;
case 3:dot2=2;display3(dot2,0xca);writelcd_cmd(0xca+11);break;
case 4:dot2=3;display3(dot2,0xca);writelcd_cmd(0xca+11);break;
case 5:dot2=4;display3(dot2,0xca);writelcd_cmd(0xca+11);break;
case 6:dot2=5;display3(dot2,0xca);writelcd_cmd(0xca+11);break;
case 7:dot2=6;display3(dot2,0xca);writelcd_cmd(0xca+11);break;
case 8:dot2=7;display3(dot2,0xca);writelcd_cmd(0xca+11);break;
case 9:dot2=8;display3(dot2,0xca);writelcd_cmd(0xca+11);break;
case 10:dot2=9;display3(dot2,0xca);writelcd_cmd(0xca+11);break;
default:break;
}
}
}
}
}
lcd_init();
}
//中断初始化函数
void init()
{
lcd_init(); //lcd初始化
speaker=1;
mode=0;
htem=80;
time=0;
htem2=20;
time2=0;
dot=0;
dot2=0;
EA=1; //总中断开启
EX0=1; //外部中断0允许
ET0=1; //定时器0允许
TMOD=0X01; //定时中断0,模式1
IT0=1; //下降沿触发
TH0=0Xee; //0.5us
TL0=0X00;
//TR0=0;
}
//主函数
void main()
{
init(); //中断初始化
while(1)
{
if(mode!=0)
{keyscan();}
else if(mode==0)
{
delay(100);
tmpchange();
tem=tmp(); //温度值获取
if(tem>=(htem*10+time*10+dot)) //高于设定温度
{
TR0=1; //中断开启
}
else if(tem<=(htem2*10+time2*10+dot2)) //高于设定温度
{
TR0=1; //中断开启
}
else //低于设定温度
{
TR0=0; //中断关闭
//报警灯灭
}
delay(10);
display(tem,0xca);
delay(100);
TR0=0;
}
}
}
//外部中断服务函数
void exter()interrupt 0
{
delay(50); //按键消抖
if(P1^2==0)
mode++;
mode=mode%5 ; //每按4次置0
}
//定时中断服务函数
void timer0()interrupt 1
{
TH0=0Xee; //重装载
TL0=0X00;
delay(200);
speaker=~speaker;delay1(1); //蜂鸣器报警
TR0=0; //定时中断关闭
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。