please help me
Does any1 know how to send SMS through a modem and read it????
im working on PIC16F887 and WaveCOM Fastrack m1206 modem.
i connected the TX and the RX throught max232
and i try this example from the site:
Code: Select all
program GSM_Test
' *
' * Project name:
' GSM_Test
' * Copyright:
' (c) MikroElektronika, 2009.
' * Revision History:
' 20090511:
' - initial release - Slavisa Zlatanovic;
' * Description:
' This is a simple project which demonstrates the use of Simcom SIM340Z GSM/GPRS module.
' Upon programming, connect your EasyGSM/GPRS SIM340Z to PORTC of your EasyPIC5 development board.
' The goal of this simple example is to display some basic functions of the GSM module like
' making and answering a call and hanging up. Note that you'll have to enter the number you wish
' to dial to in the atc3 constant.
' * Test configuration:
' MCU: PIC16F887
' http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf#page=123
' Dev.Board: EasyPIC5
' http://www.mikroe.com/en/tools/easypic5/
' Oscillator: HS, 8.00000 MHz
' Ext. Modules: EasyGSM/GPRS SIM340Z extra board on PORTC
' http://www.mikroe.com/en/tools/gsm/easygsm-gprs-sim340z/
' SW: mikroC PRO for PIC
' http://www.mikroe.com/en/compilers/mikrobasic/pro/pic/
' * NOTES:
' - Put the pull-down resistors on the PORTD
' - Pull-up resistors on the RC6 and RC7 pins
' - In order to connect EasyGSM/GPRS SIM340Z to EasyPIC5 dev. board you need to use 5V-3.3V voltage translator
' - Used pins of the Simcom SIM340Z module:
' 1,2,3,4,5,6,7,8: VBATT
' 9,10,11,12,13,14,50,51: GND
' 34: PWRKEY
' 42: TXD - MCU's RC6
' 40: RXD - MCU's RC7
' 44: RTS - MCU's RC4
' *
' lcd module connections
dim LCD_RS as sbit at RB4_bit
LCD_EN as sbit at RB5_bit
LCD_D4 as sbit at RB0_bit
LCD_D5 as sbit at RB1_bit
LCD_D6 as sbit at RB2_bit
LCD_D7 as sbit at RB3_bit
LCD_RS_Direction as sbit at TRISB4_bit
LCD_EN_Direction as sbit at TRISB5_bit
LCD_D4_Direction as sbit at TRISB0_bit
LCD_D5_Direction as sbit at TRISB1_bit
LCD_D6_Direction as sbit at TRISB2_bit
LCD_D7_Direction as sbit at TRISB3_bit
' end lcd module connections
' set of AT commands
const atc0 = "AT" ' every GSM comand starts with "AT"
const atc1 = "ATE0" ' disable echo
const atc2 = "AT+CFUN=1" ' set full functionality
const atc3 = "ATD0788488691;" ' place a call to phone number 123456789
' instead of 123456789 insert your phone number
const atc4 = "ATH" ' hang up
const atc5 = "ATA" ' answer a call
' lcd interface messages
const LCD_MESSAGE_LENGTH = 16
const lcd1 = "Initializing..."
const lcd2 = "Power-Up GSM!!!"
const lcd3 = "RD3-Continue"
const lcd4 = "Ready! RD0-Dial"
const lcd5 = "RD1-HNG RD2-ANSW"
const lcd6 = "Calling..."
const lcd7 = "Hanging Up!"
const lcd8 = "Answering!"
const lcd9 = "RING!!!"
' responses to parse
const GSM_OK = 0
const GSM_RING = 1
dim gsm_state as byte
dim response_rcvd as byte
dim responseID, response as short
dim txt_temp as string[20] ' temporary variable
dim temp_short as short ' temporary variable
' copy const to ram string
sub function CopyConst2Ram(dim const src as ^byte) as string[20]
dim i as byte
i = 0
while src^ <> 0
result[i] = src^
inc(src)
inc(i)
wend
result[i] = 0
end sub
' uart rx interrupt handler
sub procedure interrupt()
dim tmp as byte
if (PIR1.RCIF = 1) then ' do we have uart rx interrupt request
tmp = UART1_Read() ' get received byte
' process reception through state machine
' we are parsing only: "OK", "RING" responses
select case gsm_state
case 0 response = -1 ' clear response
if (tmp = "O") then ' we have "O", it could be "OK"
gsm_state = 1 ' expecting "K"
end if
if (tmp = "R") then ' we have 'R', it could be "RING"
gsm_state = 10 ' expecting 'I' or 'e'
end if
case 1 if (tmp = "K") then
response = GSM_OK ' we have "OK" response
gsm_state = 50 ' expecting CR+LF
else
gsm_state = 0 ' reset state machine
end if
case 10 if (tmp = "I") then ' we have 'I', it could be "RING"
gsm_state = 11 ' expecting 'N'
else
gsm_state = 0 ' reset state machine
end if
case 11 if (tmp = "N") then ' we have 'N', it could be "RING"
gsm_state = 12 ' expecting 'G'
else
gsm_state = 0 ' reset state machine
end if
case 12 if (tmp = "G") then ' we have 'G' ->
response = GSM_RING ' we have "RING" response
gsm_state = 50 ' expecting CR+LF
else
gsm_state = 0 ' reset state machine
end if
case 50 if (tmp = 13) then ' we have 13, it could be CR+LF
gsm_state = 51 ' expecting LF
else
gsm_state = 0 ' reset state machine
end if
case 51 if (tmp = 10) then ' we have LF, response is complete
response_rcvd = 1 ' set reception flag
responseID = response ' set response ID
else
gsm_state = 0 ' reset state machine
end if
case else ' unwanted character
gsm_state = 0 ' reset state machine
end select
end if
end sub
' send ATC command
sub procedure send_atc(dim const s as ^char)
' send command string
while(s^ <> 0 )
UART1_Write(s^)
inc(s)
wend
' terminate command with CR
UART1_Write(0x0D)
end sub
' get GSM response, if there is any
sub function get_response() as short
if (response_rcvd <> 0) then
response_rcvd = 0
result = responseID
else
result = -1
end if
end sub
' wait for GSM response
sub procedure wait_response(dim rspns as short)
while (get_response() <> rspns)
nop
wend
end sub
' pause
sub procedure wait()
Delay_ms(1000)
end sub
main:
gsm_state = 0 ' initialization of state mashine parameters
responseID = -1
response = -1
' all pins as digital I/Os
ANSEL = 0
ANSELH = 0
' set PORTD inputs
TRISD0_bit = 1 ' place a call input
TRISD1_bit = 1 ' hang up input
TRISD2_bit = 1 ' answer a call input
TRISD3_bit = 1 ' continue with PIC program
' set RTS pin to zero, we will use only RX i TX
TRISC.B4 = 0
PORTC.B4 = 0
' enable uart rx interrupt
PIE1.RCIE = 1
INTCON.PEIE = 1
INTCON.GIE = 1
' setup lcd module
Lcd_Init()
Lcd_Cmd(_LCD_CURSOR_OFF)
' LCD_Out: power-up gsm
txt_temp = CopyConst2Ram(@lcd2)
LCD_Out(1,1,txt_temp)
txt_temp = CopyConst2Ram(@lcd3)
LCD_Out(2,1,txt_temp)
UART1_init(9600) ' initialize USART module
' wait for start
while(PORTD.B3 = 0)
nop
wend
Lcd_Cmd(_LCD_CLEAR)
' LCD_Out: Initializing...
txt_temp = CopyConst2Ram(@lcd1)
LCD_Out(1,1,txt_temp)
Delay_ms(5000) ' wait for the GSM module to initialize it self
' negotiate baud rate
while TRUE
send_atc(@atc0) ' send "AT" string until gsm sets up its baud rade
Delay_ms(100) ' and gets it correctly
if (get_response() = GSM_OK) then break ' if gsm says "OK" on our baud rate than we got it
end if
wend
' disable command echo
send_atc(@atc1)
temp_short = GSM_OK
wait_response(temp_short)
' set full functionality
send_atc(@atc2)
wait_response(temp_short)
while TRUE
txt_temp = CopyConst2Ram(@lcd4)
LCD_Out(1,1,txt_temp)
' LCD_Out: RB1-HNG RB2-ASW
txt_temp = CopyConst2Ram(@lcd5)
LCD_Out(2,1,txt_temp)
if Button(PORTD, 0, 10, 1) then
' mobile originated call to specified number
send_atc(@atc3)
temp_short = GSM_OK
wait_response(temp_short)
Lcd_Cmd(_LCD_CLEAR)
' LCD_Out: Calling...
txt_temp = CopyConst2Ram(@lcd6)
LCD_Out(1,1,txt_temp)
wait()
wait()
end if
if Button(PORTD, 1, 10, 1) then
' disconnect existing connection
send_atc(@atc4)
temp_short = GSM_OK
wait_response(temp_short)
Lcd_Cmd(_LCD_CLEAR)
' LCD_Out: Hanging Up!
txt_temp = CopyConst2Ram(@lcd7)
LCD_Out(1,1,txt_temp)
wait()
end if
if Button(PORTD, 2, 10, 1) then
'answer a call `
send_atc(@atc5)
' wait_response(GSM_OK);
temp_short = GSM_OK
wait_response(temp_short)
Lcd_Cmd(_LCD_CLEAR)
' LCD_Out: Answering!
txt_temp = CopyConst2Ram(@lcd8)
LCD_Out(1,1,txt_temp)
wait()
end if
' process gsm response
if (response_rcvd <> 0 ) then
response_rcvd = 0 ' clear response received flag
select case responseID
case GSM_OK nop ' do nothing
case GSM_RING
'LCD_Out:RING!!!
txt_temp = CopyConst2Ram(@lcd9)
LCD_Out(1,1,txt_temp)
wait()
case else nop ' process illegal responses
end select
end if
wend
end.
And its work very well i can make a call and hang up and answer a call.
i just want to know how to send a SMS and read it back.[/quote]