嵌入式软件设计第10次实验报告
学号:140201229 姓名:何丹
组别:第4组 实验地点:D19
一、实验目的:
1、了解GSM模块SIM900A的使用方法。
2、掌握使用串口发送AT命令驱动SIM900A的
方法。
二、实验内容:
1.使用AT命令进行模块测试,拨打固定电话。
2.编写程序利用触摸屏完成任意电话的呼叫。
三、实验过程描述及结果展示:
设备:移动SIM卡,充电器,SIM900A板子,连接线,耳机
(一)硬件处理过程
1、用串口连接STM32_MODE与SIM900A,并将SIM卡装进SIM900A卡套里。
2、将耳机连接到(滑动按钮调节音量大小,开关控制语音)SIM900A板子上。mic与耳机口连接,phone与电话相连接。
3、连接电源。供电后长按开机按钮,使电话开机。
4、将USART1跳线棒和USART3跳线棒拔掉,用跳线将COM3TX(发送)与COM1RXD(接收),COM1RX(发送)与 COM3TXD(接收)相连接。
(二)测试处理过程: AT命令_拨打电话
1测试本机是否可用(AT+CPIN?)
2测试本机是否有信号(AT+CSQ)
3拨打任意电话号码(ATD+号码)
(三)实验处理过程:液晶屏与触摸屏显示电话菜单
通过usart3串口将呼叫命令ATD+号码+分号+传送出去
Main函数设计:
#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"
const u16 POINT_COLOR_TBL[OTT_MAX_TOUCH]={RED,GREEN,BLUE,BROWN,GRED};
unsigned char Dialling[12];
char number[20] = "";
u8 iscalling=0;
void addnumbutton(u16 x,u16 y,u8 *p){
LCD_Fill(x,y,x+60,y+60,BROWN);
POINT_COLOR=BLACK;
BACK_COLOR = BROWN;
LCD_ShowString(x+24,y+18,24,24,24,p);
}
void sendtext(char *p){
while(*p!='\0'){
USART_SendData(USART3,*p);
delay_ms(50);
p++;
}
USART_SendData(USART3,0x0D);
delay_ms(50);
USART_SendData(USART3,0x0A);
}
void call(){
char text[40]="ATD";
strcat(text,number);
strcat(text,";");
printf("%s",text);
sendtext(text);
LCD_Fill(120,40,460,66,BROWN);
LCD_Fill(122,42,458,64,BLACK);
//number="CALLING";
LCD_ShowString(122,42,336,24,24,"CALLING");
LCD_Fill(60,600,420,680,BROWN);
POINT_COLOR=BLACK;
BACK_COLOR = BROWN;
LCD_ShowString(204,626,96,144,24,"HANGUP");
iscalling=1;
}
void hangup(){
char text[40]="ATH";
sendtext(text);
LCD_Fill(120,40,460,66,BROWN);
LCD_Fill(122,42,458,64,BLACK);
number[0]='\0';
LCD_Fill(60,600,420,680,BROWN);
POINT_COLOR=BLACK;
BACK_COLOR = BROWN;
LCD_ShowString(216,626,96,24,24,"CALL");
iscalling=0;
}
int main(void)
{
delay_init(168); //初始化延时函数
uart_init(115200); //初始化串口波特率为115200
uart3_init(115200);
sendtext("AT+CPIN?");
LCD_Init(); //LCD初始化
tp_dev.init(); //触摸屏初始化
LCD_Clear(BLACK);
POINT_COLOR=YELLOW;//设置字体为黄色
BACK_COLOR = BLACK;
LCD_ShowString(30,40,210,24,24,"NUMBER:");
LCD_Fill(120,40,460,66,BROWN);
LCD_Fill(122,42,458,64,BLACK);
addnumbutton(60,120,"1");
addnumbutton(210,120,"2");
addnumbutton(360,120,"3");
addnumbutton(60,240,"4");
addnumbutton(210,240,"5");
addnumbutton(360,240,"6");
addnumbutton(60,360,"7");
addnumbutton(210,360,"8");
addnumbutton(360,360,"9");
addnumbutton(60,480,"*");
addnumbutton(210,480,"0");
addnumbutton(360,480,"#");
LCD_Fill(60,600,420,680,BROWN);
POINT_COLOR=BLACK;
BACK_COLOR = BROWN;
LCD_ShowString(216,626,96,24,24,"CALL");
while(1){
tp_dev.scan(0);
if(tp_dev.x[0]>60&&tp_dev.y[0]>120&&tp_dev.x[0]<120&&tp_dev.y[0]<180){
strcat(number,"1");
LCD_ShowString(122,42,336,24,24,number);
while(tp_dev.x[0]!=65535){tp_dev.scan(0);}
}
if(tp_dev.x[0]>210&&tp_dev.y[0]>120&&tp_dev.x[0]<270&&tp_dev.y[0]<180){
strcat(number,"2");
LCD_ShowString(122,42,336,24,24,number);
while(tp_dev.x[0]!=65535){tp_dev.scan(0);}
}
if(tp_dev.x[0]>360&&tp_dev.y[0]>120&&tp_dev.x[0]<420&&tp_dev.y[0]<180){
strcat(number,"3");
LCD_ShowString(122,42,336,24,24,number);
while(tp_dev.x[0]!=65535){tp_dev.scan(0);}
}
if(tp_dev.x[0]>60&&tp_dev.y[0]>240&&tp_dev.x[0]<120&&tp_dev.y[0]<300){
strcat(number,"4");
LCD_ShowString(122,42,336,24,24,number);
while(tp_dev.x[0]!=65535){tp_dev.scan(0);}
}
if(tp_dev.x[0]>210&&tp_dev.y[0]>240&&tp_dev.x[0]<270&&tp_dev.y[0]<300){
strcat(number,"5");
LCD_ShowString(122,42,336,24,24,number);
while(tp_dev.x[0]!=65535){tp_dev.scan(0);}
}
if(tp_dev.x[0]>360&&tp_dev.y[0]>240&&tp_dev.x[0]<420&&tp_dev.y[0]<300){
strcat(number,"6");
LCD_ShowString(122,42,336,24,24,number);
while(tp_dev.x[0]!=65535){tp_dev.scan(0);}
}
if(tp_dev.x[0]>60&&tp_dev.y[0]>360&&tp_dev.x[0]<120&&tp_dev.y[0]<420){
strcat(number,"7");
LCD_ShowString(122,42,336,24,24,number);
while(tp_dev.x[0]!=65535){tp_dev.scan(0);}
}
if(tp_dev.x[0]>210&&tp_dev.y[0]>360&&tp_dev.x[0]<270&&tp_dev.y[0]<420){
strcat(number,"8");
LCD_ShowString(122,42,336,24,24,number);
while(tp_dev.x[0]!=65535){tp_dev.scan(0);}
}
if(tp_dev.x[0]>360&&tp_dev.y[0]>360&&tp_dev.x[0]<420&&tp_dev.y[0]<420){
strcat(number,"9");
LCD_ShowString(122,42,336,24,24,number);
while(tp_dev.x[0]!=65535){tp_dev.scan(0);}
}
if(tp_dev.x[0]>60&&tp_dev.y[0]>480&&tp_dev.x[0]<120&&tp_dev.y[0]<540){
strcat(number,"*");
LCD_ShowString(122,42,336,24,24,number);
while(tp_dev.x[0]!=65535){tp_dev.scan(0);}
}
if(tp_dev.x[0]>210&&tp_dev.y[0]>480&&tp_dev.x[0]<270&&tp_dev.y[0]<540){
strcat(number,"0");
LCD_ShowString(122,42,336,24,24,number);
while(tp_dev.x[0]!=65535){tp_dev.scan(0);}
}
if(tp_dev.x[0]>360&&tp_dev.y[0]>480&&tp_dev.x[0]<420&&tp_dev.y[0]<540){
strcat(number,"#");
LCD_ShowString(122,42,336,24,24,number);
while(tp_dev.x[0]!=65535){tp_dev.scan(0);}
}
if(tp_dev.x[0]>60&&tp_dev.y[0]>600&&tp_dev.x[0]<420&&tp_dev.y[0]<680){
if(iscalling){
hangup();
}else{
call();
}
while(tp_dev.x[0]!=65535){tp_dev.scan(0);}
}
delay_ms(5);
}
}