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.

sim900 and lpc2368 :basic program to send sms

Status
Not open for further replies.

joel george

Junior Member level 1
Junior Member level 1
Joined
Aug 11, 2014
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
114
This is more of an algo that i want to implement...i need help
1)shud i be concerned about the reply i get from the gsm modem?(like OK,ERROR...)
2)how shud i den implement it...?


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
#include <stdio.h>
 
extern unsigned char cmgf[]="AT+CMGF=1";    
 
extern unsigned char cmgs[]="AT+CMGS=\"9952082259\"";  
 
extern unsigned char msg1[]="WELCOME TO GSM\0";
 
extern unsigned char msg2[]="USER HAS CROSSED THE BOUNDARY\0";
 
extern unsigned char msg3[]="I’M IN DANGER\0";
 
extern unsigned char msg4[]="PULSE RATE HAS BEEN INCREASING DRASTICALLY\0";
 
extern unsigned char readall[]="AT+CMGR=\"REC UNREAD\"\r\n";
 
void main()
{
pinsel0 = 0x00000000;        // Enable GPIO on all pins
init_serial();
gsmperform();
 
}
 
void gsmperform()
{
while(!(sendstring("AT\r\n")));         //wait till u receive OK
delaygsm();
sendstring("AT+CNMI=2,1,0,0\r\n");//enable read new message
delaygsm();
 
 
sendstring(cmgf);
txu1(0x0d);                                     // equivalent of 
txu1(0x0a);                                     //   enter key
delaygsm();
sendstring(cmgs);
txu1(0x0d);
txu1(0x0a);  
delaygsm();
if(/* SOS key pressed*/)
{
sendstring(msg3);
txu1(0x0d);
txu1(0x0a);  
}
if(/*output of pulse generator >reference*/)
   {
sendstring(msg4);
txu1(0x0d);
txu1(0x0a);  
   }
if(/* latitude,longitude >reference)
{
sendstring(msg2);
txu1(0x0d);
txu1(0x0a);  
}
}
 
 
void init_serial (void)           /* Initialize Serial Interface       */
{                      
    PINSEL0 &= 0xFFFFFF0F; // Reset P0.2,P0.3 Pin Config
    PINSEL0 |= 0x00000010; // Select P0.2 = TxD(UART0)
    PINSEL0 |= 0x00000040; // Select P0.3 = RxD(UART0)
PINSEL1|=0x00000000;
PINSEL2|=0x00000000;
 
    U1LCR   = 0x00000083;         /* 8 bits, no Parity, 1 Stop bit     */
    U1DLL   = 0x000000C2;         /* 9600 Baud Rate @ 30MHz VPB Clock  */
    U0FDR = 0x67; // Fractional Divider
    U1LCR   = 0x00000003;        /* DLAB = 0         */
 
/* MORE HELP FRON UNCLE*/
VICIntSelect&=0xffffff7f;
    VICVectAddr2=(unsigned int)uart1_irq;
    VICIntEnable|=0x00000080;
    VICVectCntl0= 0x0000002F;/*select a priority slot 4a gvn interrupt*/
 
 
}
 
void txuart1(unsigned char data)     //Transmit a byte of data through UART1
{
       while(!(U1LSR & 0x20));         //Wait until UART1 ready to send character  
 
       U1THR = data;
delay(100); //waiting for the receiver to start working
rxuart1(); 
}
 
 
 
 
unsigned char my_arr[16];//for general purpose//
unsigned char* rxuart1()
{
       
    char* ptr = my_arr;
    while(1)
    {
        while((U1LSR&0x01)!=1);
        {
            *ptr++ = U1RBR;
        }
        if(*(--ptr) == 0x0A)
            break;
    }
    
}
 
 
 
int sendstring(unsigned char *p)//Sends a string of data through UART1
{
        while(1)
        {
           if(*p=='\0')
 break;
           txuart1(*p++);
        }
        if(my_arr==”OK”)
return 1;
return 0; 
}
 
void delaygsm()                           //delay function
{
int i,j;
for(i=0;i<60000;i++)
for(j=0;j<51;j++);
}

 
Last edited by a moderator:

I am not sure I understand your question.

You can streamline your code if your strings have cr/lf escape sequences i.e.

extern unsigned char cmgs[]="AT+CMGS=\"9952082259\"\r\n"; etc etc

You can then remove txu1(0x0d); txu1(0x0a);

You can also send string literals i.e. sendstring("AT+CMGS=\"9952082259\"\r\n");

Cheers
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top