GSM SIM900A模块与PIC18F4520控制器接口



我正在与GSM(SIM900A)与PIC18F4520 MicroController连接的模块合作。

在这里,我试图通过串行的PIC控制器发送SMS到GSM模块,但无法从GSM中收到任何响应,也无法接收任何消息。

当我尝试将GSM模块连接到高端时,我就可以发送SMS。以类似的方式,当我试图从图片到高端的命令发送命令时,我会连续接收命令。

代码下面

#include<p18f4520.h>      /* Header File */
#include<string.h>
void delay_ms(int ms);
void Data(char Value); 
void Cmd(char Value);
char temp;
void main() 
{
   char tocheck[] ="AT";/*Basic command to test GSM is working or not */
   char sendingsmsmode[]="AT+CMGF=1";/* To change the GSM Module in SMS 
  sending Mode */
   char newsms[]="AT+CMGS=918500923915";/*Set Text mode for SMS */
 char msg[]="WelcometoGSM";/* The text which you want to send */
 char terminator=0x1A;
 int i=0;
  TRISC =   0x80;         /* RC6=0 (O/P) RC7=1(I/P)                    */           
 SPBRG  =   0x33;         /* Serial Port Baud rate Generator (9600)    */
 TXSTA  =   0X24;         /* Transmission Enabling(TXEN=1,SYNC=0,BRGH=1) 
 */
 RCSTA  =   0X90;         /* Rception Enabling (SPEN=1,CREN=1)         */
 TRISC=0X00;               /*  (RC1,RC0 ->O/P Setting by Zero)                 
   */
 TRISD=0X00;                 /*  PORTD (0 - 7)pins Config as Output                  
       */
   while(tocheck[i]!=''){
    while(TXSTAbits.TRMT==0);
    TXREG=tocheck[i];
    delay_ms(30);
    i++;
  }
   i=0;
   while(sendingsmsmode[i]!=''){
    while(TXSTAbits.TRMT==0);
    TXREG=sendingsmsmode[i];
    delay_ms(30);
    i++;
  }
  i=0;
  while(newsms[i]!=''){
    while(TXSTAbits.TRMT==0);
    TXREG=newsms[i];
    delay_ms(30);
    i++;
   }
   i=0;
  while(msg[i]!=''){
    while(TXSTAbits.TRMT==0);
    TXREG=msg[i];
    delay_ms(30);
    i++;
}
  TXREG=terminator;
 delay_ms(3000);
 while(1);
 }
  void Cmd(char Value)
   {
 PORTD=Value;
 PORTCbits.RC1=0;                /*  RC1=0(RS=0)        [Command Registr 
 Selection])    */
 PORTCbits.RC0=0;                /*  RC0=0(R/W=0)   [Write Process])                
   */
 PORTCbits.RC2=1;                /*  RC2=1(Enable=1)    [Enable Line ON]                
  */
 delay_ms(4);                    /*  Minimun Delay For Hold On Data                      
   */
 PORTCbits.RC2=0;                /*  RC2=0(Enable=0)    [Enable Line OFF]               
 */
    }   
void Data(char Value)
{
 PORTD=Value;
 PORTCbits.RC1=1;               /*  RC1=1(RS=1)     [Data Registr 
Selection])       */
 PORTCbits.RC0=0;                /*  RC0=0(R/W=0)   [Write Process])                
   */
 PORTCbits.RC2=1;               /*  RC2=1(Enable=1) [Enable Line ON]                
   */
 delay_ms(4);                   /*  Minimun Delay For Hold On Data                      
    */
 PORTCbits.RC2=0;               /*  RC2=0(Enable=0) [Enable Line OFF]               
    */
    }
  void delay_ms(int ms)
{
int i,count;
for(i=1;i<=ms;i++)
{
    count=498;
    while(count!=1)
    {
        count--;
    }
     }
   }

您需要在发送到调制解调器的每个字符串后,需要发送CR或CR LF(分别为13和10)。

使用诸如Hyperterminal之类的终端模拟器时,请按Enter键,对吗?如果您不按该键,调制解调器不知道命令已终止并且必须执行。您的固件也必须同样。

还有更多:您必须允许一些延迟,并且应该读回调制解调器响应,但这可能是第二步;首先,要检查设置在基本级别上工作,您必须发送" AT",然后是CR,然后查看调制解调器是否与OK回复( CR和LF ...)。

修改

char tocheck[] ="AT";

char tocheck[] ="ATr";  // the r is the CR (carriage return)

,如果所有连接良好,您将看到调制解调器会回复。

最新更新