#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    15
    Rep Power
    0

    '@' symbol in received SMS through GSM modem


    Hi, I'm using PIC18F4520 and C18 complier to send sms through a Siemens TC35 GSM modem.

    My recieved SMS reads:

    Password: @7818@


    I dont understand how the @ comes after every transmission sent to the GSM.

    Code:
    #include <p18F4520.h>
    #include <delays.h>
    #include <stdio.h>
    #include <usart.h>
    #include <stdlib.h>
    #include <system4520.h>
    
    void usart_init();
    
    void main(void)
    {
    	int num1 = rand() % 10000; 
    	char number[5];
    	
    	int z = 0x1a;
    		
    	usart_init();
    
    	itoa(num1, number);
    
    	putrsUSART("AT\r\n");
    	Delay10KTCYx(50);
    	putrsUSART("AT+CMGF=1\r\n");
    	Delay10KTCYx(50);
    	putrsUSART("AT+CMGS=0123310587\r\n");
    	Delay10KTCYx(50);
    	putrsUSART("Password: ");
    	Delay10KTCYx(50);
    	putsUSART(number);
    	Delay10KTCYx(50);
    	putcUSART(z);
    	Delay10KTCYx(50);
    	while(1);
    }
    
    void usart_init(void)
    { 
    	OpenUSART(USART_TX_INT_OFF &		//Transmit interrupt off
    	USART_RX_INT_ON &			//Receive interrupt on
    	USART_ASYNCH_MODE &			//Asynchronous mode
    	USART_EIGHT_BIT &			//8-bit data
    	USART_CONT_RX &				//Continuous reception
    	USART_BRGH_HIGH,25);//9600 baud3
    #include <p18F4520.h>
    #include <delays.h>
    #include <stdio.h>
    #include <usart.h>
    #include <stdlib.h>
    #include <system4520.h>
    
    void usart_init();
    
    void main(void)
    {
    	int num1 = rand() % 10000; 
    	char number[5];
    	
    	int z = 0x1a;
    		
    	usart_init();
    
    	itoa(num1, number);
    
    	putrsUSART("AT\r\n");
    	Delay10KTCYx(50);
    	putrsUSART("AT+CMGF=1\r\n");
    	Delay10KTCYx(50);
    	putrsUSART("AT+CMGS=0123310587\r\n");
    	Delay10KTCYx(50);
    	putrsUSART("Password: ");
    	Delay10KTCYx(50);
    	putsUSART(number);
    	Delay10KTCYx(50);
    	putcUSART(z);
    	Delay10KTCYx(50);
    	while(1);
    }
    
    void usart_init(void)
    { 
    	OpenUSART(USART_TX_INT_OFF &		//Transmit interrupt off
    	USART_RX_INT_ON &			//Receive interrupt on
    	USART_ASYNCH_MODE &			//Asynchronous mode
    	USART_EIGHT_BIT &			//8-bit data
    	USART_CONT_RX &				//Continuous reception
    	USART_BRGH_HIGH,25);//9600 baud3
    }
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,381
    Rep Power
    1871
    Code:
    	putrsUSART("Password: ");
    	Delay10KTCYx(50);
    	putsUSART(number);
    What's the difference between these two functions?

    Step 2 is create a utility function to send a string and wait.
    Code:
    void sendString ( const char *msg ) {
      putrsUSART(msg);
      Delay10KTCYx(50);
    }
    
    void main(void)
    {
      int num1 = rand() % 10000; 
      char number[5];
      char eom[] = "\x1a";
        
      usart_init();
    
      itoa(num1, number);
    
      sendString("AT\r\n");
      sendString("AT+CMGF=1\r\n");
      sendString("AT+CMGS=0123310587\r\n");
      sendString("Password: ");
    //  sendString(number);
      sendString("1234");
      sendString(eom);
      while(1);
    }
    Does this code send the password correctly?
    If it does, then try commenting out the "1234" and try sending number instead.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo