2022年温度测量、报警系统C程序 2.pdf





《2022年温度测量、报警系统C程序 2.pdf》由会员分享,可在线阅读,更多相关《2022年温度测量、报警系统C程序 2.pdf(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、程序名称: DS18B20 温度测量、报警系统简要说明: DS18B20 温度计,温度测量范围099.9 摄氏度可设置上限报警温度、下限报警温度即高于上限值或者低于下限值时蜂鸣器报警默认上限报警温度为38、默认下限报警温度为5报警值可设置范围:最低上限报警值等于当前下限报警值最高下限报警值等于当前上限报警值将下限报警值调为0 时为关闭下限报警功能编写:JiangX.net 最后更新: 09/04/16 晚于寝室*/ #include #include DS18B20.h #define uint unsigned int #define uchar unsigned char /宏定义#def
2、ine SET P3_1 /定义调整键#define DEC P3_2 /定义减少键#define ADD P3_3 /定义增加键#define BEEP P3_7 /定义蜂鸣器bit shanshuo_st; /闪烁间隔标志bit beep_st; /蜂鸣器间隔标志sbit DIAN = P27; /小数点uchar x=0; /计数器signed char m; /温度值全局变量uchar n; /温度值全局变量uchar set_st=0; /状态标志signed char shangxian=38; /上限报警温度,默认值为38 signed char xiaxian=5; /下限报警
3、温度,默认值为38 uchar code LEDData=0 xC0,0 xF9,0 xA4,0 xB0,0 x99,0 x92,0 x82,0 xF8,0 x80,0 x90,0 xff;/*延时子程序 */ void Delay(uint num) while( -num ); /*初始化定时器 0*/ void InitTimer(void) TMOD=0 x1; TH0=0 x3c; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 7 页 - - - - - -
4、- - - TL0=0 xb0; /50ms(晶振 12M )/*定时器 0 中断服务程序 */ void timer0(void) interrupt 1 TH0=0 x3c; TL0=0 xb0; x+; /*外部中断 0 服务程序 */ void int0(void) interrupt 0 EX0=0; /关外部中断 0 if(DEC=0&set_st=1) shangxian-; if(shangxianxiaxian)shangxian=xiaxian; else if(DEC=0&set_st=2) xiaxian-; if(xiaxian99)shangxian=99; els
5、e if(ADD=0&set_st=2) xiaxian+; if(xiaxianshangxian)xiaxian=shangxian; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 7 页 - - - - - - - - - /*读取温度 */ void check_wendu(void) uint a,b,c; c=ReadTemperature()-5; /获取温度值并减去DS18B20 的温漂误差 a=c/100; /计算得到十位数字 b=c/10-a*10;
6、 /计算得到个位数字 m=c/10; /计算得到整数位 n=c-a*100-b*10; /计算得到小数位 if(m99)m=99;n=9; /设置温度显示上限/*显示开机初始化等待画面*/ Disp_init() P2 = 0 xbf; /显示- P1 = 0 xf7; Delay(200); P1 = 0 xfb; Delay(200); P1 = 0 xfd; Delay(200); P1 = 0 xfe; Delay(200); P1 = 0 xff; /关闭显示/*显示温度子程序 */ Disp_Temperature() /显示温度 P2 =0 xc6; /显示 C P1 = 0 x
7、f7; Delay(300); P2 =LEDDatan; /显示个位 P1 = 0 xfb; Delay(300); P2 =LEDDatam%10; /显示十位 DIAN = 0; /显示小数点 P1 = 0 xfd; Delay(300);名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 7 页 - - - - - - - - - P2 =LEDDatam/10; /显示百位 P1 = 0 xfe; Delay(300); P1 = 0 xff; /关闭显示/*显示报
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年温度测量、报警系统C程序 2022 温度 测量 报警 系统 程序

限制150内