kemystri
Junior Member level 2
- Joined
- Feb 13, 2008
- Messages
- 20
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,446
;*****************************************************************;
; REAL-TIME GROUP ;
; Test Program for USART ;
; Date Created: January 17, 2008 4:00 PM ;
; ver 1.0 ;
;*****************************************************************;
list p=16F877; list directive to define processor
#include <p16F877.inc>; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC & _BODEN_OFF & _LVP_OFF
DataByte equ 20h
TEMP2 equ 21h
DELA1 equ 22h
DELA2 equ 23h
DELA3 equ 24h
TEMP_PORTA equ 25h
loop_delay_char equ 26h
org 00h
;************************************
; Set Up the Baud Rate of the
; USART to 9600 bps
;************************************
BANKSEL SPBRG
movlw d'25'
movwf SPBRG
BANKSEL TXSTA
bsf TXSTA,BRGH
;************************************
; Set Up the The Reception of Data
; Continuous Reception is enabled
;************************************
BANKSEL TXSTA
movlw B'00100100'
movwf TXSTA
BANKSEL RCSTA
movlw B'10010000'
movwf RCSTA
bcf status,rp0
bcf status,rp1
BANKSEL TRISB
bcf trisb,7
bcf trisb,5
bcf trisb,3
BANKSEL TRISA
bsf TRISA,3
bcf TRISA,0
bcf TRISA,1
bcf TRISA,2
movlw d'6'
movwf ADCON1
BANKSEL PORTA
bcf PORTA,0
bcf PORTA,1
bcf PORTA,2
START
banksel PORTb
bcf portb,3
BANKSEL PORTA
movf PORTA,w
movwf TEMP_PORTA
bsf TEMP_PORTA,0
bsf TEMP_PORTA,1
bsf TEMP_PORTA,2
movf TEMP_PORTA,w
BANKSEL PORTA
movwf PORTA
call delay
btfss TEMP_PORTA,3
goto START
bcf TEMP_PORTA,0
bcf TEMP_PORTA,1
bcf TEMP_PORTA,2
movf TEMP_PORTA,w
BANKSEL PORTA
movwf PORTA
;==================================
;change hexadecimal to text mode
;==================================
call delay
call delay
call delay
banksel PORTb
bsf portb,3
movlw h'61'
call sub_sendByteToPhone
call loop_tx
movlw h'74'
call sub_sendByteToPhone
call loop_tx
;================================
;test if ok?
;we checked if we recieve a "ok" reply from the gsm
;================================
SEND_O2
call loop
movf DataByte,w
addlw -a'O'
btfss STATUS,Z
GOTO SEND_O2
banksel pir1
bcf PIR1, RCIF ;clear the character present flag
banksel PORTb
bsf portb,7
SEND_K2
CALL LOOP
movf DataByte,w
addlw -a'K'
btfss STATUS,Z
GOTO SEND_K2
banksel pir1
bcf PIR1, RCIF ;clear the character present flag
banksel PORTb
bcf portb,7
bsf portb,5
goto start
sub_sendByteToPhone
BANKSEL TXREG
movwf TXREG
return
;========================
;normal delay
;========================
delay
movlw d'1'
movwf dela3
loop3
movlw d'20'
movwf dela2
loop2
movlw d'20'
movwf dela1
loop1
nop
nop
nop
decfsz dela1,f
goto loop1
decfsz dela2,f
goto loop2
decfsz dela3,f
goto loop3
return
;========================
;delay for enter
;========================
;========================
;delay for chracters
;========================
delay_char
movlw d'1'
movwf dela3
loop3_char
movlw d'20'
movwf dela2
loop2_char
movlw d'20'
movwf dela1
loop1_char
nop
nop
nop
decfsz dela1,f
goto loop1_char
decfsz dela2,f
goto loop2_char
decfsz dela3,f
goto loop3_char
decfsz loop_delay_char,f
call delay_char
return
var_char
movlw d'5'
movwf loop_delay_char
return
Loop
BANKSEL PIR1
btfss PIR1, RCIF ;wait for receive character set
goto Loop ;nothing there
readByteFromPhone
;put data received from RCREG
;to W register and DataByte register
BANKSEL RCREG
movf RCREG,W
BANKSEL DataByte
movwf DataByte
return
Loop_tx
BANKSEL PIR1
btfss PIR1,TXIF
goto Loop_tx
return
end
The cable that you use with GSM module and with Hyper Terminal has no cross over connection, but when GSM module and PIC will be communicating, RTS and CTS pins should be short at the GSM module side, additionally TX and RX must be swap.I have given you the hint, that's the only way your PIC would communicate with GSM module.I myself have wasted so much time in it, until I discovered this remedy.
If still you're unclear, let me know.I'll tell you how to do it.
Autobauding option is another PROBLEM with communication, when autobauding is enabled, the GSM uses other pins for communications rather than just TX,RX which create another issues.So what you have to do, is that make baud rate constant of your GSM module, there will be AT command for doing this, after this YOU JUST SAVE THIS INFORMATION INTO THE GSM MODULE FLASH.Or else, you still won't be getting the correct results.There are so many little things, that are necessary for making successfull communication.
we set a program for the pic to test it to the hyperterminal, by the way it goes
it works just fine but when we connect it to the benw m22 module it seem that it
wont establish a connection
umery2k75 said:I think it must be given in DTE-DCE local flow control at page 163.
But pages are missing in AT command file from Page 160-166
By pin number on DB-9, I don't remember which one is DSR and DTR, I'm sure they are shorted in the diagram which I have given you in the PDF file.Those serial cables designs are tested and they work.
The theme is that you won't use Hardware Flow Control communication and neither the Software Flow Control XOR/XNOR.You won't use Flow Control, so that you don't need CTS,RTS,etc.It is important where a GSM modem is working at different baud rate and your PIC is working at a different baud rate.To make communication possible, such pins are necessary.
But over here same baud rate will be set for GSM modem and PIC.Some pins will be shorted at the GSM modem side, so as to make it think it's in fully controlled co-ordination with PIC.Where as you'll use only TX and RX pins for communcation with GSM.
ive worked with ur connection and it still doesnt work fine. T.T
umery2k75 said:
even the gsm module are connected internally with just TX and RX and GND.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?