|
之前写了一个智能家居下gsm模块的程序,可以根据按键输入的密码来判断是否可以进行修改报警号码,并向对应的手机号码发送报警信息,不过得注意需要插入sim卡。程序附录如下:
#include "gsm.h"
#include "common.h"
#include "serial.h"
#include "string.h"
#include "delay.h"
#include <stdio.h>
#include <stdlib.h>
#include "key.h"
#include "24c02.h"
#include "lcd1602.h"
#if 0
/* 发送AT指令 */
int gsm_send_command(uchar *command, uchar *response, uchar waittime)
{
int xdata res = 0;
uart_send_str(command);
if(response && waittime) //需要等待应答
{
while(--waittime) //等待倒计时
{
delay_ms(10);
if(RI)//接收到期待的应答结果
{
if(is_gsm_get_response(response)) break;//得到有效数据
RI = 0;
}
}
if(waittime == 0) res = 1;
}
return res;
}
/*
*是否得到想要的回应
* return 0 : 响应正确
* return -1: 没得到正确的响应
*/
uchar* is_gsm_get_response(uchar *response)
{
uchar xdata resp[20];
uchar *strx = 0;
int xdata len = 0;
int xdata i;
uart_receive_str(resp); //读取响应
strx = strstr((const char*)resp, (const char*)response);
return strx;
}
int gsm_send_sms(uchar *phone_number, uchar *sms_message)
{
const uchar xdata message[] = "Someone in your home,please check.";
int xdata res;
char xdata *p1;
p1 = malloc(sizeof(char)*4);
res = gsm_send_command("AT+CMGF=1\r\n", "OK",200); //设置文本模式
res =gsm_send_command("AT+CSCS=\"GSM\"\r\n","OK",200); //设置TE字符集为GSM
res = gsm_send_command( "AT+CSMP=17,0,2,25\r\n", "OK",200); //设置短消息文本模式参数
res = gsm_send_command("AT+CMGS=\"18819467282\"\r\n", ">", 300);
delay_ms(10);
uart_send_str(message);
delay_ms(10);
sprintf(p1,"%c",0x1a);
return 0;
}
#endif
void gsm_call(void)
{
uchar phone_num[12];
uchar all[24] = "ATD";
uchar one[] = ";\r\n";
iic_read_password_phone(phone_num, 1); //读出电话号码
strcat(all, phone_num);
strcat(all, one);
uart_send_str(all);
}
void change_phone_number(uchar *password)
{
uchar xdata pass_set_suceess[16] = "phone number set";
uchar xdata new_phone[16] = "New phone number";
uint i;
int flag = -1;
if(check_password(password, 0, 1) == 0) //密码正确
{
flag = password_display(password, new_phone, 16);
if(flag == 0)
{
iic_write_password_phone(password, 1); //写入新号码
delay_ms(10);
lcd1602_init(0x0c);
write_1602com(FIRST_LINE);
for(i = 0; i < 16; i++)
write_1602dat(pass_set_suceess[i]);
delay_ms(2000);
lcd1602_init(0x0c);
}
else
lcd1602_init(0x0c);
}
}
|
|