智能住宅安防报警系统

/****************************************************

工程名:智能住宅安防报警系统
作者:付江云
说明:系统开关控制系统开始/结束工作,
系统开始工作后需要先设定当前时间,
确认后系统正式开始工作,系统可检测
来自气体传感器的信号以及光电传感器
的信号以供判断是否有险情,一旦测到
险情,先读取当前时间写入数组,并触
发报警电路自动拨号报警。
用户回来后,可利用查询键查询何时发
生何种险情。

***************************************************/
#include
#define uchar unsigned char
#define uint unsigned int

//定义液晶控制端口
sbit lcdrs = P1^0;
sbit lcdrw = P1^1;
sbit lcden = P1^2;

//控制输出信号端口
sbit sys = P1^3;
sbit tohuo = P1^4;
sbit todao = P1^5;
sbit tophone = P1^6;

//定义几个变量
uchar flag; //用于记录系统当前状态,可用于判断系统状态及设置时间
uchar num,tempnum; //用于记录当前险情组数,设置系统只存5组,每次重启系统又复位
bit disdanger; //显示灾情标志位
uchar temphour,tempmin,tempsec,secnum;

//定义存储时间的二维数组
uchar info[10][4];

//预设液晶显示的内容
uchar code dat1[12] = ” System is”;
uchar code dat2[12] = ” setting!”;
uchar code dat3[14] = ” not working!”;
uchar code dat4[14] = ” Fire Danger!”;
uchar code dat5[15] = ” Theft Danger!”;
uchar code dat6[15] = ” Setting Time!”;
uchar code dat7[6] = ” Time:”;
uchar code dat8[10] = “0123456789”;
uchar code dat9[12] = ” working!”;
uchar code dat10[15] = ” Setting Hour!”;
uchar code dat11[15] = ” Setting Min! “;
uchar code dat12[15] = ” Setting Sec! “;
uchar code dat13[13] = ” Fire Danger!”;
uchar code dat14[14] = ” Theft Danger!”;
uchar code dat15[13] = ” No Danger!”;

uchar code huan[16] = {
0xe0,0xff,0xe4,0xff,0xe4,0xe4,0xff,0×00,
0xe0,0xff,0xe4,0xee,0xf5,0xe4,0xe4,0×00
}; //汉字”环”

void delayms(uint z) //毫秒延时函数
{
uint i,j;
for(i=z;i>0;i–)
for(j=124;j>0;j–);
}

void lcd_write_com(uchar com) //液晶写指令函数
{
lcdrw = 0;
lcdrs = 0;
P0 = com;
delayms(5);
lcden = 1;
delayms(5);
lcden = 0;
}

void lcd_write_dat(uchar dat) //液晶写数据函数
{
lcdrw = 0;
lcdrs = 1;
P0 = dat;
delayms(5);
lcden = 1;
delayms(5);
lcden = 0;
}

void lcd_init() //液晶初始化函数
{
lcden = 0;
lcd_write_com(0×38);
lcd_write_com(0×0c);
lcd_write_com(0×06);
lcd_write_com(0×01);
lcd_write_com(0×80);
}

void system_init()
{
sys = 1;
tohuo = 1;
todao = 1;
tophone = 1;
flag = 0;
num = 0;
disdanger = 0;
temphour = 23;
tempmin = 59;
tempsec = 59;
secnum = 0;
tempnum = 0;
TR0 = 0;
}

