Discussion in "8051 Discussion Forum" started by    Malik_Umair    May 24, 2013.
Mon Jun 24 2013, 04:37 AM
#21
I appreciate your thinking and I will look forward for your contribution. Post your current code so I can help you solve issues. and also share SMS format you're sending.
Sat Jun 29 2013, 10:30 AM
#22
Hello Ajay,
I am seriously fed up of this task. I have tried my best but unable to receive any SMS. I am sharing the whole code with you, please arrange it for me. Its been a month and a half that I am working on it. The interrupt routine for sending sms is working fine.
;***********************************************************************************************
;       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 0H
            LJMP MAIN

 ;**********************************************************************************************
 ;       ISR for External Interrupt 0 to send Message for
 ;       particular activated input
 ;**********************************************************************************************
            ORG 03H
            LJMP CHECK
;***********************************************************************************************
;         ISR FOR TIMER 0 INTERRUPT
;***********************************************************************************************
           ORG 000BH  ; TIMER 0 INTERRUPT

                                                        ;This is your ISR where you will count
                                                       ;60 interrupts and set timer flag
        INC R6 ;increment counter
        CJNE R6, #60,OUT
        CALL TIMEDOUT
OUT:
        MOV TL0,#0CDH
        MOV TH0,#0FFH ;Reload timer again for 50ms
        RETI
TIMEDOUT:
        ; Timeout occured
        CLR TR0 ;stop timer now
        SETB TIMEOUT_FLAG
        RETI
;***********************************************************************************************
;         The MAIN program for initilization
;***********************************************************************************************
            ORG 30H
     ; to define TIMEOUT_FLAG you can use
        ; bit addressable area
        TIMEOUT_FLAG equ 0H ;0H means Address:20H[bit0]
MAIN:       MOV P1,#00H
            MOV P2,#00H
            ACALL DELAY1
            ACALL DELAY1
            ACALL DELAY1
            ACALL DELAY1
            SETB P1.0
 START:     MOV IE, #83H
            ACALL SERIAL
            ACALL DELAY1
            ACALL DELAY1
            ACALL DELAY1
            ACALL DELAY1
            LCALL CMGF
            LCALL DELAY1
            LCALL DELAY1
            LCALL DELAY1
            LCALL DELAY1
            LCALL CSMS   ; SET t PHASE 1
            LCALL DELAY1
            LCALL DELAY1
            LCALL DELAY1
            LCALL DELAY1
            LCALL CNMI_READ
            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 CMGL   ; LIST SMS FROM LOCATION (CURRENTLY SET TO "ALL")
            LCALL DELAY1
            LCALL DELAY1
            LCALL DELAY1
            LCALL DELAY1

READ_AGAIN: LCALL INIT_TIMEOUT
            LCALL CMGR   ; READ THE STORED MESSAGE
            ;LCALL DELAY1
            ;LCALL DELAY1
            ;LCALL DELAY1
            ;LCALL DELAY1
;**********************************************************************************************
WaitForStar:
        JB RI, CHECK_BYTE
        JB TIMEOUT_FLAG, READ_AGAIN ;TIMEOUT_FLAG is a bit variable that is set
                                    ; In ISR of timer that your initialized earlier
        SJMP WaitForStar            ;if no timeout is not received
                                    ;go back and check data received
CHECK_BYTE:
        MOV A, SBUF
        CLR RI
        CJNE A, '*', WaitForStar

WaitForCode:                           ;the next char is a command
           JNB RI,WaitForCode
            MOV A,SBUF
            CLR RI
            CJNE A,'1', ERROR    ; If TRUE then make P2.1 HIGH
            SETB P2.1
            Sjmp CommonExit

ERROR:
             SETB P2.2          ; If FALSE then make P2.2 HIGH

           

CommonExit:

            LCALL DELAY1
            LCALL DELAY1
            LCALL DELAY1
            LCALL DELAY1

             CLR P2.1
             CLR P2.2
             CLR A

             LCALL CMGD    ; DELETE THE SMS STORED IN SIM
             LCALL DELAY1
             LCALL DELAY1
             LCALL DELAY1
             LCALL DELAY1
             LJMP START

;***********************************************************************************************
  ;DELETE:   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
