Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Sending text 16f628 +GSM modem

Status
Not open for further replies.

Larynx1

New Member
Hi everyone,

I am trying to send a text message via a Wavecom fastrack supreme and a 16f628
I know that the subject has been covered many times before, but I can't find much written in .ASM.
I need some help regarding the response from the modem.

When I connect the modem to the PC and send AT+CMGS="***********" <ENTER> (number to dial), I receive a response from the modem,(>).

The question is this... do I need to look for 0x3E before I can send the message?

I haven't a max232 at the moment, so I haven't yet tried to send the pic to the PC.

Thanks in advance for any help received.


Code:
	list P=16F628
	#include <P16F628.INC>
	ERRORLEVEL	0,	-302	;suppress bank selection messages
	__config 0x0210
 
		cblock 0x20		;start of general purpose registers

		
		count			;used in looping routines
		count1			;used in delay routine
		counta			;used in delay routine
		countb			;used in delay routine
		Xmit_Byte        	;holds byte to xmit
            	Rcv_Byte        	;holds received byte 
            	Bit_Cntr        	;bit counter for RS232
            	Delay_Count        	;delay loop counter

		endc
 
SER_PORT	Equ	PORTB
SER_TRIS	Equ	TRISB
SER_IN		Equ	0x07
SER_OUT		Equ	0x06



		org	0x0000

Start		movlw	0x07
		movwf	CMCON			;turn comparators off (make it like a 16F84)

Initialise	clrf	count
		clrf	PORTA
		clrf	PORTB	
		call	SER_INIT		;initialise serial port
		call	Long_Delay
		movlw	0x19			;9600 baud with 4Mhz Internal Oscillator
		movwf	SPBRG
		movlw   0x00			;select first string
		call	Print_String
;Done		goto	Done			;loop for ever
 

Print_String	movwf	count1			;save string number (0 is first string)
		clrf	count			;set counter register to zero
NextLine	movf	count1,		w
		xorlw	0x00			;is it a zero?
		btfsc	STATUS, 	Z
		goto	NextChar		;if so we've reached required string
		movlw	0x07
		movwf	PCLATH
		movf	count, 		w	;put counter value in W
		call	Dial_num			;get a character from the text table
		clrf	PCLATH
		xorlw	0x00			;is it a zero?
		btfsc	STATUS, 	Z
		decf	count1,		f
		incf	count, 		f
		goto	NextLine
		
NextChar					;display selected string
		movlw	0x07			;set PCLATH for strings in last page of memory
		movwf	PCLATH
		movf	count, 		w	;put counter value in W
		call	Dial_num			;get a character from the text table
		clrf	PCLATH			;reset PCLATH
		xorlw	0x00			;is it a zero?
		btfsc	STATUS, 	Z
		return				;exit from routine
		call	XMIT_RS232
		incf	count, 		f
		goto	NextChar
 

 

;Serial routines

SER_INIT
            BSF     STATUS, RP0           ;select bank 1
            BCF     SER_TRIS, SER_OUT     ;set B6 as an output
            BSF     SER_TRIS, SER_IN      ;set B7 as an input
            BCF     STATUS, RP0           ;select bank 0
            BSF     SER_PORT, SER_OUT     ;set SER_OUT high
            RETURN

XMIT_RS232  MOVWF   Xmit_Byte             ;move W to Xmit_Byte
            MOVLW   0x08                  ;set 8 bits out
            MOVWF   Bit_Cntr
            BCF     SER_PORT, SER_OUT
            CALL    Bit_Delay
Ser_Loop    RRF     Xmit_Byte , f         ;send one bit
            BTFSS   STATUS    , C
            BCF     SER_PORT, SER_OUT
            BTFSC   STATUS    , C
            BSF     SER_PORT, SER_OUT
            CALL    Bit_Delay
            DECFSZ  Bit_Cntr  , f         ;test if all done
            GOTO    Ser_Loop
            BSF     SER_PORT, SER_OUT
            CALL    Bit_Delay
            RETURN

Rcv_RS232   BTFSC   SER_PORT, SER_IN      ;wait for start bit
            GOTO    Rcv_RS232
            CALL    Start_Delay	          ;do half bit time delay
            BTFSC   SER_PORT, SER_IN      ;check still in start bit
            GOTO    Rcv_RS232
            MOVLW   0x08                  ;set up to read 8 bits
            MOVWF   Bit_Cntr
            CLRF    Rcv_Byte
