|
#include "reg52.h"
#include "1602.h"
#include "delay.h"
#include "18b20.h"
sbit key1=P3^4;
sbit key2=P3^5;
sbit key3=P3^6;
sbit key4=P3^7;
sbit host=P2^3;
sbit buzz=P2^7;
unsigned char page;
unsigned char fresh;
unsigned char tempsetflag;
unsigned char updownflag;
unsigned char ss;
unsigned char set=20;
unsigned char up=50;
unsigned char down=10;
unsigned char temp;
void Init_Timer0(void)
{
TMOD |= 0x01; //使用模式1,16位定时器,使用"|"符号可以在使用多个定时器时不受影响
EA=1; //总中断打开
ET0=1; //定时器中断打开
TR0=1; //定时器开关打开
}
void main()
{
LCD_Init();
Init_DS18B20();
ReadTemperature();
DelayMs(500);
ReadTemperature();
DelayMs(500);
ReadTemperature();
DelayMs(500);
Init_Timer0();
while(1)
{
if(fresh)
{
fresh=0;
temp=ReadTemperature();
if(temp<set)host=0;
else host=1;
if(temp>=up)buzz=0;
else if(temp<down)buzz=0;
else buzz=1;
if(page==0)
{
LCD_Write_String(0,0,"TEMPTURE:");
LCD_Write_Tmp(9,0,temp);
LCD_Write_Data(0xdf);
LCD_Write_Data(0x43);
LCD_Write_String(0,1,"SET:");
LCD_Write_Tmp(5,1,set);
LCD_Write_Data(0xdf);
LCD_Write_Data(0x43);
if(tempsetflag)
{
if(ss)LCD_Write_String(5,1," ");
ss=!ss;
}
}
else if(page==1)
{
LCD_Write_String(0,0,"UP:");
LCD_Write_Tmp(6,0,up);
LCD_Write_Data(0xdf);
LCD_Write_Data(0x43);
LCD_Write_String(0,1,"DOWN:");
LCD_Write_Tmp(6,1,down);
LCD_Write_Data(0xdf);
LCD_Write_Data(0x43);
if(ss)LCD_Write_String(6,0," ");
ss=!ss;
}
else if(page==2)
{
LCD_Write_String(0,0,"UP:");
LCD_Write_Tmp(6,0,up);
LCD_Write_Data(0xdf);
LCD_Write_Data(0x43);
LCD_Write_String(0,1,"DOWN:");
LCD_Write_Tmp(6,1,down);
LCD_Write_Data(0xdf);
LCD_Write_Data(0x43);
if(ss)LCD_Write_String(6,1," ");
ss=!ss;
}
}
}
}
void Timer0_isr(void) interrupt 1
{
static unsigned int num;
static unsigned char key1num;//按键一按下标志
static unsigned char key2num;//按键二按下标志
static unsigned char key3num;//按键三按下标志
static unsigned char key4num;//按键四按下标志
TH0=(65536-2000)/256; //重新赋值 2ms
TL0=(65536-2000)%256;
num++;
if(num==250) //大致100ms
{
num=0;
fresh=1;
}
if(key1==0)key1num=1;//设定设定温度
else if(key1num==1)
{
key1num=0;
if(page==0)tempsetflag=!tempsetflag;//只有在界面一才可以调节
}
if(key2==0)key2num=1;//上下限设定
else if(key2num==1)
{
key2num=0;
if(!tempsetflag)//只有非设置设置温度的时候才可以
{
page++;
LCD_Init();
if(page==3)page=0;
}
}
if(key3==0)key3num=1;//温度加
else if(key3num==1)
{
key3num=0;
if((page==0)&&(tempsetflag))if(set<up)set++;//只有在设置设置温度时才可以调节
if(page==1)if(up<99)up++;
if(page==2)if(down<up)down++;
}
if(key4==0)key4num=1;//温度减
else if(key4num==1)
{
key4num=0;
if((page==0)&&(set>down))set--;
if(page==1)if(up>down)up--;
if(page==2)if(down>0)down--;
}
}
|
|