概述
嵌入式软件设计第11次实验报告
学号:140201110 姓名:王涵
组别:第4组 实验地点:D19
一、实验目的:
1、了解短信AT指令的使用方法。
2、掌握使用短信AT指令驱动SIM900A发送和接收短信的方法。
二、实验内容:
1.使用AT命令进行模块测试,发送和接收短信。
2.编写程序利用触摸屏完成固定号码短信的发送和接收。(需要加上AT测试命令模块、手机SIM卡检测模块、手机信号质量检测模块等等。)
三、实验过程描述及结果展示:
短信常用AT指令1
短信常用AT指令2
GSM短信发送菜单示例
实现代码:
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "lcd.h"
#include "key.h"
#include "touch.h"
#include "text.h"
#include "w25qxx.h"
#include "malloc.h"
#include "ff.h"
#include "exfuns.h"
#include <string.h>
const u16 POINT_COLOR_TBL[OTT_MAX_TOUCH]={RED,GREEN,BLUE,BROWN,GRED};
extern u16 USART3_RX_STA;
extern u8 USART3_RX_BUF[400];
unsigned char cnt = 0;
unsigned char *SMS = 0;
u8 SMS_string[10]={"AT+CMGR="};
void LCD_Draw_Circle(u16 x0,u16 y0,u8 r);
//串口3发送数据示例代码
// USART_SendData(USART3,send_string[i]);
// while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//等待发送结束
//串口3接收数据示例代码
// while(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET);
// receive_string[i] = (USART_ReceiveData(USART3));
int main(void)
{
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
delay_init(168); //初始化延时函数
uart_init(115200); //初始化串口波特率为115200
uart3_init(115200);
LED_Init(); //初始化LED
LCD_Init(); //LCD初始化
tp_dev.init(); //触摸屏初始化
LCD_Clear(BLACK);
POINT_COLOR=YELLOW;//设置字体为黄色
BACK_COLOR = BLACK;
//初始化SIM900A
//发AT测试命令
//设置短信的新消息提示AT+CNMI=2,1;
{
unsigned char temp;
unsigned char send_string0[] = {"AT+CNMI=2,1x0dx0a"};
unsigned char send_string1[] = {"AT+CMGF=1rn"};
unsigned char send_string2[] = {"AT+CSCS="GSM"rn"};
for(temp=0;temp<2;temp++)
{
USART_SendData(USART3,'A');
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);
USART_SendData(USART3,'T');
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);
USART_SendData(USART3,'0x0d');
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);
USART_SendData(USART3,'0x0a');
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);
}
delay_ms(100);
for(temp=0;temp<13;temp++)//发送AT+CNMI=2,1x0dx0a
{
USART_SendData(USART3,send_string0[temp]);
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);
}
delay_ms(100);
for(temp=0;temp<11;temp++)//发送AT+CMGP=1rn
{
USART_SendData(USART3,send_string1[temp]);
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);
}
delay_ms(100);
for(temp=0;temp<15;temp++)//发送AT+CSCS="GSM"rn
{
USART_SendData(USART3,send_string2[temp]);
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);
}
delay_ms(100);
}
USART3_RX_STA = 0;
//以下代码构建短信发送菜单
{
Show_Str(30,30,200,24,"命令按钮区",24,1);
Show_Str(248,30,200,24,"文本区",24,1);
LCD_DrawRectangle(30,70,174,118);//AT测试按钮方程
Show_Str(42,82,200,24,"AT测试按钮",24,1);
LCD_DrawRectangle(248,70,452,118);//AT测试按钮的显示文字框
LCD_DrawRectangle(30,142,222,190);//SIM卡测试按钮方程
Show_Str(42,154,204,24,"卡状态测试按钮",24,1);
LCD_DrawRectangle(248,142,452,190);//
LCD_DrawRectangle(30,214,198,262);
Show_Str(42,226,204,24,"信号测试按钮",24,1);
LCD_DrawRectangle(248,214,452,262);
LCD_DrawLine(0,282,479,282);
Show_Str(42,338,204,24,"发送按钮",24,1);
LCD_DrawRectangle(30,326,162,374);
Show_Str(168,310,204,16,"发送号码",16,1);
LCD_ShowString(256,310,88,16,16,"17801017974");
LCD_DrawRectangle(248,302,452,334);
Show_Str(168,358,204,16,"发送内容",16,1);
LCD_ShowString(256,358,150,16,16,"this is test text");
LCD_DrawRectangle(248,350,452,382);
LCD_DrawLine(0,402,479,402);//画分割线
Show_Str(42,458,204,24,"接收按钮:",24,1);
LCD_DrawRectangle(30,446,162,494);
Show_Str(168,430,204,16,"来信号码:",24,1);
LCD_DrawRectangle(248,422,452,454);
Show_Str(168,478,204,16,"提示灯",16,1);
Show_Str(42,510,204,16,"短信内容:",24,1);
LCD_DrawRectangle(30,526,452,766);
//画个圆框用来做短信提示
{
int i;
POINT_COLOR=YELLOW;//设置字体为黄色
for(i=20;i<22;i++)
{
LCD_Draw_Circle(272,486,i);
}
}
}
//以下代码扫描触摸屏检测按键
while(1)
{
tp_dev.scan(0);
if(tp_dev.x[0]>30 && tp_dev.x[0]<174 && tp_dev.y[0]>70 &&tp_dev.y[0]<118)//AT测试按钮的按键区域
{
u8 i;
u8 send_string[] = {"ATrn"};
u8 receive_string[20] = {0};
char *p_display;
receive_string[19] = '