Next_RcvBit CALL    Bit_Delay
            BTFSS   SER_PORT, SER_IN
            BCF     STATUS    , C
            BTFSC   SER_PORT, SER_IN
            BSF     STATUS    , C
            RRF     Rcv_Byte  , f
            DECFSZ  Bit_Cntr  , f         ;test if all done
            GOTO    Next_RcvBit
            CALL    Bit_Delay
            MOVF    Rcv_Byte, W
            RETURN

Start_Delay MOVLW   0x0C
            MOVWF   Delay_Count
Start_Wait  NOP
            DECFSZ  Delay_Count , f
            GOTO    Start_Wait
            RETURN

Bit_Delay   MOVLW   0x18
            MOVWF   Delay_Count
Bit_Wait    NOP
            DECFSZ  Delay_Count , f
            GOTO    Bit_Wait
            RETURN

;End of serial routines

;Delay routines

Long_Delay
		call	Delay255
		call	Delay255
		call	Delay255
		call	Delay255
		return

Delay255	movlw	0xff		;delay 255 mS
		goto	d0
Delay100	movlw	d'100'		;delay 100mS
		goto	d0
Delay50		movlw	d'50'		;delay 50mS
		goto	d0
Delay20		movlw	d'20'		;delay 20mS
		goto	d0
Delay10		movlw	d'10'		;delay 10mS
		goto	d0
Delay1		movlw	d'1'		;delay 1mS
		goto	d0
Delay5		movlw	0x05		;delay 5.000 ms (4 MHz clock)
d0		movwf	count1
d1		movlw	0xC7
		movwf	counta
		movlw	0x01
		movwf	countb
Delay_0		decfsz	counta, f
		goto	$+2
		decfsz	countb, f
		goto	Delay_0

		decfsz	count1	,f
		goto	d1
		retlw	0x00

;end of Delay routines


	org	0x0700				;set to last page of memory
Dial_num  	addwf   PCL       , f



            	retlw   0x61		;A
            	retlw   0x54		;T
            	retlw   0x2B		;+
            	retlw   0x43		;C
            	retlw   0x4D		;M		
            	retlw   0x47		;G
            	retlw   0x53		;S
            	retlw   0x3D		;=
		retlw	0x22		;"
		retlw	0x30		;0
		retlw	0x37		;7
		retlw	0x37		;7
		retlw	0x38		;8
		retlw	0x33		;3
		retlw	0x37		;7
		retlw	0x31		;1
		retlw	0x32		;2
		retlw	0x35		;5
		retlw	0x31		;1
		retlw	0x39		;9
		retlw	0x22		;"
            	retlw   0x0D		;ENTER


            	
		end
 
Last edited:
I have sent messages via an 'actual' phone with a 16f628 before. I tried it through Hyperterminal first. Once I'd gotten it working there, I moved on to the Pic. That's where I'd advise you to start.
If you can get it working with a 'terminal' emulator (I.e Hyperterminal, Teraterm etc. . . .) to start with, then you can move on.
 
HouseOFwax, I have sucessfully sent a text via the gsm modem!

I used Tut_7 of Nigel's excellent tutorial, didn't even need to use the 16f628 uart. Just need to sort out the timing, my message came through along with AT commands as text. Can't be far off now!!!
 
Help!

Can anyone explain why this is happening. I am monitoring 6 inputs of 16f628 and sending SMS via Wavecom GSM modem depending on state of the inputs.

I can send 2 different messages to 2 different mobiles no problem; but now I need to send the same message to 2 mobiles.

The problem I have is this. When the text is received on DIAL1, it has the AT commands and phone no. for DIAL2 along with the message.

Is the micro sending the data to the modem for the 2nd no. too quickly?

I have tried to increase the delay in WAIT, but all this does is to delay the transmission of the text.

Any help greatly appreciated.


Code:
NO_PWR	
		BTFSS	M_FP			
		GOTO	MAIN
		CALL	DIAL1
		CALL	MESS_8
		CALL	WAIT
		CALL	DIAL2
		CALL	MESS_8
		CALL	WAIT
		BCF	TXRLY
		BCF	SER_OUT			
		
