Microcontroller › 8051 › Interfacing of GSM SIM908 and 89v51rd2
- This topic has 2 replies, 2 voices, and was last updated 10 years, 10 months ago by Amit Raijade.
-
AuthorPosts
-
January 20, 2014 at 9:27 am #2818Amit RaijadeParticipant
Hello frnds..
I m doing a small project on sending SMS through above mentioned modules
I m using 8051 development board made by nskelectronics.
My hardware connections:-
RX of 908 to TX of Controller. and vice versa.
My Queries:-
1> Is there more connection to do?
2> Should i bypass max232 IC from board?
3> How to check OK response after every AT command?
My code:-
#include <reg51.h>#include <stdio.h>sbit BIT1 = P0^0;sbit BIT2 = P0^1;char phone_number1[13]= “+9197xxxxxxxx”;char phone_number2[13]= “+9197xxxxxxxx”;char msg1[10] = “HELLO”char msg2[10] = “SYSTEM”;char aux_string[20];void delay_ms(unsigned int);void send_sms(char[],char[]);void serial_init() {SCON=0x50; //setup for 8-bit dataTMOD=0x20; //setup timer 1 for auto-reloadTH1=0xfd; //Baud Rate 9600TR1=1; //turn on timer 1//TI=1; //indicate ready to transmit}void send_serial(unsigned char *s){while (*s != 0x0){SBUF = *s;while (!TI){}TI = 0;s++;}}void main(){BIT1 = 1;BIT2 = 1;delay_ms(800);serial_init(); //Initialize Serial port.if(BIT1 == 1){send_sms(phone_number1,msg1);}else if(BIT2 == 1){send_sms(phone_number2, msg2);}else{send_serial(“check pin statusn”);}}void delay_ms(unsigned int iTime){unsigned int i,j;for(i = 0 ; i < iTime ; i++)for(j = 0 ; j < 1275 ; j++);}void send_sms(char phone_number[],char msg[]){send_serial(“ATr”);delay_ms(2000);send_serial(“AT+CREG=1r”);delay_ms(2000);send_serial(“AT+CMGF=1r”);delay_ms(2000);sprintf(aux_string,”AT+CMGS=”%s””, phone_number);send_serial(aux_string);send_serial(“r”);delay_ms(2000);send_serial(msg);send_serial(“r”);delay_ms(2000);send_serial(“0x1Ar”);delay_ms(3000);}January 21, 2014 at 7:16 am #10872AJISH ALFREDParticipantHi Amit,
1> Is there more connection to do?
Connect the ground lines together.
2> Should i bypass max232 IC from board?
If you are connecting the gsm module through db9 connector then you must use max232 at the microcontroller end.
3> How to check OK response after every AT command?
Take this piece of code,
send_serial(“ATr”);delay_ms(2000);Instead of using a delay, try something like this;while ( strcmp( “OK” == receive_serial_string () ) );where, “receive_serial_string ()” is a function which you have to write, that can read a string from the serial port. The statement will loop there itself until the received string matches with the required sting “OK”January 21, 2014 at 10:07 am #10874Amit RaijadeParticipantthank you Ajish..
-
AuthorPosts
- You must be logged in to reply to this topic.