Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to interface GSM modem with PIC16F877A and send sms from PIC16F877A to GSM MODEM

Status
Not open for further replies.

Bernard jackson

Newbie level 4
Joined
Feb 10, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Tanzania
Activity points
1,366
Hi....
I need to interface GSM modem with micro controller PIC16F877A and send some AT commands along with a message, to send an sms, to a GSM modem through/from a micro controller PIC16F877A as a part of my BE project. I don't have much knowledge of a GSM modem. Which one should I use...?
I know that micro controller and the modem are interfaced through a serial port but how do i send the command and what are the actual connections......???

plz help me.
my email: mahiya_b@yahoo.com
 

go thru AT commands first and then sample programs to completely understand its operation
 

i need AT command to auto answer a voice call,i'm using SIM900A,ATSO dosnt seem to work.
 

thanks you for the help, you made my day..! i succeeded to write and interface but still the gsm does not respond to receive sms
please anyone can help to check it, and go thru my code and correct the wrong line by running it,
i will accept even new style of writting again a simple code.
I will be thankful, kindly and humble for your support about my final project

here below is my code:

Code:
/ LCD connection
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;

 // Manchester module connections
sbit MANRXPIN at RC6_bit;
sbit MANRXPIN_Direction at TRISC6_bit;
sbit MANTXPIN at RC7_bit;
sbit MANTXPIN_Direction at TRISC7_bit;
// End Manchester module connections

//prototype
  //void pic_Send_SMS();
  //void Read_SMS(void);
  //void gsm_SMS_Init(void);
  void writeWarning();
  void writeNormal();
  void Move_Delay();
  //void delay(unsigned long ctr);
  void Man_send_init();
  //end of prototype
  
// Declaration start
char output[70] = " LOW OIL LEVEL T4 ILALA ";
unsigned int *counter, i;
char return_gsm[2];
char Gsm_Receive[50];
char Gsm_Msg[100];
unsigned int THRESHOLD = 0xCd;
unsigned int read_value = 0;
char index, character;
char *set[] = " LOW OIL LEVEL T4 ILALA ";
char *text1 = " !! WARNING !!";
char *text2 = " LOW OIL LEVEL ";
char *text3 = " T4 ILALA_EAST ";
char *text5 = " SAFE OPERATION ";
char *text4 = " TRANSFORMER AT ";
//char *COMError = " Initialization error";
char *sms = " LOW OIL LEVEL T4 ILALA_EAST ";
int change = 0;         //  change is 0 for  safe operation and 1 for unsafe operation
int ANSEL, ANSELH, C1ON_bit, C2ON_bit;
char USART_rd[] = "AT";
char USART_rd1[]= "AT+CMGF=1";
char USART_rd2[]= "AT+CMGR=1";
char USART_rd3[]= "AT+CMGS= 1";
// End of declaration part

void main()
{
  // pic16f877A

 ANSEL  = 0x02;              // Configure AN1 pin as analog
 ANSELH = 0;                 // Configure other AN pins as digital I/O
 C1ON_bit = 0;               // Disable comparators
 C2ON_bit = 0;

 TRISB = 0;                    // PORTB as output port
 TRISD = 0;                     // PORTD as output port
 TRISC = 0;                   //  PORTC as output port
 TRISA = 0X07;               // PORTA as the input/output 0000 0111
 UART1_Init(9615);              // Initialize Soft UART module at 9600 bps
 Move_Delay();                // Wait for UART module to stabilize
 Lcd_Init();                        // Initialize LCD connected to PORTB
 Lcd_Cmd(_LCD_CLEAR);              // clear Display
 Lcd_Cmd(_LCD_CURSOR_OFF);        // Turn cursor off
 Lcd_Out(1, 1, text4);             // "transformer at" text
 Lcd_Out(1, 1, text5);            // display safe operation on lcd

 do
   {
    read_value = ADC_Read(1);   // Get 10-bit results of AD conversion
    PORTD = read_value;         // Send lower 8 bits to PORTB

 if(read_value > THRESHOLD )                    // if true mean abnormal operation
   {
       if(change == 0)
       {
          writeWarning();                  // call function to display warning on lcd and send sms to GSM
          //gsm_SMS_Init();              // initialize gsm modem
           //pic_Send_SMS();                    //send an sms
           //Read_SMS();

          change = 1;
       }

   }
     else    // safe
   {
      if(change == 1)              // if the previous condition is exit i.e unsafe operation
      {

        writeNormal();         // call function to display safe operation on lcd
        change = 0;           // set to safe operation
      }
   }

  } while(1);
}

