2 qq 38610782 qq_38610782 于 2017.05.20 12:12 提问

求解释程序,基于gsm烟雾防盗报警 90C

#include
#include
#include //头文件
#define uint unsigned int
#define uchar unsigned char //宏定义

//按键
sbit key1=P3^2; //布防
sbit key2=P3^3; //撤防
sbit key3=P3^4; //紧急报警

sbit BUZZ=P0^4; //蜂鸣器
sbit rsd=P2^4; //热释电输入
sbit yanwu=P2^5;
sbit LED_B=P2^3; //布防指示灯
sbit LED_S=P2^0; //发送消息指示灯

uchar code PhoneNO[] ="15046397767"; //接受号码

uchar code somebody[] ="67094EBA8FDB5165FF0C8BF76CE8610F3002"; //有人进入,请注意。
uchar code somebody1[] ="70DF96FE6D535EA68FC79AD8FF0C8BF76CE8610F3002"; //烟雾浓度过高,请注意。

uchar code somebody2[] ="67094EBA8FDB5165FF0C70DF96FE6D535EA68FC79AD8FF0C8BF76CE8610F3002"; //有人进入,烟雾浓度过高,请注意。

uint TIME_50ms=0; //计时的最小分辨率50ms
uint time_continue;
uchar TIME_ALAM=0;
bit flag=0,flag_BF=0;
bit flag_time_start=0;
bit again=0;
bit flag_alam;
bit SOS;
bit flag_continue;
bit into_BF=0;

void delay(uint z)//延时函数
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}

void Uart_init()
{
TMOD= 0X20; //T1 方式2 ,8位 自动重装

TH1=0Xfd;
TL1=0Xfd; //9600
TR1=1; // 定时器1启动

SM0=0; // 设置串口的工作模式
SM1=1; //方式1

REN=0;       // 允许串口接收数据     

ES=0;        // 串口中断应许 
EA=1;        // 开启中断 

}

void SendASC(uchar d)
{

SBUF=d;
while(!TI);

TI=0;

}

void SendString(uchar *str)
{
while(*str)
{
SendASC(*str) ;
str++;
//delay_uart(1);
}
}

void TIME()
{
if(flag==0)
{
delay(50);
TIME_50ms++;
if(TIME_50ms%10==0)
LED_B=!LED_B;

    if(TIME_50ms>=400)
    {
        TIME_50ms=0;
        flag_BF=1;
        LED_B=0;
        flag_time_start=0;
        again=1;
    }   
}
else
{
    delay(50);
    TIME_50ms++;
    if(TIME_50ms%10==0)
    {
        LED_B=!LED_B;
        if(flag_alam==1)
        {

            if(flag_continue==0)
            {
                flag_continue=1;
                time_continue=TIME_50ms;
            }
            BUZZ=!BUZZ;
            if(TIME_50ms>=time_continue+100)
            {
                BUZZ=1;
                flag_continue=0;
                flag_alam=0;
                time_continue=0;
            }   
        }
    }
    if(TIME_50ms>=1200)
    {
        LED_B=0;
        TIME_50ms=0;
        flag_time_start=0;
        again=1;
    }
}

}

//按键扫描函数
void keyscan()
{
if(key1==0&&flag_BF==0)//布防
{
delay(5);//延时
if(key1==0)
{
LED_B=0;
flag=0;
flag_time_start=1;
}
while(key1==0);
}
if(flag_time_start==1)
{
TIME();
}
if(key2==0)
{

delay(5);//撤防
if(key2==0)
{
BUZZ=1; //关闭蜂鸣器
flag_alam=0;
flag_BF=0;
flag=0;
flag_time_start=0;
LED_S=1;
LED_B=1;
}
while(key2==0);
}
if(key3==0)
{
delay(5);
if(key3==0)
{
SOS=1;
flag_alam=1;
}
while(key3==0);
}
}

void GSM_work()
{
unsigned char send_number;
if((rsd==0||yanwu==0)&&flag_BF==1)
flag_alam=1;
if(((rsd==0||yanwu==0)&&flag_BF==1&&again==1)||SOS==1)
{
LED_S=0;
BUZZ=1;
SendString("AT+CMGF=1\r\n");

    delay(200);

    SendString("AT+CSCS=\"UCS2\"\r\n"); 

    delay(200);

    SendString("AT+CSMP=17,0,2,25\r\n");    

    delay(200);

    SendString("AT+CMGS="); //信息发送指令 AT+CMGS=//
    SendASC('"');
    for(send_number=0;send_number<11;send_number++)
    {
        SendASC('0');
        SendASC('0');
        SendASC('3');
        SendASC(PhoneNO[send_number]);
    }     
    SendASC('"');
    SendASC('\r');          //发送回车指令//
    SendASC('\n');          //发送换行指令//

    delay(200);

    if(rsd==0&&yanwu==1)
    SendString(somebody);
    else if(rsd==1&&yanwu==0)
    SendString(somebody1);
    else if((rsd==0&&yanwu==0)||SOS==1)
    SendString(somebody2);

    delay(200);

    SendASC(0x1a);

    if(SOS==0)
    {
        again=0;
        flag_time_start=1;
        flag_alam=1;

    }
    else if(SOS==1&&flag_time_start==1)
    {
        TIME_50ms=0;
        flag_BF=1;
        LED_B=0;
        flag_time_start=0;
        again=1;
    }
    delay(2000);
    LED_S=1;
    SOS=0;
    flag=1;
}

}

void main()
{

Uart_init();
while(1)
{
keyscan();
GSM_work();
}

}

1个回答

devmiao
devmiao   Ds   Rxr 2017.05.21 18:04

这是单片机的C语言,要结合你的硬件看。你最好问写程序的人。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!