vimj
Newbie level 2
I would be really grateful if someone has knowledge about PIC18F452 and would help me with its interfacing with GSM modem. The following program works successfully when PIC18F452 is interfaced with HyperTerminal. That is, PIC sends AT to HyperTerminal and I manually send OK to PIC and it displays the same on LCD screen. However, it doesn't work when it is interfaced with GSM modem. That is, I do not get OK for AT.
Also, can you at least mention the algorithm in general to interface a microcontroller with GSM Modem. I am using SIM300 GSM Modem
Thank you!
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Program to test interfacing of PIC18F452 with GSM Module.
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
listp=18f452 ; Using PIC18F452
#include<p18f452.inc>
REG1 EQU 0X000
REG2 EQU 0X001
ORG 0X0000
EUSART: BSF INTCON, GIE ; Enable global interrupts
BSF INTCON, PEIE ; Enable peripheral interrupts
MOVLW B'00100100' ; Enable transmit, 8 bits, HIGH-speed baud, asynchronous mode
MOVWF TXSTA
MOVLW D'25' ; Byte for 9600 baud 25 for BRGH=1 FOR 4 MHZ
MOVWF SPBRG
MOVLW B'10010000' ; Enable serial port, 8 bits, receive enable, No Check for framing or overrun error
MOVWF RCSTA
USARTINT:
BSF PIE1, TXIE ; Enable interrupt for transmitting data
BSF PIE1, RCIE ; Enable interrupt for receiving data
clrf TRISC
BSF TRISC, RX
clrf TRISD
CLRF TRISB
MOVLW 0X38 ; Initialising LCD with 2 lines 5 x 7 matrix
RCALL CMD
RCALL DELAY
MOVLW 0X0E ; Display on, cursor blinking
RCALL CMD
RCALL DELAY
MOVLW 0X01 ; Clear display screen
RCALL CMD
RCALL DELAY
MOVLW 0X06 ; Increment cursor (shift cursor to the right)
RCALL CMD
RCALL DELAY
MOVLW 0X80 ; Force cursor to beginning of 1st line.
RCALL CMD
RCALL DELAY
MOVLW 'A'
RCALL TRANSMIT
RCALL DATA1
RCALL DELAY
MOVLW 'T'
RCALL TRANSMIT
RCALL DATA1
RCALL DELAY
MOVLW 0X0D ; ASCII for Carriage Return
RCALL TRANSMIT
MOVLW 0X0A ; ASCII for New Line
RCALL TRANSMIT
AGAIN: RCALL RECEIVE ; Receiving information from GSM Modem and displaying it on LCD
RCALL DATA1
RCALL DELAY
BRA AGAIN
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; SUBROUTINES
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
TRANSMIT: BTFSS PIR1, TXIF ; Check if transmit register is empty
BRA TRANSMIT ; If not, wait until it is empty
MOVWF TXREG ; Write byte from W register into TXREG.
RETURN
RECEIVE: BTFSS PIR1, RCIF ; Check if new data byte arrived in RCREG
GOTO RECEIVE ; If RCIF flag is not set, go back and wait
MOVF RCREG, W ; If a new data byte has arrived, save in W register
RETURN
CMD: MOVWF PORTD,0 ; Send command on PORT D
BCF PORTC, 0, 0 ; (Port C pin no. 0) RS = 0 i.e. instruction command code register is selected
BCF PORTC, 1, 0 ; (PC pin 1) R/W-b = 0 i.e. Writing operation
BSF PORTC,2,0 ; (PC pin 2) E = 1
BCF PORTC,2,0 ; E = 0 i.e. a high to low transition for LCD to latch in the data present at data pins
RETURN 0
DATA1: MOVWF PORTD,0 ; Send data on PORT D
BSF PORTC, 0, 0 ; RS = 1 i.e. data register is selected
BCF PORTC, 1, 0 ; R/W-b = 0 i.e. Writing operation
BSF PORTC,2,0 ; E = 1
BCF PORTC,2,0 ; E = 0 i.e. a high to low transition for LCD to latch in the data present at data pins
RETURN 0
DELAY: MOVLW D'255' ; Delay subroutine.
MOVWF 0X20,0
UP: DECF 0X20,1,0
BNZ UP
RETURN 0
END
Also, can you at least mention the algorithm in general to interface a microcontroller with GSM Modem. I am using SIM300 GSM Modem
Thank you!
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Program to test interfacing of PIC18F452 with GSM Module.
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
listp=18f452 ; Using PIC18F452
#include<p18f452.inc>
REG1 EQU 0X000
REG2 EQU 0X001
ORG 0X0000
EUSART: BSF INTCON, GIE ; Enable global interrupts
BSF INTCON, PEIE ; Enable peripheral interrupts
MOVLW B'00100100' ; Enable transmit, 8 bits, HIGH-speed baud, asynchronous mode
MOVWF TXSTA
MOVLW D'25' ; Byte for 9600 baud 25 for BRGH=1 FOR 4 MHZ
MOVWF SPBRG
MOVLW B'10010000' ; Enable serial port, 8 bits, receive enable, No Check for framing or overrun error
MOVWF RCSTA
USARTINT:
BSF PIE1, TXIE ; Enable interrupt for transmitting data
BSF PIE1, RCIE ; Enable interrupt for receiving data
clrf TRISC
BSF TRISC, RX
clrf TRISD
CLRF TRISB
MOVLW 0X38 ; Initialising LCD with 2 lines 5 x 7 matrix
RCALL CMD
RCALL DELAY
MOVLW 0X0E ; Display on, cursor blinking
RCALL CMD
RCALL DELAY
MOVLW 0X01 ; Clear display screen
RCALL CMD
RCALL DELAY
MOVLW 0X06 ; Increment cursor (shift cursor to the right)
RCALL CMD
RCALL DELAY
MOVLW 0X80 ; Force cursor to beginning of 1st line.
RCALL CMD
RCALL DELAY
MOVLW 'A'
RCALL TRANSMIT
RCALL DATA1
RCALL DELAY
MOVLW 'T'
RCALL TRANSMIT
RCALL DATA1
RCALL DELAY
MOVLW 0X0D ; ASCII for Carriage Return
RCALL TRANSMIT
MOVLW 0X0A ; ASCII for New Line
RCALL TRANSMIT
AGAIN: RCALL RECEIVE ; Receiving information from GSM Modem and displaying it on LCD
RCALL DATA1
RCALL DELAY
BRA AGAIN
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; SUBROUTINES
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
TRANSMIT: BTFSS PIR1, TXIF ; Check if transmit register is empty
BRA TRANSMIT ; If not, wait until it is empty
MOVWF TXREG ; Write byte from W register into TXREG.
RETURN
RECEIVE: BTFSS PIR1, RCIF ; Check if new data byte arrived in RCREG
GOTO RECEIVE ; If RCIF flag is not set, go back and wait
MOVF RCREG, W ; If a new data byte has arrived, save in W register
RETURN
CMD: MOVWF PORTD,0 ; Send command on PORT D
BCF PORTC, 0, 0 ; (Port C pin no. 0) RS = 0 i.e. instruction command code register is selected
BCF PORTC, 1, 0 ; (PC pin 1) R/W-b = 0 i.e. Writing operation
BSF PORTC,2,0 ; (PC pin 2) E = 1
BCF PORTC,2,0 ; E = 0 i.e. a high to low transition for LCD to latch in the data present at data pins
RETURN 0
DATA1: MOVWF PORTD,0 ; Send data on PORT D
BSF PORTC, 0, 0 ; RS = 1 i.e. data register is selected
BCF PORTC, 1, 0 ; R/W-b = 0 i.e. Writing operation
BSF PORTC,2,0 ; E = 1
BCF PORTC,2,0 ; E = 0 i.e. a high to low transition for LCD to latch in the data present at data pins
RETURN 0
DELAY: MOVLW D'255' ; Delay subroutine.
MOVWF 0X20,0
UP: DECF 0X20,1,0
BNZ UP
RETURN 0
END