void writeWarning()
{
      Lcd_Init();
      Lcd_Cmd(_LCD_CLEAR);              // clear Display
      Lcd_Cmd(_LCD_CURSOR_OFF);        // Turn cursor off
      Lcd_Out(1,1,text1);
      Lcd_Out(2, 1, text2);                  // Print  text to LCD, first row
      Lcd_Out(3, 1, text3);                 // Print text1 to LCD 3rd row

}
void writeNormal()
{
   Lcd_Init();
   Lcd_Cmd(_LCD_CLEAR);              // clear Display
   Lcd_Cmd(_LCD_CURSOR_OFF);        // Turn cursor off
   Lcd_Out(1,1, text4 );             // text to display
   Lcd_Out(1, 1, text5);            // display normal operation on lcd


}

void Move_Delay()       // function used for text delay
{
  Delay_ms(500);       //  delay for half a second
}

void Read_SMS(void)
{
   pic_Send_SMS();         // send text
   UART1_Write_Text("AT+CGMM= 1");    // GET supported frequency band
   UART1_Write_Text("AT");    // send AT to the GSM
   //Move_Delay();               // Delay
   UART1_Write_Text("AT+CMGF=1 ");      // sms configuration  /SET TEXT MODE
   //Move_Delay();
   UART1_Write_Text("AT+CNMA= 1");    //ACKNOWLEDGE NEW SMS
   UART1_Write_Text("AT+CMGR= 1\n\r");
   UART1_Write_Text("AT+CGMR= 1\n\r");      // request revision identification
   //Move_Delay();
   UART1_Write_Text("AT+CPMS= output");    // store from the ram  (BM)
   UART1_Write_Text("AT+CMGL= 1");      //list message
   UART1_Write_Text("AT+CMGR= 1\n\r");      // Read message
   //Move_Delay();
   UART1_Write_Text("AT+CPMS= output");    // read from the ram  (BM)
   while (UART1_Data_Ready() == 0) ;
   for(i=0;i<=65;i++)
   {
     output[i]=UART1_Read();
   }
   
}
void pic_Send_SMS()
{
      do
      {
          //gsm_SMS_Init();
          //Read_SMS();                         //to read the sms in location 1
          UART1_Write_Text("AT+CSMS= 1");       // SMS AT command
          UART1_Write_Text("AT+CGMI= 1");       //gives manufacturer identification
          UART1_Write_Text("AT+CMGS= +0682006300");    //Write "AT+CMGS= 1"
          UART1_Write(0x0D);                 // mean (Enter)
          Move_Delay();                        // Delay
          UART1_Write_Text("AT+CMGW= 1");     // WRITE message
          UART1_Write_Text("AT+CMSS= 1");      //SEND MESSAGE
          //UART1_Write_Text("AT+CMGS= ");    //Write "AT+CMGS="
          UART1_Write(0x22);
          UART1_Write_Text("AT = +255682006300");   // Phone Number  SMS send to
          UART1_Write(0x22);
          UART1_Write(0x0D);            // mean (ENTER)
          UART1_Write_Text("\n\r");
          Move_Delay();                   // Delay
          UART1_Write_Text(output);       // Word to be sent
          UART1_Write(26);                     // send ctrl + Z
          Move_Delay();                      // Delay

      }
        while(1);

}
</pre>

my email: bernardjm88@gmail.com
 

At+cmgf = 1 0d
at+cmgs="+0682006300" 0d (REMEMBER INVERTED COMMAS MUST B INLCUDED)
mobile send (>)
write any txt, terminate by ctlr+z (ascii = 26)
wait for ok


at+cmgr = 0 for unread sms
at+cmgr = 1 for last read sms
save it to array
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top