Using 18f452 send/ receive sms to GSM A900 , mikroC

Status
Not open for further replies.
unable to receive gsm using pic16

here is code
plz help me someone




Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
unsigned char sms_in[80];
unsigned char dat[80];
bit flag;
char i=0;
char x;
char mob2[12];
 
void interrupt()
 {
  if (PIR1.RCIF==1)
  { 
  do
  {
    if (UART1_Data_Ready())
    {
     sms_in[i] = UART1_Read();
     i++;
     }
  }
    while(sms_in[i]!='K');
    sms_in[i]='\0';
 
   }
}
 
void main()
{
     INTCON.GIE = 1;
     INTCON.PEIE = 1;
     PIE1.RCIE=1;
 
     TRISC5_bit = 0;
     UART1_Init(9600);
     Delay_ms(500);
    UART1_Write_Text("AT");
Delay_ms(1500);
UART1_Write_Text("AT+CMGF=1");
Delay_ms(1500);
 
 
UART1_Write_Text("AT+CMGR=1");
Delay_ms(1500);
 
while (1)
      {
 
      if(sms_in[i]=='+')
       {
          if(sms_in[i+1]=='C' && sms_in[i+2]=='M' && sms_in[i+3]=='T' && sms_in[i+4]=='I')
          {
            x=sms_in[i+5];      //index number
 
 
       /*     printf("AT+CMGR=");
            putchar(x);
            putchar(0x0D);  // enter
            delay_ms(150);   */
 
            while(sms_in[i]!='+');
 
               if(sms_in[i+1]=='C' && sms_in[i+2]=='M' && sms_in[i+3]=='G' && sms_in[i+4]=='R')
                {
                while(sms_in[i]!='"');
                while(sms_in[i]!='"');
                while(sms_in[i]!='"');
 
                   for(i=0;i<=12;i++)
                     {
                       mob2[i]=sms_in[i]; //mobile Number
                     }
 
                   while(sms_in[i]!=0x0D);
 
                            for(i=0;i<=80;i++)
                              {
 
                                dat[i]=sms_in[i];  //message
                                if(dat[i]==0x0D) break;
                                UART1_Write(dat[i]);
 
 
                               }
                  }
                  }
                  }
                  }
                  }

 
Last edited by a moderator:

Code:
    while(sms_in[i]!='K');
Never place a while loop with a blocking condition (e.g. waiting for another UART character) in an interrupt procedure.
 

To get receive SMS CODE to be programmed Properly, you must carefully observe the new message alert status received from GSM Modem, Show this to me, because some modems contain sms content within +CMT string. If your modem is the same, i can give you complete working code, if not, i may help you as much as possible.
 

first send AT+CMGF=1 PRESS ENTER(0DH)
THEN TYPE AT+CMGS="+9800220107" PRESS ENTER (0DH) YOU SHOULD BE GIVE + SYMBOL BEFORE 10 DIGIT MOBILE NUMBER
THEN WRITE SMS
THEN PRESS <CTRL+Z>
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…