功能:
设计一个温度报警系统,可以设定温度上、下限的值,到达设定值时,蜂鸣器响;按键设定有设置、确定、取消、减少与增加功能,LCD1602实时显示相关温度信息
设定界面:
温度超过设定值,蜂鸣器响:
温度超过设定值,蜂鸣器响:温度超过设定值
温度低于设定值,蜂鸣器响:
部分程序:
#include #include "SETTEM.h" //设置报警的上下限值头文件 #include "Lcd1602.h" //LCD显示模块功能头文件 #include "DS18B20.h" //DS18B02模块功能头文件 #include "IntToChar.h" //存放整型数转换为字符串头文件 #include "Alarm.h" //报警功能头文件 bit flag1s = 0; //1s定时标志 unsigned char T0RH = 0; //T0重载值的高字节 unsigned char T0RL = 0; //T0重载值的低字节 int key=0; char Hint1[]={"Current temperature"}; void ConfigTimer0(unsigned int ms); void main() { bit res; int temp; //读取到的当前温度值 int intT, decT; //温度值的整数和小数部分 unsigned char len; unsigned char str[12]; EA = 1; //开总中断 ConfigTimer0(10); //T0定时10ms Start18B20(); //启动DS18B20 InitLcd1602(); //初始化液晶 ConfigInt0(); //设置温度 while (1) { if (flag1s) //每秒更新一次温度 { flag1s = 0; res = Get18B20Temp(&temp); //读取当前温度 if (res) //读取成功时,刷新当前温度显示 { intT = temp >> 4; //分离出温度值整数部分 decT = temp & 0xF; //分离出温度值小数部分 len = IntToString(str, intT); //整数部分转换为字符串 str[len++] = '.'; //添加小数点 decT = (decT*10) / 16; //二进制的小数部分转换为1位十进制位 str[len++] = decT + '0'; //十进制小数位再转换为ASCII字符 str[len++] = key + '0'; while (len < 6) //用空格补齐到6个字符长度 { str[len++] = ' '; } str[len] = '
相关文章









