嵌入式软件设计第10次实验报告

嵌入式软件设计第10次实验报告

 

学号:140201101                  姓名:刘子聪

 组别:第7组             实验地点:D19

 

一、实验目的:

1、了解GSM模块SIM900A的使用方法。

2、掌握使用串口发送AT命令驱动SIM900A的方法。

二、实验内容:

1.使用AT命令进行模块测试,拨打固定电话。

2.编写程序利用触摸屏完成任意电话的呼叫。

三、实验过程描述及结果展示:

实验器材:STM32F407开发板、LCD显示屏

SIM900A跳线帽连接方式:

长按PWR_KEY键后网络状态指示灯对应的状态:

常用AT指令_准备工作:

常用AT命令_拨打电话

#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);

}

}

实验结果展示:

四、总结及实验心得:

了解了GSM模块SIM900A的使用方法,掌握了使用串口发送AT命令驱动SIM900A的方法。

 

posted @ 2017-03-26 19:19  bgd140201101  阅读(168)  评论(0编辑  收藏  举报