NO_PWR1
		BTFSC	FIRE
		GOTO	F_ACT
		BTFSS	M_FP			
		GOTO	REP_3		
		BTFSC	M_FP	
		GOTO	NO_PWR1
		GOTO	MAIN
REP_3
		CALL	DIAL1
		CALL	MESS_7
		CALL	WAIT
		CALL	DIAL2
		CALL	MESS_7
		CALL	WAIT
		BCF	TXRLY
		BCF	SER_OUT
		GTO	MAIN
DIAL1:		
		BSF     SER_OUT       		
		BSF	TXRLY
		CALL	WAIT
		movlw	0x41		;A
		call	XMIT_RS232
		movlw	0x54		;T
		call	XMIT_RS232
		movlw	0x2B		;+
		call	XMIT_RS232
		movlw	0x43		;C
		call	XMIT_RS232
		movlw	0x4D	;M
		call	XMIT_RS232
		movlw	0x47		;G
		call	XMIT_RS232
		movlw	0x53		;S
		call	XMIT_RS232
		movlw	0x3D		;=
		call	XMIT_RS232
		movlw	0x22		;"
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'"'		;"
		call	XMIT_RS232
            	movlw   0x0D		;ENTER
		call	XMIT_RS232
		return	
;------------------------------------
DIAL2:		
		BSF     SER_OUT       		;set SER_OUT high
		BSF	TXRLY
		CALL	WAIT
		movlw	0x41		;A
		call	XMIT_RS232
		movlw	0x54		;T
		call	XMIT_RS232
		movlw	0x2B		;+
		call	XMIT_RS232
		movlw	0x43		;C
		call	XMIT_RS232
		movlw	0x4D		;M
		call	XMIT_RS232
		movlw	0x47		;G
		call	XMIT_RS232
		movlw	0x53		;S
		call	XMIT_RS232
		movlw	0x3D		;=
		call	XMIT_RS232
		movlw	0x22		;"
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'*'		
		call	XMIT_RS232
		movlw	'"'		
		call	XMIT_RS232
            	movlw   0x0D		;ENTER
		call	XMIT_RS232
		return	
MESS_1:		
		movlw	0x4D		
		call	XMIT_RS232
		movlw	0x61		
		call	XMIT_RS232
		movlw	0x69		
		call	XMIT_RS232
		movlw	0x6E		
		call	XMIT_RS232
		movlw	0x73		
		call	XMIT_RS232
		movlw	0x20		
		call	XMIT_RS232
		movlw	0x50		
		call	XMIT_RS232
		movlw	0x6F		
		call	XMIT_RS232
		movlw	0x77		
		call	XMIT_RS232
		movlw	0x65		
		call	XMIT_RS232
		movlw	0x72		
		call	XMIT_RS232
		movlw	0x20		
		call	XMIT_RS232
		movlw	0x48		
		call	XMIT_RS232
		movlw	0x61		
		call	XMIT_RS232
		movlw	0x73		
		call	XMIT_RS232
		movlw	0x20		
		call	XMIT_RS232
		movlw	0x42		
		call	XMIT_RS232
		movlw	0x65		
		call	XMIT_RS232
		movlw	0x65		
		call	XMIT_RS232
		movlw	0x6E	
		call	XMIT_RS232
		movlw	0x20		
		call	XMIT_RS232
		movlw	0x52		
		call	XMIT_RS232
		movlw	0x65		
		call	XMIT_RS232
		movlw	0x73		
		call	XMIT_RS232
		movlw	0x74		
		call	XMIT_RS232
		movlw	0x6F		
		call	XMIT_RS232
		movlw	0x72		
		call	XMIT_RS232		
		movlw	0x65		
		call	XMIT_RS232
		movlw	0x64		
		call	XMIT_RS232
		movlw	0x2E		
		call	XMIT_RS232
		movlw	0x1A		;cntl+z
		call	XMIT_RS232
		return
	
WAIT		;2 sec 
		movlw	0x11
		movwf	d4
		movlw	0x5D
		movwf	d5
		movlw	0x05
		movwf	d6

WAIT_06
		decfsz	d4, f
		goto	$+2
		decfsz	d5, f
		goto	$+2
		decfsz	d6, f
		goto	WAIT_06
		return
 
Sorted the problem. placed a delay after dialing each number. I don't monitor the modem response so was probably sending at commands too quickly.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top