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.

GSM interface with microcontroller (code)

Status
Not open for further replies.

Vanessa Love Strawberriie

Newbie level 3
Joined
May 27, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
48
Hi, is there anybody who is able to write a keil c programming for my gsm to receive the message from what the user send to the gsm? i am using the #include<DS89C4xx.H> header and xdata.
 

Vanessa Love Strawberriie

Newbie level 3
Joined
May 27, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
48
Hi sorry i was not able to open up the code and i kind of think that this isn't what i am looking for. thanks though:)
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
You need winrar to extract the file. It is a CodeVisionAVR Project. So, just open the .c file in notepad and copy it and paste it to keil. Remove the code related to AVR and use it for your 8051.
 

Vanessa Love Strawberriie

Newbie level 3
Joined
May 27, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
48
this is my programme code. i want to detect +CMGR and extract out the phone number and messgae. please help


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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include<DS89C4xx.H>  //microcontroller specific library (DS89C450)
#include<absacc.h>    //XBYTE[]
#include<string.h>
#define uchar unsigned char;
 
/*Global Variables*/
 
uchar start_header='+',end_header=':';      //gsm command header 
uchar xdata GSMrd[80];
uchar xdata raw_data[80];
uchar xdata infor[4];
enum sector_state {Idle,Extract} state;
uchar read_count,raw_data_count,infor_count,infor_count1, get_infor,infor_start,infor_start1;
uchar xdata extract;
 
void initializtion (void)
{
    SCON1 = 0x52;             //set serial port 1, 8-bit UART, TI Enable
    SCON0 = 0x52;
    TMOD = 0x21;              //set Timer 1 to 16-bit timer/counter
    //WDCON = 0x80;
    TH1 = 0xFD;               //set Baud Rate=9600
    //PCON=0x80;                //set SCON=1 for baud rate = 19200
    TR1=1;                    //Run Timer 1
    EA=1;
    ES0=1;
}
 
void tx(unsigned char x)
{
while (TI_1==0);
TI_1 = 0;
SBUF1 = x;
}
 
void tx0(unsigned char x)
{
  while (TI_0==0);
  TI_0 = 0;
  SBUF0 = x;
}
 
void SMSstring(unsigned char *msg)        //send string GSM to hyper terminal
{
  int count=0;
  while(msg[count])
  {
    tx(msg[count++]);
  }
//  tx(0x0D); //CR carriage return
//  tx(0x0A); //next line
}
 
void SMSstring0(unsigned char *msg)
{
 
  int count=0;
  
ES0=0;
  while(msg[count])
  {
    tx0(msg[count++]);
  }
ES0=1;
//  tx(0x0D); //CR carriage return
//  tx(0x0A); //next line
}
 
void serial_int(void) interrupt 4   //serial port 0
{
    ES0=0;          //disable interrupt
 
    if(RI_0==1)
    {
        if(read_count==80)          //Check is array full
        read_count=0;               //Restart from position 0
        GSMrd[read_count]=SBUF0;    //Storing the data from serial buffer into array
    
        read_count++;               //increase the count
        //indicator=1;
        RI_0=0;                     //reset RI flag
    }
    ES0=1;
}
 
void delay(int num)
{
  int i,j;
  for(i=0;i<num;i++)            //number of loop according with the given num
  for(j=0;j<1200;j++);         //num * 1200 times of looping
}
 
void read_message (void)
{   
    if(raw_data_count != read_count)         //checking is there any unread data?
    {
        if(raw_data_count==80) //go back to start position of array
        raw_data_count=0;
 
        raw_data[raw_data_count]=GSMrd[raw_data_count];//read the data  
//======================= CHECK FOR "CMTI"================================
        if(raw_data[raw_data_count]==start_header)    //check for + sign
        {
            SMSstring0("Detected + Sign");                           //prove that is detected
            infor_start=1;                                           //increment to 1 if start header is true
            raw_data[raw_data_count]=GSMrd[raw_data_count]='0';     //reset the string array of raw_data and GSmrd
            tx0(0x0D); //CR carriage return
            tx0(0x0A); //next line
 
        }
        else if(infor_start==1)                    // if information (CMTI) is true
        {
            if(raw_data[raw_data_count]==end_header)     //check for : sign
            {
                SMSstring0("Detected : Sign");
                raw_data[raw_data_count]=GSMrd[raw_data_count]='0';     //reset the string array of raw_data and GSmrd
                infor_start=0;                                         //reset infor_start back to zero
                infor_count=0;                                         //reset infor_count back to zero
                tx0(0x0D); //CR carriage return
                tx0(0x0A); //next line
 
                if((infor[0]=='C') && (infor[1]=='M') && (infor[2]=='T') && (infor[3]=='I'))
                {
                    delay(100);
                    SMSstring0("AT+CMGR=1");        //Read SMS message in SIM location 1
                    tx0(0x0D); //CR carriage return
                    tx0(0x0A); //next line
                    extract=1;  //when message is true it will extract out the data
 
                    switch(raw_data[raw_data_count])
                    {
                     case: '+':
                     state=extract;
                     break;
 
                     default:
                     break;
                    }
                }     
                infor[0]=infor[1]=infor[2]=infor[3]='0';     //reset the CMTI information
                    
            
            }
            else if(infor_count<4)   //counter to detect CMTI
            {
                infor[infor_count]= raw_data[raw_data_count];    //store the raw data into infor as a string
                infor_count++;                                  //every character receieve will incraese the count 
            }
    
    
    }   
         raw_data_count++;
    }   
}
  
 
void main(void)
{
    delay(200);                  //call delay   
    PMR=PMR|0X81;               //power management modules for external memory
    initializtion();            //initialization                                                                                                                                                                                                                                                                                                                                                                                                                                                   );
    SMSstring("GSM Testing ");   //to indicate system is ready for testing
 
    while(1)
    {
        read_message();
    }
 
}

 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top