Arm 从LPC2148向移动电话发送SMS
我昨天发布了一个类似的问题,但我无法编辑代码并发布更多问题,所以我将其重新发布在这里。我已将gsm调制解调器连接到LPC2148,正在向手机发送一条简单的信息“vehicle”。我把打印语句放在中间,这样我就知道程序在哪里了。它运行所有打印语句,但消息未发送 这是代码 Main.cArm 从LPC2148向移动电话发送SMS,arm,gsm,at-command,uart,lpc,Arm,Gsm,At Command,Uart,Lpc,我昨天发布了一个类似的问题,但我无法编辑代码并发布更多问题,所以我将其重新发布在这里。我已将gsm调制解调器连接到LPC2148,正在向手机发送一条简单的信息“vehicle”。我把打印语句放在中间,这样我就知道程序在哪里了。它运行所有打印语句,但消息未发送 这是代码 Main.c #include "i2c.h" #include "LPC214x.H" // LP
#include "i2c.h"
#include "LPC214x.H" // LPC2148 MPU Register
#include <stdio.h>
#include "gsm.h"
#include "lcd.h"
#include "buzzer.h"
extern int msgflag;
/* Main Program Start Here */
int main(void)
{
PINSEL0 = 0x00000000; // Enable GPIO on all pins
PINSEL1 = 0x00000000;
PINSEL2 = 0x00000000;
lcd_init(); // Initial LCD
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
//lcd_print("gps"); // Display LCD Line-1
lcd_print("gsm");
gsmperform();
}
#include<lpc214x.h> /*Header file*/
#include "gsm.h" //header file
#include "lcd.h"
extern unsigned char cmgf[]="AT+CMGF=1"; //Text format in GSM modem
extern unsigned char cmgs[]="AT+CMGS=\"+919844420844\""; //Mobile number to which the msg is sent
//extern unsigned char msg[]="*\0"; //secret code
extern unsigned char msg[]="vehicle"; //secret code
extern unsigned char readall[]="AT+CMGR=\"REC UNREAD\"\r\n";
//static unsigned char lat[10];
//static unsigned char lon[11];
//extern int blink;
unsigned char content[7];
void txu1(unsigned char data) //Transmit a byte of data through UART1
{
while(!(U1LSR & 0x20)); // Wait until UART1 ready to send character
U1THR = data;
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("data"); // Display LCD Line-1
}
unsigned char rxu1()
{
unsigned char p;
while ((U1LSR&0x01)!=1);
p=U1RBR;
return p;
}
/*unsigned char rxu0()
{
unsigned char p;
while ((U0LSR&0x01)!=1);
p=U0RBR;
return p;
}
*/
void sendstring(unsigned char *p) //Sends a string of data through UART1
{
while(1)
{
if(*p=='\0') break;
txu1(*p++);
}
}
void delaygsm() //delay function
{
int i,j;
for(i=0;i<60000;i++)
for(j=0;j<51;j++);
}
void delay2() //delay function
{
int i,j;
for(i=0;i<60000;i++)
for(j=0;j<200;j++);
}
unsigned char recuart1() //recieves a byte from UART1
{
unsigned char p;
while ((U1LSR&0x01)!=1);
p=U1RBR;
return p;
}
void sendmsg(void)
{
sendstring(cmgf);
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("cmgf"); // Display LCD Line-1
txu1(0x0d); // equivalent of
txu1(0x0a); // enter key
delaygsm();
sendstring(cmgs);
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("cmgs"); // Display LCD Line-1
txu1(0x0d);
txu1(0x0a);
delaygsm();
sendstring(msg);
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("msg"); // Display LCD Line-1
//sendstring(lat);
//sendstring(lon);
txu1(0x1a);
delay2();
txu1(0x1a);
}
void initgsm() //Initialization of UART0,UART1 and ISR
{
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("begin init"); // Display LCD Line-1
U0LCR=0x83;
U0DLL=0x61;
U0DLM=0x00;
U0LCR=0x03;
U1LCR=0x83;
U1DLL=0x61;
U1DLM=0x00;
U1LCR=0x03;
U1IER=0x01;
U1FCR=0x07;
*/
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("end init"); // Display LCD Line-1
sendmsg();
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("in sendmsg"); // Display LCD Line-1
}
void gsmperform(void)
{
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("begin gsm"); // Display LCD Line-1
PINSEL0|=0x00050005;
PINSEL1|=0x00000000;
PINSEL2|=0x00000000;
/* nsk PINSEL0 &= 0xFFF0FFFF; // Reset P0.8,P0.9 Pin Config
PINSEL0 |= 0x00010000; // Select P0.8 = TxD(UART1)
PINSEL0 |= 0x00040000; // Select P0.9 = RxD(UART1)
*/
initgsm();
sendstring("ATe0\r\n");
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("ATe0"); // Display LCD Line-1
delaygsm();
sendstring("AT+CMGD=1,4\r\n");
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("AT+CMGD"); // Display LCD Line-1
delaygsm();
sendstring("AT+CNMI=1,0,0,0\r\n");
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("AT+CNMI"); // Display LCD Line-1
delaygsm();
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("end gsm"); // Display LCD Line-1
}
#包括“i2c.h”
#包括“LPC214x.H”//LPC2148 MPU寄存器
#包括
#包括“gsm.h”
#包括“lcd.h”
#包括“蜂鸣器h”
外部-内部msgflag;
/*主程序从这里开始*/
内部主(空)
{
PINSEL0=0x00000000;//在所有管脚上启用GPIO
PINSEL1=0x00000000;
PINSEL2=0x00000000;
lcd_init();//初始lcd
lcd_write_control(0x01);//清除显示(清除显示,设置DD RAM地址=0)
转到光标(0x00);//设置光标行-1
//lcd_print(“gps”);//显示lcd第1行
lcd_打印(“gsm”);
gsmperform();
}
gsm.c
#include "i2c.h"
#include "LPC214x.H" // LPC2148 MPU Register
#include <stdio.h>
#include "gsm.h"
#include "lcd.h"
#include "buzzer.h"
extern int msgflag;
/* Main Program Start Here */
int main(void)
{
PINSEL0 = 0x00000000; // Enable GPIO on all pins
PINSEL1 = 0x00000000;
PINSEL2 = 0x00000000;
lcd_init(); // Initial LCD
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
//lcd_print("gps"); // Display LCD Line-1
lcd_print("gsm");
gsmperform();
}
#include<lpc214x.h> /*Header file*/
#include "gsm.h" //header file
#include "lcd.h"
extern unsigned char cmgf[]="AT+CMGF=1"; //Text format in GSM modem
extern unsigned char cmgs[]="AT+CMGS=\"+919844420844\""; //Mobile number to which the msg is sent
//extern unsigned char msg[]="*\0"; //secret code
extern unsigned char msg[]="vehicle"; //secret code
extern unsigned char readall[]="AT+CMGR=\"REC UNREAD\"\r\n";
//static unsigned char lat[10];
//static unsigned char lon[11];
//extern int blink;
unsigned char content[7];
void txu1(unsigned char data) //Transmit a byte of data through UART1
{
while(!(U1LSR & 0x20)); // Wait until UART1 ready to send character
U1THR = data;
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("data"); // Display LCD Line-1
}
unsigned char rxu1()
{
unsigned char p;
while ((U1LSR&0x01)!=1);
p=U1RBR;
return p;
}
/*unsigned char rxu0()
{
unsigned char p;
while ((U0LSR&0x01)!=1);
p=U0RBR;
return p;
}
*/
void sendstring(unsigned char *p) //Sends a string of data through UART1
{
while(1)
{
if(*p=='\0') break;
txu1(*p++);
}
}
void delaygsm() //delay function
{
int i,j;
for(i=0;i<60000;i++)
for(j=0;j<51;j++);
}
void delay2() //delay function
{
int i,j;
for(i=0;i<60000;i++)
for(j=0;j<200;j++);
}
unsigned char recuart1() //recieves a byte from UART1
{
unsigned char p;
while ((U1LSR&0x01)!=1);
p=U1RBR;
return p;
}
void sendmsg(void)
{
sendstring(cmgf);
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("cmgf"); // Display LCD Line-1
txu1(0x0d); // equivalent of
txu1(0x0a); // enter key
delaygsm();
sendstring(cmgs);
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("cmgs"); // Display LCD Line-1
txu1(0x0d);
txu1(0x0a);
delaygsm();
sendstring(msg);
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("msg"); // Display LCD Line-1
//sendstring(lat);
//sendstring(lon);
txu1(0x1a);
delay2();
txu1(0x1a);
}
void initgsm() //Initialization of UART0,UART1 and ISR
{
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("begin init"); // Display LCD Line-1
U0LCR=0x83;
U0DLL=0x61;
U0DLM=0x00;
U0LCR=0x03;
U1LCR=0x83;
U1DLL=0x61;
U1DLM=0x00;
U1LCR=0x03;
U1IER=0x01;
U1FCR=0x07;
*/
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("end init"); // Display LCD Line-1
sendmsg();
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("in sendmsg"); // Display LCD Line-1
}
void gsmperform(void)
{
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("begin gsm"); // Display LCD Line-1
PINSEL0|=0x00050005;
PINSEL1|=0x00000000;
PINSEL2|=0x00000000;
/* nsk PINSEL0 &= 0xFFF0FFFF; // Reset P0.8,P0.9 Pin Config
PINSEL0 |= 0x00010000; // Select P0.8 = TxD(UART1)
PINSEL0 |= 0x00040000; // Select P0.9 = RxD(UART1)
*/
initgsm();
sendstring("ATe0\r\n");
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("ATe0"); // Display LCD Line-1
delaygsm();
sendstring("AT+CMGD=1,4\r\n");
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("AT+CMGD"); // Display LCD Line-1
delaygsm();
sendstring("AT+CNMI=1,0,0,0\r\n");
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("AT+CNMI"); // Display LCD Line-1
delaygsm();
lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0)
goto_cursor(0x00); // Set Cursor Line-1
lcd_print("end gsm"); // Display LCD Line-1
}
#include/*头文件*/
#包括“gsm.h”//头文件
#包括“lcd.h”
外部无符号字符cmgf[]=“AT+cmgf=1”//GSM调制解调器中的文本格式
外部无符号字符cmgs[]=“AT+cmgs=\”+919844420844\”//向其发送消息的移动电话号码
//外部无符号字符消息[]=“*\0”//密码
外部无符号字符消息[]=“车辆”//密码
extern unsigned char readall[]=“AT+CMGR=\”REC UNREAD\“\r\n”;
//静态无符号字符lat[10];
//静态无符号字符lon[11];
//外-内闪烁;
无符号字符内容[7];
void txu1(无符号字符数据)//通过UART1传输一个字节的数据
{
while(!(U1LSR&0x20));//等待UART1准备好发送字符
U1THR=数据;
lcd_write_control(0x01);//清除显示(清除显示,设置DD RAM地址=0)
转到光标(0x00);//设置光标行-1
lcd_打印(“数据”);//显示lcd第1行
}
无符号字符rxu1()
{
无符号字符p;
而((U1LSR&0x01)!=1);
p=U1RBR;
返回p;
}
/*无符号字符rxu0()
{
无符号字符p;
而((U0LSR&0x01)!=1);
p=U0RBR;
返回p;
}
*/
void sendstring(unsigned char*p)//通过UART1发送数据字符串
{
而(1)
{
如果(*p=='\0')中断;
txu1(*p++);
}
}
void delaygsm()//延迟函数
{
int i,j;
对于(i=0;i,这里有两种方法从根本上说是处理AT命令的错误方法
首先,决不,决不,决不,决不,决不,决不使用函数delaygsm这样的延迟。您必须更改处理逻辑,以便在发送命令后,除了从调制解调器读取响应外,您什么也不做,直到在开始下一个命令之前获得最终结果代码。有关详细信息,请参阅
使用ATE0关闭echo只会使您需要解析的文本稍微减少,但没有办法。您必须阅读并解析调制解调器返回的响应。这并不复杂,只需按照上面链接的答案中给出的说明进行操作即可
另外请注意,AT命令行应仅以'\r'
(或写为0x0d
)终止,而不应以其他方式终止,有关详细信息,请参阅