基于单片机的智能火灾报警系统设计源程序代码.docx
- 文档编号:13768637
- 上传时间:2023-06-17
- 格式:DOCX
- 页数:8
- 大小:15.86KB
基于单片机的智能火灾报警系统设计源程序代码.docx
《基于单片机的智能火灾报警系统设计源程序代码.docx》由会员分享,可在线阅读,更多相关《基于单片机的智能火灾报警系统设计源程序代码.docx(8页珍藏版)》请在冰点文库上搜索。
基于单片机的智能火灾报警系统设计源程序代码
#include
#defineucharunsignedchar//无符号字符型宏定义变量范围0~255
#defineuintunsignedint//无符号整型宏定义变量范围0~65535
#include
#include"lcd1602.h"
#include"eeprom52.h"
sbitCS=P2^4;//CS定义为P2口的第4位脚,连接ADC0832CS脚
sbitSCL=P2^3;//SCL定义为P2口的第3位脚,连接ADC0832SCL脚sbitDO=P2^2;//DO定义为P2口的第2位脚,连接ADC0832DO脚
sbitdq=P2^0;//18b20IO口的定义
sbitbeep=P3^2;//蜂鸣器IO口定义
uinttemperature,s_temp;//温度的变量
ucharyanwu,s_yanwu;//烟物等级
ucharshoudong;//手动报警键
bitflag_300ms;
ucharkey_can;//按键值的变量
ucharmenu_1;//菜单设计的变量
bitkey_500ms;
ucharphone1_i=0;//电话号码是多少位
ucharphone2_i=0;//电话号码是多少位
ucharphone1_call[11]={""};
ucharphone2_call[11]={""};
uchardis_smg[11];
/***********************1ms延时函数*****************************/voiddelay_1ms(uintq)
{
uinti,j;
for(i=0;i for(j=0;j<120;j++); } #include"gsm.h" /***************把数组清空**********************/ voidclear_shuzu(uchar*p,ucharnum) { for(i=0;i p[i]=''; } /******************把数据保存到单片机内部eeprom中**写电话号码****************/voidwrite_eeprom()//数据保存 { SectorErase(0x2000); for(i=0;i<11;i++) byte_write(0x2000+i,phone1_call[i]); byte_write(0x2012,phone1_i); byte_write(0x2013,phone2_i); byte_write(0x2014,s_temp); byte_write(0x2015,s_yanwu); byte_write(0x2016,a_a); byte_write(0x2020,phone2_call[0]); byte_write(0x2021,phone2_call[1]); byte_write(0x2022,phone2_call[2]); byte_write(0x2023,phone2_call[3]); byte_write(0x2024,phone2_call[4]); byte_write(0x2025,phone2_call[5]); byte_write(0x2026,phone2_call[6]); byte_write(0x2027,phone2_call[7]); byte_write(0x2028,phone2_call[8]); byte_write(0x2029,phone2_call[9]); byte_write(0x2030,phone2_call[10]); } /******************把数据从单片机内部eeprom中读出来**读电话号码***************/voidread_eeprom() { for(i=0;i<11;i++) phone1_call[i]=byte_read(0x2000+i); phone1_i=byte_read(0x2012); phone2_i=byte_read(0x2013); s_temp=byte_read(0x2014); s_yanwu=byte_read(0x2015); a_a=byte_read(0x2016); phone2_call[0]=byte_read(0x2020); phone2_call[1]=byte_read(0x2021); phone2_call[2]=byte_read(0x2022); phone2_call[3]=byte_read(0x2023); phone2_call[4]=byte_read(0x2024); phone2_call[5]=byte_read(0x2025); phone2_call[6]=byte_read(0x2026); phone2_call[7]=byte_read(0x2027); phone2_call[8]=byte_read(0x2028); phone2_call[9]=byte_read(0x2029); phone2_call[10]=byte_read(0x2030); } /**************开机自检eeprom初始化*****************/ voidinit_eeprom() { read_eeprom();//读电话号码 if(a_a! =22) { a_a=22; for(i=0;i<11;i++) { phone1_call[i]=''; phone2_call[i]=''; } phone1_i=0; phone2_i=0; s_temp=50; s_yanwu=60; write_eeprom();//保存数据 } } /***********************18b20初始化函数*****************************/voidinit_18b20() { bitq; dq=1;//把总线拿高 delay_uint (1);//15us dq=0;//给复位脉冲 delay_uint(80);//750us dq=1;//把总线拿高等待 delay_uint(10);//110us q=dq;//读取18b20初始化信号 delay_uint(20);//200us dq=1;//把总线拿高释放总线 } /*************写18b20内的数据***************/ voidwrite_18b20(uchardat) { uchari; for(i=0;i<8;i++) {//写数据是低位开始 dq=0;//把总线拿低写时间隙开始 dq=dat&0x01;//向18b20总线写数据了 delay_uint(5);//60us dq=1;//释放总线 dat>>=1; } } /*************读取18b20内的数据***************/ ucharread_18b20() { uchari,value; for(i=0;i<8;i++) { dq=0;//把总线拿低读时间隙开始 value>>=1;//读数据是低位开始 dq=1;//释放总线 if(dq==1)//开始读写数据 value|=0x80; delay_uint(5);//60us读一个时间隙最少要保持60us的时间 } returnvalue;//返回数据 } /*************读取温度的值读出来的是小数***************/ uintread_temp() { uintvalue; ucharlow;//在读取温度的时候如果中断的太频繁了,就应该把中断给关了,否则会影响到18b20的时序 init_18b20();//初始化18b20 write_18b20(0xcc);//跳过64位ROM write_18b20(0x44);//启动一次温度转换命令 delay_uint(50);//500us init_18b20();//初始化18b20 write_18b20(0xcc);//跳过64位ROM write_18b20(0xbe);//发出读取暂存器命令 EA=0; low=read_18b20();//读温度低字节 value=read_18b20();//读温度高字节 EA=1; value<<=8;//把温度的高位左移8位 value|=low;//把读出的温度低位放到value的低八位中 value*=0.0625;//转换到温度值 returnvalue;//返回读出的温度 } /***********读数模转换数据********************************************************/ //请先了解ADC0832模数转换的串行协议,再来读本函数,主要是对应时序图来理解,本函数是模拟0832的串行协议进行的 //100通道 //111通道 unsignedcharad0832read(bitSGL,bitODD) { unsignedchari=0,value=0,value1=0; SCL=0; DO=1; CS=0;//开始 SCL=1;//第一个上升沿 SCL=0; DO=SGL; SCL=1;//第二个上升沿 SCL=0; DO=ODD; SCL=1;//第三个上升沿 DO=1; for(i=0;i<8;i++) { SCL=1; SCL=0;//开始从第四个下降沿接收数据 value<<=1; if(DO) value++; } for(i=0;i<8;i++)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 单片机 智能 火灾 报警 系统 设计 源程序 代码