这个温度火灾烟雾报警器设计的51单片机程序及注释和protus仿真都有,非常好用.
烟雾传感器仿真中没有,其实就是传感器检测时相应的电阻值会变化,用滑动电位器代替就ok
单片机源程序:
#include
#include "intrins.h"
#define u8 unsigned char
#define u16 unsigned int
#define uchar unsigned char
#define uint unsigned int
uchar yushe_wendu=50; //温度预设值
uchar yushe_yanwu=45; //烟雾预设值
uint wendu; //温度值全局变量
uchar yanwu; //用于读取ADC数据
//运行模式
uchar Mode=0; //=1是设置温度阀值 =2是设置烟雾阀值 =0是正常监控模式
//管脚声明
sbit Led_Reg =P2^2; //红灯
sbit Led_Yellow =P2^4; //黄灯
sbit Buzzer =P2^0; //蜂鸣器
sbit Fan =P3^3; //
/********************************************************************
* 名称 : delay_1ms()
* 功能 : 延时1ms函数
* 输入 : q
* 输出 : 无
***********************************************************************/
void delay_ms(uint q)
{
uint i,j;
for(i=0;i for(j=0;j<110;j++); } /*********************************************************************************************************** LCD1602相关函数 ***********************************************************************************************************/ //LCD管脚声明 (RW引脚实物直接接地,因为本设计只用到液晶的写操作,RW引脚一直是低电平) sbit LCDRS = P2^7; sbit LCDEN = P2^6; sbit D0 = P0^0; sbit D1 = P0^1; sbit D2 = P0^2; sbit D3 = P0^3; sbit D4 = P0^4; sbit D5 = P0^5; sbit D6 = P0^6; sbit D7 = P0^7; //LCD延时 void LCDdelay(uint z) //该延时大约100us(不精确,液晶操作的延时不要求很精确) { uint x,y; for(x=z;x>0;x--) for(y=10;y>0;y--); } void LCD_WriteData(u8 dat) { if(dat&0x01)D0=1;else D0=0; if(dat&0x02)D1=1;else D1=0; if(dat&0x04)D2=1;else D2=0; if(dat&0x08)D3=1;else D3=0; if(dat&0x10)D4=1;else D4=0; if(dat&0x20)D5=1;else D5=0; if(dat&0x40)D6=1;else D6=0; if(dat&0x80)D7=1;else D7=0; } //写命令 void write_com(uchar com) { LCDRS=0; LCD_WriteData(com); // DAT=com; LCDdelay(5); LCDEN=1; LCDdelay(5); LCDEN=0; } //写数据 void write_data(uchar date) { LCDRS=1; LCD_WriteData(date); // DAT=date; LCDdelay(5); LCDEN=1; LCDdelay(5); LCDEN=0; } /*------------------------------------------------ 选择写入位置 ------------------------------------------------*/ void SelectPosition(unsigned char x,unsigned char y) { if (x == 0) { write_com(0x80 + y); //表示第一行 } else { write_com(0xC0 + y); //表示第二行 } } /*------------------------------------------------ 写入字符串函数 ------------------------------------------------*/ void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s) { SelectPosition(x,y) ; while (*s) { write_data( *s); s ++; } } //======================================================================== // 函数: void LCD_Write_Char(u8 x,u8 y,u16 s,u8 l) // 应用: LCD_Write_Char(0,1,366,4) ; // 描述: 在第0行第一个字节位置显示366的后4位,显示结果为 0366 // 参数: x:行,y:列,s:要显示的字,l:显示的位数 // 返回: none. // 版本: VER1.0 // 日期: 2013-4-1 // 备注: 最大显示65535 //======================================================================== void LCD_Write_Char(u8 x,u8 y,u16 s,u8 l) { SelectPosition(x,y) ; if(l>=5) write_data(0x30+s/10000%10); //万位 if(l>=4) write_data(0x30+s/1000%10); //千位 if(l>=3) write_data(0x30+s/100%10); //百位 if(l>=2) write_data(0x30+s/10%10); //十位 if(l>=1) write_data(0x30+s%10); //个位 } /*1602指令简介 write_com(0x38);//屏幕初始化 write_com(0x0c);//打开显示 无光标 无光标闪烁 write_com(0x0d);//打开显示 阴影闪烁 write_com(0x0d);//打开显示 阴影闪烁 */ //1602初始化 void Init1602() { uchar i=0; write_com(0x38);//屏幕初始化 write_com(0x0c);//打开显示 无光标 无光标闪烁 write_com(0x06);//当读或写一个字符是指针后一一位 write_com(0x01);//清屏 } void Display_1602(yushe_wendu,yushe_yanwu,c,temp) { //显示预设温度 LCD_Write_Char(0,6,yushe_wendu,2) ; //显示预设烟雾 LCD_Write_Char(0,13,yushe_yanwu,3) ; //时时温度 LCD_Write_Char(1,6,c/10,2) ; write_data('.'); LCD_Write_Char(1,9,c%10,1) ; //时时烟雾 LCD_Write_Char(1,13,temp,3) ; } /*********************************************************************************************************** ADC0832相
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』