这个是原子哥写的gsm模块读短信函数,我想把它改成接收到一条短信后蜂鸣器长响,需要怎么改?求解~~~~~
void sim900a_sms_read_test(void)
{
u8 *p,*p1,*p2;
u8 timex=0;
u8 msgindex[3];
u8 msglen=0;
u8 msgmaxnum=0; //短信最大条数
u8 key=0;
u8 smsreadsta=0; //是否在短信显示状态
p=mymalloc(SRAMIN,200);//申请200个字节的内存
LCD_Clear(WHITE);
POINT_COLOR=RED;
Show_Str_Mid(0,30,"ATK-SIM900A 读短信测试",16,240);
Show_Str(30,50,200,16,"读取: 总信息:",16,0);
kbd_fn_tbl[0]="读取";
kbd_fn_tbl[1]="返回";
sim900a_load_keyboard(0,180,(u8**)kbd_tbl1);//显示键盘
while(1)
{
key=sim900a_get_keynum(0,180);
if(key)
{
if(smsreadsta)
{
LCD_Fill(30,75,239,179,WHITE);//清除显示的短信内容
smsreadsta=0;
}
if(key<10||key==11)
{
if(msglen<2)
{
msgindex[msglen++]=kbd_tbl[key-1][0];
u2_printf("AT+CLDTMF=2,\"%c\"\r\n",kbd_tbl[key-1][0]);
}
if(msglen==2)
{
key=(msgindex[0]-'0')*10+msgindex[1]-'0';
if(key>msgmaxnum)
{
msgindex[0]=msgmaxnum/10+'0';
msgindex[1]=msgmaxnum%10+'0';
}
}
}else
{
if(key==13)if(msglen)msglen--;//删除
if(key==14&&msglen)//执行读取短信
{
LCD_Fill(30,75,239,179,WHITE);//清除之前的显示
sprintf((char*)p,"AT+CMGR=%s",msgindex);
if(sim900a_send_cmd(p,"+CMGR:",200)==0)//读取短信
{
POINT_COLOR=RED;
Show_Str(30,75,200,12,"状态:",12,0);
Show_Str(30+75,75,200,12,"来自:",12,0);
Show_Str(30,90,200,12,"接收时间:",12,0);
Show_Str(30,105,200,12,"内容:",12,0);
POINT_COLOR=BLUE;
if(strstr((const char*)(USART2_RX_BUF),"UNREAD")==0)Show_Str(30+30,75,200,12,"已读",12,0);
else Show_Str(30+30,75,200,12,"未读",12,0);
p1=(u8*)strstr((const char*)(USART2_RX_BUF),",");
p2=(u8*)strstr((const char*)(p1+2),"\"");
p2[0]=0;//加入结束符
sim900a_unigbk_exchange(p1+2,p,0); //将unicode字符转换为gbk码
Show_Str(30+75+30,75,200,12,p,12,0); //显示电话号码
p1=(u8*)strstr((const char*)(p2+1),"/");
p2=(u8*)strstr((const char*)(p1),"+");
p2[0]=0;//加入结束符
Show_Str(30+54,90,200,12,p1-2,12,0); //显示接收时间
p1=(u8*)strstr((const char*)(p2+1),"\r"); //寻找回车符
sim900a_unigbk_exchange(p1+2,p,0); //将unicode字符转换为gbk码
Show_Str(30+30,105,180,75,p,12,0); //显示短信内容
smsreadsta=1; //标记有显示短信内容
}else
{
Show_Str(30,75,200,12,"无短信内容!!!请检查!!",12,0);
delay_ms(1000);
LCD_Fill(30,75,239,75+12,WHITE);//清除显示
}
USART2_RX_STA=0;
}
if(key==15)break;
}
msgindex[msglen]=0;
LCD_Fill(30+40,50,86,50+16,WHITE);
Show_Str(30+40,50,86,16,msgindex,16,0); //键盘输入数字
}
if(timex==0) //2.5秒左右更新一次
{
if(sim900a_send_cmd("AT+CPMS?","+CPMS:",200)==0) //查询优选消息存储器
{
p1=(u8*)strstr((const char*)(USART2_RX_BUF),",");
p2=(u8*)strstr((const char*)(p1+1),",");
p2[0]='/';
if(p2[3]==',')//小于64K SIM卡,最多存储几十条短信
{
msgmaxnum=(p2[1]-'0')*10+p2[2]-'0'; //获取最大存储短信条数
p2[3]=0;
}else //如果是64K SIM卡,则能存储100条以上的信息
{
msgmaxnum=(p2[1]-'0')*100+(p2[2]-'0')*10+p2[3]-'0';//获取最大存储短信条数
p2[4]=0;
}
sprintf((char*)p,"%s",p1+1);
Show_Str(30+17*8,50,200,16,p,16,0);
USART2_RX_STA=0;
}
}
if((timex%20)==0)LED0=!LED0;//200ms闪烁
timex++;
delay_ms(10);
if(USART2_RX_STA&0X8000) //检查从GSM模块接收到的数据
{
//BEEP=1;
sim_at_response(1);
}
}
myfree(SRAMIN,p);
}
|