void main()
{
uchar i;
system_init();
lcd_init();
EA = 1;
ET0 = 1;
TMOD = 0×01;
TH0 = 0×3c;
TL0 = 0×0bc;
EX1 = 1;
for(i=0;i<12;i++)
lcd_write_dat(dat1[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<14;i++)
lcd_write_dat(dat3[i]);
while(1);
/*
测试显示汉字。By Cloud.
uchar i;
lcd_init();
lcd_write_com(0×01);
lcd_write_com(0×40);
for(i=0;i<16;i++)
lcd_write_dat(huan[i]);
lcd_write_com(0×80+5);
for(i=0;i<8;i++)
lcd_write_dat(i);
*/
}

void int0() interrupt 2
{
uchar tempdat = P2;
uchar tempflag,i;
EX0 = 1;
switch(tempdat)
{
case 0×0fe: //设置时间
tempflag = 0;break;
case 0×0fd: //时间加
tempflag = 1;break;
case 0×0fb: //时间减
tempflag = 2;break;
case 0×0f7: //系统开关
tempflag = 3;break;
case 0×0ef: //火警信号
tempflag = 4;break;
case 0×0df: //盗情信号
tempflag = 5;break;
case 0×0bf: //切换下组险情
tempflag = 6;break;
}
switch(flag)
{
case 0:
{
if(tempflag==3)
{
flag = 1;
sys = 0;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<12;i++)
lcd_write_dat(dat1[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<14;i++)
lcd_write_dat(dat2[i]);
}
break;
}
case 1:
{
if(tempflag==3)
{
flag = 0;
sys = 1;
tohuo = 1;
todao = 1;
tophone = 1;
num = 0;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<12;i++)
lcd_write_dat(dat1[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<14;i++)
lcd_write_dat(dat3[i]);
}
if(tempflag==0)
{
flag = 2;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<15;i++)
lcd_write_dat(dat10[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<6;i++)
lcd_write_dat(dat7[i]);
lcd_write_dat(dat8[temphour/10]);
lcd_write_dat(dat8[temphour%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempmin/10]);
lcd_write_dat(dat8[tempmin%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempsec/10]);
lcd_write_dat(dat8[tempsec%10]);
}
break;
}
case 2:
{
if(tempflag==3)
{
flag = 0;
sys = 1;
tohuo = 1;
todao = 1;
tophone = 1;
num = 0;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<12;i++)
lcd_write_dat(dat1[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<14;i++)
lcd_write_dat(dat3[i]);
}
if(tempflag==0)
{
flag = 3;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<15;i++)
lcd_write_dat(dat11[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<6;i++)
lcd_write_dat(dat7[i]);
lcd_write_dat(dat8[temphour/10]);
lcd_write_dat(dat8[temphour%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempmin/10]);
lcd_write_dat(dat8[tempmin%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempsec/10]);
lcd_write_dat(dat8[tempsec%10]);
}
if(tempflag==1)
{
if(temphour==23)
temphour = 0;
else
temphour++;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<15;i++)
lcd_write_dat(dat10[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<6;i++)
lcd_write_dat(dat7[i]);
lcd_write_dat(dat8[temphour/10]);
lcd_write_dat(dat8[temphour%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempmin/10]);
lcd_write_dat(dat8[tempmin%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempsec/10]);
lcd_write_dat(dat8[tempsec%10]);
}
if(tempflag==2)
{
if(temphour==0)
temphour = 23;
else
temphour–;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<15;i++)
lcd_write_dat(dat10[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<6;i++)
lcd_write_dat(dat7[i]);
lcd_write_dat(dat8[temphour/10]);
lcd_write_dat(dat8[temphour%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempmin/10]);
lcd_write_dat(dat8[tempmin%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempsec/10]);
lcd_write_dat(dat8[tempsec%10]);
}
break;
}
case 3:
{
if(tempflag==3)
{
flag = 0;
sys = 1;
tohuo = 1;
todao = 1;
tophone = 1;
num = 0;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<12;i++)
lcd_write_dat(dat1[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<14;i++)
lcd_write_dat(dat3[i]);
}
if(tempflag==0)
{
flag = 4;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<15;i++)
lcd_write_dat(dat12[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<6;i++)
lcd_write_dat(dat7[i]);
lcd_write_dat(dat8[temphour/10]);
lcd_write_dat(dat8[temphour%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempmin/10]);
lcd_write_dat(dat8[tempmin%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempsec/10]);
lcd_write_dat(dat8[tempsec%10]);
}
if(tempflag==1)
{
if(tempmin==59)
tempmin = 0;
else
tempmin++;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<15;i++)
lcd_write_dat(dat11[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<6;i++)
lcd_write_dat(dat7[i]);
lcd_write_dat(dat8[temphour/10]);
lcd_write_dat(dat8[temphour%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempmin/10]);
lcd_write_dat(dat8[tempmin%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempsec/10]);
lcd_write_dat(dat8[tempsec%10]);
}
if(tempflag==2)
{
if(tempmin==0)
tempmin = 59;
else
tempmin–;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<15;i++)
lcd_write_dat(dat11[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<6;i++)
lcd_write_dat(dat7[i]);
lcd_write_dat(dat8[temphour/10]);
lcd_write_dat(dat8[temphour%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempmin/10]);
lcd_write_dat(dat8[tempmin%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempsec/10]);
lcd_write_dat(dat8[tempsec%10]);
}
break;
}
case 4:
{
if(tempflag==3)
{
flag = 0;
sys = 1;
tohuo = 1;
todao = 1;
tophone = 1;
num = 0;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<12;i++)
lcd_write_dat(dat1[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<14;i++)
lcd_write_dat(dat3[i]);
}
if(tempflag==0)
{
flag = 5;
TR0 = 1;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<15;i++)
lcd_write_dat(dat1[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<12;i++)
lcd_write_dat(dat9[i]);
}
if(tempflag==1)
{
if(tempsec==59)
tempsec = 0;
else
tempsec++;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<15;i++)
lcd_write_dat(dat12[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<6;i++)
lcd_write_dat(dat7[i]);
lcd_write_dat(dat8[temphour/10]);
lcd_write_dat(dat8[temphour%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempmin/10]);
lcd_write_dat(dat8[tempmin%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempsec/10]);
lcd_write_dat(dat8[tempsec%10]);
}
if(tempflag==2)
{
if(tempsec==0)
tempsec = 59;
else
tempsec–;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<15;i++)
lcd_write_dat(dat12[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<6;i++)
lcd_write_dat(dat7[i]);
lcd_write_dat(dat8[temphour/10]);
lcd_write_dat(dat8[temphour%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempmin/10]);
lcd_write_dat(dat8[tempmin%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempsec/10]);
lcd_write_dat(dat8[tempsec%10]);
}
break;
}
case 5:
{
if(tempflag==3)
{
flag = 0;
sys = 1;
tohuo = 1;
todao = 1;
tophone = 1;
num = 0;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<12;i++)
lcd_write_dat(dat1[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<14;i++)
lcd_write_dat(dat3[i]);
}
if(tempflag==0)
{
flag = 2;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<15;i++)
lcd_write_dat(dat10[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<6;i++)
lcd_write_dat(dat7[i]);
lcd_write_dat(dat8[temphour/10]);
lcd_write_dat(dat8[temphour%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempmin/10]);
lcd_write_dat(dat8[tempmin%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[tempsec/10]);
lcd_write_dat(dat8[tempsec%10]);
}
if(tempflag==4)
{
num++;
info[num-1][0] = temphour;
info[num-1][1] = tempmin;
info[num-1][2] = tempsec;
info[num-1][3] = 1;
tohuo = 0;
todao = 1;
tophone = 0;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<14;i++)
lcd_write_dat(dat4[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<6;i++)
lcd_write_dat(dat7[i]);
lcd_write_dat(dat8[info[num-1][0]/10]);
lcd_write_dat(dat8[info[num-1][0]%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[info[num-1][1]/10]);
lcd_write_dat(dat8[info[num-1][1]%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[info[num-1][2]/10]);
lcd_write_dat(dat8[info[num-1][2]%10]);
}
if(tempflag==5)
{
num++;
info[num-1][0] = temphour;
info[num-1][1] = tempmin;
info[num-1][2] = tempsec;
info[num-1][3] = 2;
todao = 0;
tohuo = 1;
tophone = 0;
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<14;i++)
lcd_write_dat(dat5[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<6;i++)
lcd_write_dat(dat7[i]);
lcd_write_dat(dat8[info[num-1][0]/10]);
lcd_write_dat(dat8[info[num-1][0]%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[info[num-1][1]/10]);
lcd_write_dat(dat8[info[num-1][1]%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[info[num-1][2]/10]);
lcd_write_dat(dat8[info[num-1][2]%10]);
}
if(tempflag==6)
{
if(tempnum==0)
tempnum = num;
else
tempnum–;
if(tempnum==0)
{
lcd_write_com(0×01);
lcd_write_com(0×80);
for(i=0;i<13;i++)
lcd_write_dat(dat15[i]);
}
else
{
if(info[tempnum-1][3]==1)
{
tohuo = 0;
todao = 1;
lcd_write_com(0×01);
lcd_write_com(0×80);
lcd_write_dat(dat8[tempnum]);
for(i=0;i<13;i++)
lcd_write_dat(dat13[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<6;i++)
lcd_write_dat(dat7[i]);
lcd_write_dat(dat8[info[tempnum-1][0]/10]);
lcd_write_dat(dat8[info[tempnum-1][0]%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[info[tempnum-1][1]/10]);
lcd_write_dat(dat8[info[tempnum-1][1]%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[info[tempnum-1][2]/10]);
lcd_write_dat(dat8[info[tempnum-1][2]%10]);
}
if(info[tempnum-1][3]==2)
{
todao = 0;
tohuo = 1;
lcd_write_com(0×01);
lcd_write_com(0×80);
lcd_write_dat(dat8[tempnum]);
for(i=0;i<14;i++)
lcd_write_dat(dat14[i]);
lcd_write_com(0×80+0×40);
for(i=0;i<6;i++)
lcd_write_dat(dat7[i]);
lcd_write_dat(dat8[info[tempnum-1][0]/10]);
lcd_write_dat(dat8[info[tempnum-1][0]%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[info[tempnum-1][1]/10]);
lcd_write_dat(dat8[info[tempnum-1][1]%10]);
lcd_write_dat(‘-‘);
lcd_write_dat(dat8[info[tempnum-1][2]/10]);
lcd_write_dat(dat8[info[tempnum-1][2]%10]);
}
}
}
break;
}
}
EX1 = 1;
}

void int1() interrupt 1
{
TH0 = 0×3c;
TL0 = 0X0b0;
if(secnum==14)
{
secnum = 0;
if(tempsec==59)
{
tempsec = 0;
if(tempmin==59)
{
tempmin = 0;
if(temphour==23)
{
temphour = 0;
}
else
temphour++;
}
else
tempmin++;
}
else
tempsec++;
}
else
secnum++;
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注