Need help in GSM Coding (Assembly Language)
Discussion in "8051 Discussion Forum" started by Malik_Umair May 24, 2013.
Fri May 24 2013, 08:23 am
Hello All Experts,
I have written the following assembly language code for the GSM interfacing with 89c51, I want to get SMS on my mobile when 89c51 get input. But I am unable to get any message on my cell phone. Please help me in this regard.
Program:
I have written the following assembly language code for the GSM interfacing with 89c51, I want to get SMS on my mobile when 89c51 get input. But I am unable to get any message on my cell phone. Please help me in this regard.
Program:
ORG 0000H MOV P1, #00H ; GSM COMMUNICATION SOFTWARE SIMULTION MOV TMOD,#20H MOV TH1,#0FDH MOV SCON,#50H SETB TR1 ;MOV P1, #0FH MOV P2, #00H START: MOV A, #01H CJNE A, #00000001B, NEXT SJMP ONE NEXT: CJNE A, #00000010B, NEXT_2 LJMP TWO NEXT_2: CJNE A, #00000100B, START LJMP THREE ONE: CLR P2.1 LCALL DELAY LCALL DELAY LCALL DELAY SETB P2.1 MOV DPTR,#MSG1 ACALL H1 CLR P2.1 LCALL DELAY LCALL DELAY LCALL DELAY SETB P2.1 ACALL DELAY MOV DPTR,#MSG2 ACALL H1 CLR P2.1 LCALL DELAY LCALL DELAY LCALL DELAY SETB P2.1 ACALL DELAY ;MOV DPTR,#MSG3 ;ACALL H1 ;CLR P2.1 ;LCALL DELAY ;LCALL DELAY ;LCALL DELAY ;SETB P2.1 ;ACALL DELAY MOV DPTR,#MSG4 ACALL H1 CLR P2.1 LCALL DELAY LCALL DELAY LCALL DELAY SETB P2.1 ACALL DELAY MOV DPTR,#MSG5 ACALL H1 CLR P2.1 LCALL DELAY LCALL DELAY LCALL DELAY SETB P2.1 ACALL DELAY LJMP START TWO: MOV DPTR,#MSG1 ACALL H1 ACALL DELAY MOV DPTR,#MSG2 ACALL H1 ACALL DELAY ;MOV DPTR,#MSG3 ;ACALL H1 ;ACALL DELAY MOV DPTR,#MSG4 ACALL H1 ACALL DELAY MOV DPTR,#MSG6 ACALL H1 ACALL DELAY LJMP START THREE: MOV DPTR,#MSG1 ACALL H1 ACALL DELAY MOV DPTR,#MSG2 ACALL H1 ACALL DELAY ;MOV DPTR,#MSG3 ;ACALL H1 ;ACALL DELAY MOV DPTR,#MSG4 ACALL H1 ACALL DELAY MOV DPTR,#MSG7 ACALL H1 ACALL DELAY LJMP START H1: CLR A MOVC A,@A+DPTR JZ B1 ACALL SEND INC DPTR SJMP H1 B1: RET SEND: MOV SBUF,A H2: JNB TI,H2 CLR TI RET DELAY: MOV R3,#50H HERE2: MOV R4,#50H HERE: DJNZ R4,HERE DJNZ R3,HERE2 RET ORG 300H MSG1: DB "AT",0DH,0AH DB 0H MSG2: DB "AT+CMGF=1",0DH,0AH DB 0H ;MSG3: DB "ATE=0",0DH,0AH ; DB 0H MSG4: DB "AT+CMGS=",'"+92334xxxxxxx"',0DH,0AH DB 0H MSG5: DB "INPUT 1 ACTIVATED",01AH DB 0H MSG6: DB "INPUT 2 ACTIVATED",01AH DB 0H MSG7: DB "INPUT 3 ACTIVATED",01AH DB 0H END
[ Edited Fri May 24 2013, 11:10 am ]
Fri May 24 2013, 11:16 am
I do not see any issue in your code. Few changes I would suggest:
1. remove 0A from all commands as when we press enter from hyperterminal PC only transmit 0D
2. change ATE=0 to ATE0
3. I do not know how much delay your routine generates, But make sure there is approx 1sec delay between each command.
1. remove 0A from all commands as when we press enter from hyperterminal PC only transmit 0D
2. change ATE=0 to ATE0
3. I do not know how much delay your routine generates, But make sure there is approx 1sec delay between each command.
Fri May 24 2013, 11:55 am
Hello Ajay,
1) I am not going interface it with PC hyper terminal, rather I am directly interfacing my SIM900 GSM module to 89c51. So for this I have added 0AH.
2) I did not understand about the ATE0? Will you please explain me?
3) 20ms delay I am generating.
1) I am not going interface it with PC hyper terminal, rather I am directly interfacing my SIM900 GSM module to 89c51. So for this I have added 0AH.
2) I did not understand about the ATE0? Will you please explain me?
3) 20ms delay I am generating.
Fri May 24 2013, 12:07 pm
I have one another doubt. My GSM modem operates on maximum +4.3v and 89c51 operates on +5v. Is their any logic level problem that the GSM module is not recognizing 9600bps data on +5v level? Should I use in between MAX232 and provide +4.3v to MAX232? Please help me to get out of it successfully.
Sun May 26 2013, 12:18 am
I believe that you should look into the datasheet of your GSM modem once again and see if the pins of modem are 5V tolerant or not.
If yes then there is no requirement for max232 because 8051 works in TTL level and your GSM modem can well understand the incoming data from the MCU. Max232 converts rs232 to TTL level and vice versa.
If no then use a resistor network on each pin of GSM to lower down the 5V from 8051 to required level (eg 3V).
If yes then there is no requirement for max232 because 8051 works in TTL level and your GSM modem can well understand the incoming data from the MCU. Max232 converts rs232 to TTL level and vice versa.
If no then use a resistor network on each pin of GSM to lower down the 5V from 8051 to required level (eg 3V).
Sun May 26 2013, 09:48 am
Yup, pins connections were bad. Now I am receiving SMS on my mobile. But at the same time I want to receive sms to micro-controller and do some controlled jobs through MCU. Can anybody help me how to do this? Any code? or a guide line?
Mon May 27 2013, 10:05 am
I recently posted a project on this:
http://www.8051projects.net/download-d248-gsm-notice-board.html
you can see how sms receive is working in this project.
http://www.8051projects.net/download-d248-gsm-notice-board.html
you can see how sms receive is working in this project.
Tue May 28 2013, 03:06 pm
Hi Ajay,
The code is in C language and I hardly understand only few basic commands of C. I am good in Assembly. Will you please translate that code in Assembly so that I can also understand and extract my concerned commands and their syntax?
The code is in C language and I hardly understand only few basic commands of C. I am good in Assembly. Will you please translate that code in Assembly so that I can also understand and extract my concerned commands and their syntax?
Wed May 29 2013, 09:51 am
it will be a complex to transfer that logic to ASM. I would suggest you do an alternative approach. Fix a location for reading sms, e.g. you read only location #1 for reading sms. To read SMS you will send AT+CMGR=1
if there is no new sms on that location you will get only "OK" from modem, but If there is a new sms you will get response starting with "+CMGR:" and after reading SMS delete that SMS using AT+CMGD=1 so that new sms comes in same location. that's a simplest way of reading SMS and is fairly simple to implement it in assembly.
if there is no new sms on that location you will get only "OK" from modem, but If there is a new sms you will get response starting with "+CMGR:" and after reading SMS delete that SMS using AT+CMGD=1 so that new sms comes in same location. that's a simplest way of reading SMS and is fairly simple to implement it in assembly.
Tue Jun 04 2013, 02:23 pm
Hi Ajay,
I am really thankful to you regarding helping me in GSM code. The sending porting is working (if put alone). I have written the following code for sending and receiving the SMS through GSM module. But I am having problem in the interrupt routine (I think). My aim is that in normal mode the GSM and micro-controller will remain in receiving mode means it receive SMS and act upon accordingly but when the external interrupt INT0 comes it goes to sending mode and sends the SMS to pre-defined number. I have written the code but it is not working. Please guide me in this program.
I am really thankful to you regarding helping me in GSM code. The sending porting is working (if put alone). I have written the following code for sending and receiving the SMS through GSM module. But I am having problem in the interrupt routine (I think). My aim is that in normal mode the GSM and micro-controller will remain in receiving mode means it receive SMS and act upon accordingly but when the external interrupt INT0 comes it goes to sending mode and sends the SMS to pre-defined number. I have written the code but it is not working. Please guide me in this program.
CODE: ;*********************************************************************************************** ; Program for Sending SMS through GSM network using ; SIM900D and AT89C51 ;*********************************************************************************************** ; Upon wake-up goto MAIN, avoid using memory space, allocated ; to interrupt vector table ;*********************************************************************************************** ORG 0000H LJMP MAIN ;********************************************************************************************** ; ISR for External Interrupt 0 to send Message for ; particular activated input ;********************************************************************************************** ORG 0003H CHECK: JNB P1.0, CHECK ACALL SERIAL ACALL DELAY1 ACALL DELAY1 ACALL DELAY1 ACALL DELAY1 ACALL CMGF ACALL DELAY1 ACALL DELAY1 ACALL DELAY1 ACALL DELAY1 ACALL CNMI ACALL DELAY1 ACALL DELAY1 ACALL DELAY1 ACALL DELAY1 ACALL CMGS ACALL DELAY1 ACALL DELAY1 ACALL DELAY1 ACALL DELAY1 ACALL SALAM ACALL THIEF ACALL DELAY1 ACALL DELAY1 ACALL DELAY1 ACALL DELAY1 RETI ;*********************************************************************************************** ; The MAIN program for initilization ;*********************************************************************************************** MAIN: ORG 0030H MOV P1,#00H MOV P2,#00H ACALL DELAY1 ACALL DELAY1 ACALL DELAY1 ACALL DELAY1 SETB P1.0 START: MOV IE, #00000100B ACALL SERIAL ACALL DELAY1 ACALL DELAY1 ACALL DELAY1 ACALL DELAY1 LCALL CMGF LCALL DELAY1 LCALL DELAY1 LCALL DELAY1 LCALL DELAY1 LCALL CSMS ; SET TO PHASE 1 LCALL DELAY1 LCALL DELAY1 LCALL DELAY1 LCALL DELAY1 LCALL CNMI_READ ; SET TO DISPLAY +CMTI INDICATION WHEN SMS IS RECEIVED LCALL DELAY1 LCALL DELAY1 LCALL DELAY1 LCALL DELAY1 LCALL CPMS ; SET THE READ & WRITE STORAGE TO SIM LCALL DELAY1 LCALL DELAY1 LCALL DELAY1 LCALL DELAY1 LCALL CMGR ; READ THE STORED MESSAGE LCALL DELAY1 LCALL DELAY1 LCALL DELAY1 LCALL DELAY1 ;********************************************************************************************** RECV: JNB RI, RECV MOV A,SBUF CLR RI CJNE A,'1',ERROR SETB P2.1 CLR A ;*********************************************************************************************** LCALL CMGD ; DELETE THE SMS STORED IN SIM LCALL DELAY1 LCALL DELAY1 LCALL DELAY1 LCALL DELAY1 LJMP START ;********************************************************************************************** ERROR: SETB P2.2 LCALL DELAY1 LCALL DELAY1 LCALL DELAY1 LCALL DELAY1 CLR P2.2 LJMP START ;*********************************************************************************************** ; Subroutine for Sending one byte out of serial port ;*********************************************************************************************** TRAIN: MOV SBUF,A HERE: JNB TI,HERE CLR TI RET ;*********************************************************************************************** ; Subroutine for initializing the serial port with 9600BPS ;*********************************************************************************************** SERIAL: MOV TMOD,#20H MOV TH1,#0FDH MOV SCON,#50H SETB TR1 RET ;*********************************************************************************************** ; Subroutine for CSMS ;*********************************************************************************************** CSMS: MOV DPTR,#TABLE6 MOV R7,#10 LOOOP: MOV A,#0 MOVC A,@A+DPTR INC DPTR LCALL TRAIN DJNZ R7,LOOOP RET ;*********************************************************************************************** ; Subroutine for CNMI_READ ;*********************************************************************************************** CNMI_READ: MOV DPTR,#TABLE7 MOV R7,#18 LOP: MOV A,#0 MOVC A,@A+DPTR INC DPTR ACALL TRAIN DJNZ R7,LOP RET ;********************************************************************************************** ; Subroutine for CPMS ;********************************************************************************************** CPMS: MOV DPTR,#TABLE8 MOV R7,#18 LOOOOP: MOV A,#0 MOVC A,@A+DPTR INC DPTR LCALL TRAIN DJNZ R7,LOOOOP RET ;*********************************************************************************************** ; Subroutine for CMGR ;*********************************************************************************************** CMGR: MOV DPTR,#TABLE9 MOV R7,#10 BACK: MOV A,#0 MOVC A,@A+DPTR INC DPTR ACALL TRAIN DJNZ R7,BACK RET ;*********************************************************************************************** ; Subroutine for CMGD ;*********************************************************************************************** CMGD: MOV DPTR,#TABLE10 MOV R7,#10 BACK1: MOV A,#0 MOVC A,@A+DPTR INC DPTR ACALL TRAIN DJNZ R7,BACK1 RET ;*********************************************************************************************** ; Subroutine for CMGF ;*********************************************************************************************** CMGF: MOV DPTR,#TABLE1 MOV R7,#10 LOOP1: MOV A,#0 MOVC A,@A+DPTR INC DPTR ACALL TRAIN ; ACALL DELAY DJNZ R7,LOOP1 RET ;*********************************************************************************************** ; Subroutine for CNMI ;*********************************************************************************************** CNMI: MOV DPTR,#TABLE2 MOV R7,#18 LOOP2: MOV A,#0 MOVC A,@A+DPTR INC DPTR ACALL TRAIN ; ACALL DELAY DJNZ R7,LOOP2 RET ;*********************************************************************************************** ; Subroutine for CMGS ;*********************************************************************************************** CMGS: MOV DPTR,#TABLE3 MOV R7,#22 LOOP3: MOV A,#0 MOVC A,@A+DPTR INC DPTR ACALL TRAIN ; ACALL DELAY DJNZ R7,LOOP3 RET ;*********************************************************************************************** ; Subroutine for SALAM ;*********************************************************************************************** SALAM: MOV DPTR,#TABLE4 MOV R7,#18 LOOP4: MOV A,#0 MOVC A,@A+DPTR INC DPTR ACALL TRAIN ; ACALL DELAY DJNZ R7,LOOP4 RET ;*********************************************************************************************** ; Subroutine for THIEF ;*********************************************************************************************** THIEF: MOV DPTR,#TABLE5 MOV R7,#31 LOOP5: MOV A,#0 MOVC A,@A+DPTR INC DPTR ACALL TRAIN ; ACALL DELAY DJNZ R7,LOOP5 RET ;*********************************************************************************************** ; Subroutine for delay ;*********************************************************************************************** DELAY: MOV R0,#50 RELOAD: MOV R1,#50 WAIT: DJNZ R1,WAIT DJNZ R0,RELOAD RET ;*********************************************************************************************** ; Subroutine for LARGE delay ;*********************************************************************************************** DELAY1: MOV R0,#255 RELOAD1: MOV R1,#255 WAIT1: DJNZ R1,WAIT1 DJNZ R0,RELOAD1 RET ;*********************************************************************************************** ; Lookup Tables ;*********************************************************************************************** TABLE1: DB "AT+CMGF=1",0Dh TABLE2: DB "AT+CNMI=2,2,0,0,0",0Dh TABLE3: DB 'AT+CMGS="0331xxxxxx"',0Dh TABLE4: DB "ASSALAM-O-ALAIKUM",0Dh TABLE5: DB "GSM is working",1Ah TABLE6: DB "AT+CSMS=0",0Dh TABLE7: DB "AT+CNMI=2,1,0,0,0",0Dh TABLE8: DB "AT+CPMS=","SM","SM",0Dh TABLE9: DB "AT+CMGR=1",0Dh TABLE10: DB "AT+CMGD=1",0Dh END
[ Edited Tue Jun 04 2013, 11:34 pm ]
Powered by e107 Forum System