;***********************************************************************************************
;   Sending ISR
;***********************************************************************************************
            ORG 200H
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
;***********************************************************************************************
;   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
   LOOP6:  MOV A,#0
           MOVC A,@A+DPTR
           INC DPTR
           LCALL TRAIN
           DJNZ R7,LOOP6
           RET
 ;**********************************************************************************************
 ;  Subroutine for CPMS
 ;**********************************************************************************************
   CPMS:   MOV DPTR,#TABLE8
           MOV R7,#13
   LOOOOP: MOV A,#0
           MOVC A,@A+DPTR
           INC DPTR
           LCALL TRAIN
           DJNZ R7,LOOOOP
           RET
 ;**********************************************************************************************
 ;  Subroutine for CMGL
 ;**********************************************************************************************
   CMGL:   MOV DPTR,#TABLE7
           MOV R7,#14
   LOOP7: MOV A,#0
           MOVC A,@A+DPTR
           INC DPTR
           LCALL TRAIN
           DJNZ R7,LOOP7
           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 CNMI_READ
;***********************************************************************************************
 CNMI_READ: MOV DPTR,#TABLE11
            MOV R7,#18
    BACK2:  MOV A,#0
            MOVC A,@A+DPTR
            INC DPTR
            ACALL TRAIN
            DJNZ R7,BACK2
            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
;***********************************************************************************************
;   Subroutine for INIT_TIMEOUT
;***********************************************************************************************
INIT_TIMEOUT:
        CLR TR0 ;make sure timer is stopped
        CLR TIMEOUT_FLAG
        MOV R6, #0 ;assuming r6 is used for counting interrupts
        ;INIT timer for 50ms approx. time period

        MOV TMOD,#00000001B  ; TIMER 0, MODE 1
        MOV TL0,#0CDH
        MOV TH0,#0FFH
        SETB TR0 ;start timer
        RET
;***********************************************************************************************
;   Lookup Tables
;***********************************************************************************************
  ORG 400H
  TABLE1:   DB "AT+CMGF=1",0Dh
  TABLE2:   DB "AT+CNMI=2,2,0,0,0",0Dh
  TABLE3:   DB 'AT+CMGS="03319018928"',0Dh
  TABLE4:   DB "ASSALAM-O-ALAIKUM",0Dh
  TABLE5:   DB "GSM is working",1Ah
  TABLE6:   DB "AT+CSMS=0",0Dh
  TABLE7:   DB 'AT+CMGL="ALL"',0Dh
  TABLE8:   DB 'AT+CPMS="SM"',0Dh
  TABLE9:   DB "AT+CMGR=1",0Dh
  TABLE10:  DB "AT+CMGD=1",0Dh
  TABLE11:   DB "AT+CNMI=2,2,0,0,0",0Dh

            END


[ Edited Sat Jun 29 2013, 10:31 AM ]
Sat Jun 29 2013, 09:28 PM
#23
My earlier tips were lost in the server hack.

This works on Proteus.
Your main error was in setting TMOD in "INIT_TIMEOUT"
Good luck

Attachment
 Malik_Umair like this.
Sun Jun 30 2013, 07:49 AM
#24
Yeah I was also finding our previous few posts. So you have initialized timer 0 and 1 in same instruction in "INIT_TIMEOUT", But I have also initialized the timer in serial communication "ACALL SERIAL". So I want to as will these two separate initialization will not effect the execution? Also please I didn't understand the TMOD 21H. Please esplain it. Have you tested this code? Is this working fine? Because I am totally failed in it
Mon Jul 01 2013, 06:11 AM
#25
I do not see any issues in the program that ExperimenterUK shared.

TMOD=21H will not effect anything, as for serial you initialized Timer 1 in mode2 which means TMOD = 0x20
and when you are initializing timer0 for timer we are using mode1 so TMOD should only set timer1 mode bits and should not effect any other bit in that register, so TMOD = 0x21 timer1 mode bits remain same/unmodified. SERIAL subroutine should only be called once in your program, please remove SERIAL call from ISR.

You need to debug your program as follows:
1. Connect your board to PC or somehow tap your controller's TX pin to see if your controller is sending commands properly or not.
2. You must see AT+CMGR=1 continuously after every 3 seconds

What is the format of SMS you are using? It must start from '*'

PS: Electronics project needs lot of patience.
 Malik_Umair like this.
Mon Jul 01 2013, 05:30 PM
#26
Thank you to Dear Ajay and ExperimenterUK to help me, I have little modified the ExperimenterUK program because it was giving interrupt and subroutine error but now it is working fine I am receiving SMS perfectly. But I have noticed that when I send message from microcontroller and I feed the number like "03319018928" the message is send correctly but when I feed the number like "+923319018928" I am unable to send message (or message is not sending from the microcontroller). Please help me in this regard.

Also I want to get help in that how can I update the sending number through sending SMS to microcontroller. For-example like currently I have programmed the micro-controller that it will send messages to a number, i-e, 03319018928 and I have burned this program into microcontroller and the system is in function now. Now I want to change the number to which microcontroller send the number, so in order to switch off the system and re-program the microcontroller how can I update the new number by sending message to the system when it is operational?
Mon Jul 01 2013, 07:09 PM
#27
Glad to hear it is working at last.


