[Moved] problem faced during interfacing gsm with 8051

Status
Not open for further replies.

ashwija

Newbie level 1
Joined
Apr 19, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
hi...,
we r facing a problem while interfacing gsm wit 8051, we r able to interface gsm with pc n 8051 wit pc , but we are not able interface microcontroller wit gsm module..plz help us
here is our code


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
#include<at89x51.h>         // include at89x51 . h
#include<stdio.h>                    // include stdio . h
#include<stdlib.h>                          // include stdlib . h
 
unsigned char Command_CMGF[]="AT+CMGF=1\r"; 
                                    // AT+CMGF for selecting Text Mode
unsigned char SUB[]="0x1A";                   
//# define C  Ctrl^Z                                               // CTRL+Z for sedning SMS after the message has been entered
unsigned char Command_CMGS[]="AT+CMGS =+919590166616\r"; 
                                   // recepient mobile number
unsigned char Command_AT[]="AT\r";
unsigned char msg02[]="Hello!";
 
 
 void delay2(){
unsigned int i;
for(i=0;i<25000;i++);
}
void initialize_serialcommunication(){
TMOD = 0x20;
SCON = 0x50;        
TH1  = 0xFD;       
TL1  = 0xFD;        
TR1  = 1; 
TI = 1;
}
 
 void initialize_GSM_modem(){
 delay2();
puts(Command_AT);
delay2();    
puts(Command_CMGF);
delay2();
puts(Command_CMGS);
delay2();
    puts(msg02);
delay2();
 
 
while(!TI);
 TI=0;
 SBUF= "^Z";    
//SBUF=0X1A;    
//SBUF=SUB;                                     
 
 
}
 
 void main ()
 {
 
 initialize_serialcommunication();
   initialize_GSM_modem();
 
while (1) {
   ; 
 }
  }

 
Last edited by a moderator:

Re: problem faced during interfacing gsm with 8051

what type of problem u r facing

- - - Updated - - -

better u can try ur code in proteus and thn u can chek in hardware
 

Re: problem faced during interfacing gsm with 8051

What part are you facing problem actually..?


This much is what I figured out:

You need to give Carriage Return and Line Feed after every UART tx, not just carriage return.

SBUF= "^Z";
The Ctrl+Z should not be a string, instead use the ASCII equivalent.
 

Re: problem faced during interfacing gsm with 8051

hai ashwija

you have to use Carriage return ASCII value 13 because of "\n"
 

Re: problem faced during interfacing gsm with 8051

check the port connections to which your gsm is interfaced.
better to verify the code using proteus.
 

Re: problem faced during interfacing gsm with 8051

try these changes.

1.msg02[]=msg02[]="Hello!\r";
2.After sending msg02 send 0x1a or equivalent decimal not a string or ^z
 

Re: problem faced during interfacing gsm with 8051

try these changes.

1.msg02[]=msg02[]="Hello!\r";
2.After sending msg02 send 0x1a or equivalent decimal not a string or ^z

what is the meaning of double declaration of msg02[] ?
 

Working mikroC PRO Code attached.


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
#include <reg51.h>         
 
unsigned char Command_AT[3] = "AT";
unsigned char Command_CMGF[16] = "AT+CMGF=1";
unsigned char Command_CMGS[16] = "AT+CMGS=";
unsigned char mobileno[16] = "+919590166616";
unsigned char SMS0[] = "Hello!"; 
 
void Delay_ms(unsigned int msec); 
void UART_Init();
void SendSMS();
void UART_Write(unsigned char uartData);
void UART_Write_Text(unsigned char *uartData);
 
void Delay_ms(unsigned int msec){
        unsigned int i;
    
        for(i = 0; i < (5 * msec); i++);        
}
 
void UART_Init(){
        P3   = 0x03;
        TMOD = 0x20;
        SCON = 0x50;        
        TH1  = 0xFD;       
        TR1  = 1; 
        EA   = 1;
      ES   = 1;
}
 
void SendSMS(){
        UART_Write_Text(Command_AT);
        UART_Write(0x0D);
        UART_Write(0x0A);
        Delay_ms(4000);    
        UART_Write_Text(Command_CMGF);
        UART_Write(0x0D);
        UART_Write(0x0A);
        Delay_ms(4000);
        UART_Write_Text(Command_CMGS);
        UART_Write(0x22);
        UART_Write_Text(mobileno);
        UART_Write(0x22);
    UART_Write(0x0D);
        UART_Write(0x0A);
        Delay_ms(8000);
    UART_Write_Text(SMS0);
    UART_Write(0x0D);
        UART_Write(0x1A);
        UART_Write(0x0D);
        Delay_ms(8000);
}
 
void UART_Write(unsigned char uartData){
        SBUF = uartData;                        
        while(TI == 0);                         
        TI = 0;                                 
}
 
void UART_Write_Text(unsigned char *uartData){
        while(*uartData)UART_Write(*uartData++);                                    
}
 
 
void main (){
 
    UART_Init();
      Delay_ms(4000);       
 
        while (1){
                    SendSMS();
        }
}

 

Attachments

  • GSM 8051.rar
    25.1 KB · Views: 37
Last edited:

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…