保温杯厂家
免费服务热线

Free service

hotline

010-00000000
保温杯厂家
热门搜索:
行业资讯
当前位置:首页 > 行业资讯

电脑可调温度控制器源程序

发布时间:2020-07-21 19:11:04 阅读: 来源:保温杯厂家

/*-------------------------------温度控制器V1.5显示为三个共阳极LED温度传感器用单总线DS18B20CPU为2051,四个按键,分别为UP,DOWN,SET温度调节上限为125度,下限为-55度只能用于单只18B20本软件仅供学习与参考,引用时请注明版权 /> 明浩2004/1/2pnzwzw@-------------------------------*/#include #include #define Key_UP P3_0 //上调温度#define Key_DOWN P3_1 //下调温度#define Key_SET P1_7 //设定键(温度设定,长按开电源)#define RelayOutPort P3_5 //继电器输出#define LEDPort P1 //LED控制口#define LEDOneC P3_2 //LED DS1控制(百位)#define LEDTwoC P3_3 //LED DS2控制(十位)#define LEDThreeC P3_4 //LED DS3控制(个位)#define TMPort P3_7 //DS1820 DataPortunsigned char code LEDDis[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF,0xBF}; //0-9的LED笔划,0xFF为空,0xF7为负号static unsigned char bdata StateREG; //可位寻址的状态寄存器sbit DS1820ON = StateREG^0; //DS1820是否存在sbit SetTF = StateREG^1; //是否是在温度设置状态sbit KeySETDown = StateREG^2; //是否已按过SET键标识sbit PowTF = StateREG^3; //电源电源标识sbit KeyTF = StateREG^4; //键盘是否允许//sbit KeySETDowning = StateREG^5; //SET是否正在按下static unsigned char bdata TLV _at_ 0x0029; //温度变量高低位static unsigned char bdata THV _at_ 0x0028;static signed char TMV; //转换后的温度值static unsigned char KeyV,TempKeyV; //键值static signed char TMRomV _at_ 0x0027; //高温限制static signed char TMSetV _at_ 0x0026; //温度设定值static unsigned char KSDNum; //SET键连按时的采集次数static unsigned char IntNum,IntNum2,IntNum3; //中断发生次数,IntNum用于SET长按检测,IntNum2用于设定状态时LED闪烁static signed char LED_One,LED_Two,LED_Three; //LED的显示位 LED_One为十位,LED_Two为个位static unsigned char Sign; //负号标识void main(void){void InitDS1820(void); //定义函数void ROMDS1820(void);void TMVDS1820(void);void TMRDS1820(void);void TMWDS1820(void);void TMREDS1820(void);void TMERDS1820(void);void ReadDS1820(void);void WriteDS1820(void);void Delay_510(void);void Delay_110(void);void Delay_10ms(void);void Delay_4s(void);void V2ToV(void);StateREG = 0; //初始化变量SetTF = 1; PowTF = 1; //关电源THV = 0;TLV = 0;TMV = 0;KeyV = 0;TempKeyV = 0;KSDNum = 0;IntNum = 0;IntNum2 = 0;IntNum3 = 0;LED_One = 0;LED_Two = 0;InitDS1820(); //初始化ROMDS1820(); //跳过ROMTMERDS1820(); //E2PRAM中温度上限值调入RAMInitDS1820(); //初始化ROMDS1820(); //跳过ROMTMRDS1820(); //读出温度指令ReadDS1820(); //读出温度值和上限值TMSetV = TMRomV; //拷贝保存在DS18B20ROM里的上限值到TMSetVEA = 1; //允许CPU中断ET0 = 1; //定时器0中断打开TMOD = 0x1; //设定时器0为模式1,16位模式TH0=0xB1;TL0=0xDF; //设定时值为20000us(20ms)TR0 = 1; //开始定时while(1);}//定时器0中断外理中键扫描和显示void KeyAndDis_Time0(void) interrupt 1 using 2{TH0=0xB1;TL0=0xDF; //设定时值为20000us(20ms)LEDPort = 0xFF;if (!Key_UP)KeyV = 1;if (!Key_DOWN)KeyV = 2;if (!Key_SET)KeyV = 3;//KeySETDowning = 0; //清除if (KeyV != 0) //有键按下{Delay_10ms(); //延时防抖 按下10ms再测if (!Key_UP)TempKeyV = 1;if (!Key_DOWN)TempKeyV = 2;if (!Key_SET)TempKeyV = 3;if (KeyV == TempKeyV) //两次值相等为确定接下了键{if (KeyV == 3) //按下SET键,如在SET状态就退出,否则进入{//KeySETDowning = 1; //表明SET正在按下PowTF = 0; //电源标识开if (!KeyTF)if (SetTF){SetTF = 0; //标识位标识退出设定InitDS1820(); //初始化ROMDS1820(); //跳过ROMTMWDS1820(); //写温度上限指令WriteDS1820(); //写温度上限到DS18B20ROMWriteDS1820(); //写温度上限到DS18B20ROMWriteDS1820(); //写温度上限到DS18B20ROMInitDS1820(); //初始化ROMDS1820(); //跳过ROMTMREDS1820(); //温度上限值COPY回E2PRAM}elseSetTF = 1;if (!KeySETDown) //没有第一次按下SET时,KeySETDown标识置1KeySETDown = 1;elseKSDNum = KSDNum + 1; //前一秒内有按过SET则开始计数}if (SetTF) //在SET状态下{if ((KeyV == 1) (!KeyTF))TMSetV = TMSetV + 1; //上调温度if ((KeyV == 2) (!KeyTF))TMSetV = TMSetV - 1; //下调温度if (TMSetV = -55) //限制温度上下限TMSetV = -55;if (TMSetV >= 125)TMSetV = 125;}if ((!KeyTF) (IntNum3 == 0)) KeyTF = 1; //当键盘处于可用时,锁定}if (KeySETDown) //在2秒内按下了SET则计中断发生次数用于长按SET时计时用IntNum = IntNum + 1; if (IntNum > 55) //中断发生了55次时(大约1.2秒)75为1.5秒左右{IntNum = 0;KeySETDown = 0;if (KSDNum == 55) //如一直长按了SET1.2秒左右{RelayOutPort = 1; //关闭继电器输出PowTF = 1; //电源标识关LEDOneC = 0;LEDTwoC = 0;LEDThreeC = 0;LEDPort = 0xBF; //显示--Delay_4s(); //延时LEDOneC = 1;LEDTwoC = 1; //关显示LEDThreeC = 1;Delay_4s();IntNum = 0;IntNum2 = 0;IntNum3 = 0;}KSDNum = 0;}}KeyV = 0;TempKeyV = 0; //清空变量准备下次键扫描if (!PowTF){InitDS1820(); //初始化ROMDS1820(); //跳过ROMTMVDS1820(); //温度转换指令Delay_510();Delay_510(); //延时等待转换完成InitDS1820(); //初始化ROMDS1820(); //跳过ROMTMRDS1820(); //读出温度指令ReadDS1820(); //读出温度值V2ToV(); //转换显示值if (TMV > TMSetV) //根据采集到的温度值控制继电器{RelayOutPort = 0;}else{RelayOutPort = 1;}

石家庄植发医院

郑州植发医院

济南双眼皮

郑州磨骨价格

相关阅读