Toll-Free Customer Support 24/7

Gsm pic code


/*
 * Project name:
   GSM sim900 MODEM
 * Copyright
     (c) Researchdesignlab.com
 * Test configuration:
     MCU:             PIC16F877A
     Dev.Board:       PIC
     Oscillator:      20.0 MHz
     Software:  mikroC PRO for PIC v 4.6

*/

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

unsigned int k;
  unsigned char count222,message[50],J,message1,uart_rd,byte,i;

 void str_cpy1(unsigned char *str1,unsigned char b)
{
unsigned char i=0;
while(b<count222)
 {
message1=str1[b];
if(i==0)
 Lcd_Cmd(_LCD_CLEAR);
if(i==16)
 Lcd_Cmd(_LCD_CLEAR);
 i++;

b++;
}
}

void main()
{

 
 Lcd_Init();               // Initialize LCD
 Lcd_Cmd(_LCD_CLEAR);      // Clear display
 Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

 UART1_Init(9600);         // Initialize UART for GPS board connectivity
     DELAY_ms(1000);

  while(1)
  {
     UART1_Write_Text("AT+CMGD=1");
  UART1_Write(10);
  UART1_Write(13);
  Delay_ms(2000);

       uart_rd=0;
   while(uart_rd!='+')
   {
  if(UART1_Data_Ready()==1)
  {
 uart_rd = UART1_Read();

   }
   }
       Delay_ms(2000);
      UART1_Write_Text("AT+CMGR=1");
     UART1_Write(10);
      UART1_Write(13);

        for(i=0;i<6;i++)   
        {
        while(byte!='"')
        {
        while(!UART1_Data_Ready()==1);
        byte = UART1_Read();
        }
        byte=0;
        }


        while(byte !=10 )
        {
        while(!UART1_Data_Ready()==1);
        byte = UART1_Read();

        }

        count222=0;
        byte='0';
        k=0;



      while(byte!=13)
         {

      while(!UART1_Data_Ready()==1);
      byte = UART1_Read();
      message[k]=byte;
      k++;
      count222++;
           }

        count222--;
         str_cpy1(message,1);

          Delay_ms(2000);
      UART1_Write_Text("AT+CMGS=\"1234567890\"");
          Delay_ms(200);
       UART1_Write_Text("MESSAGE REVIED");
        UART1_Write(0x1A);

 }

  }



Back to top