when I feed the number like "+923319018928" I am unable to send message (or message is not sending from the microcontroller). Please help me in this regard.

Malik_Umair


Easy, don't send numbers like "+923319018928"

Seriously, why are you adding "+92 to the number ?
What does your phone manual say about the numbers you can use ?



Now I want to change the number to which microcontroller send the number, so in order to switch off the system and re-program the microcontroller how can I update the new number by sending message to the system when it is operational?

Malik_Umair


This will be complicated.
Could you store several alternative numbers and change which one used via SMS ?
that would be much easier.



[ Edited Mon Jul 01 2013, 07:10 PM ]
Tue Jul 02 2013, 06:50 PM
#28
try to avoid using ORG multiple time in your program. just keep on writing your assembler automatically assign space to code one after the other. anyways.. I think experimenterUK's suggestion is good do not add prefix... But i think problem is the way you have written the code. You might be chaning number but you forgot to change number of characters:
    CMGS:   MOV DPTR,#TABLE3
            MOV R7,#22 ; if you change size of TABLE3 then change value 22 here accordingly


best way is to end strings with 0H or null I will give example later.

Now regarding saving number.. you can define a memory area to store number and simply copy received sms over there.. and use that memory area as your mobile number. Its bit difficult try if you can. In your code if you receive sms starting from * then next byte contains your command if command is a number like 1, 2 etc then process them as you are doing already if your sms has + character then it means new number to set e.g. *+01234567890# read till # and move to memory and use it.
 Malik_Umair like this.

Get Social

Information

Powered by e107 Forum System

Conversation

Thu Nov 21 2019, 12:30 PM
raj2555
how to interface 8051 microcontroller with NRF24L01+ module
ExperimenterUK
Sat Oct 12 2019, 10:23 PM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 10:18 AM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 07:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 08:48 PM
Caryn Kover
Thank you for your time,
ExperimenterUK
Mon Aug 05 2019, 07:09 PM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 04:33 PM
Ismail balghmi
Hello. Please I won't download
ExperimenterUK
Wed Jul 24 2019, 12:47 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 06:13 PM
BUSTER123
hello! newbie here. i am kind of a guy who hates using ready - made existing libraries, so this helped a lot as i was trying to control and write to a character lcd display. however, i can't figure out how to set the cursor position. for example, i want to set it to the 5th column in the first row, so position 5. so according to the table, i am sending 10000101 on the 8 data lines of the lcd (register select pulled low). the cursor does not move there however. and i cant move the cursor left or right too. is it something wrong that i am doing? thank you.
ExperimenterUK
Thu Jul 11 2019, 07:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html

Downloads

Comments

nabiha_anaya
Sun Dec 08 2019, 09:16 AM
ananyagupta
Tue Dec 03 2019, 07:53 AM
wells
Mon Nov 25 2019, 08:25 PM
auwal
Tue Nov 19 2019, 03:13 PM
ANKITPATEL
Mon Nov 18 2019, 11:00 AM
Casmir
Wed Nov 13 2019, 06:25 AM
DeepakBGattani
Mon Nov 11 2019, 01:31 PM
Jeanbusatta
Sun Nov 10 2019, 04:42 AM

Online

Guests: 62, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38108
Newest member: nabiha_anaya
Forum Activity
ilylily07 Avatar
Posted By ilylily07
Sun Dec 08 2019, 01:24 PM
Hi .im humbly ask for your advice as i wrongly pur...
nabiha_anaya Avatar
Posted By nabiha_anaya
Sun Dec 08 2019, 09:19 AM
My teacher assign me a project on "voice control h...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Nov 29 2019, 04:24 AM
" Is it possible to interface a fingerprint scanne...
ilylily07 Avatar
Posted By ilylily07
Thu Nov 28 2019, 03:50 PM
You will not find any code for an 8051 as no one w...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 26 2019, 05:44 PM
You will not find any code for an 8051 as no one w...
ilylily07 Avatar
Posted By ilylily07
Tue Nov 26 2019, 04:13 AM
I tracked down a OV7670 data sheet.The OV7670 puts...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 26 2019, 12:08 AM
I tracked down a OV7670 data sheet.The OV7670 puts...
ilylily07 Avatar
Posted By ilylily07
Mon Nov 25 2019, 04:38 PM
The 8051 has too little memory to do anything us...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 19 2019, 10:44 PM
The 8051 has too little memory to do anything us...
ilylily07 Avatar
Posted By ilylily07
Mon Nov 18 2019, 09:54 AM
0v7670 camera interfacing with stc 8051.using asse...