Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me combine program for reading GPS data and one for sending it via GSM

Status
Not open for further replies.

jodatnia

Newbie level 3
Joined
Jul 23, 2009
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
iran
Activity points
1,532
can anyone help me to combine these two programmes I want to read Gps data(latitude&longitude) and send with Gsm :
gps :
$regfile = "m16def.dat"
$crystal = 11059200
$baud = 9600
'-------------------------------------------------------------------------------
Config Lcd = 20 * 4
Cls
Cursor Off
'-------------------------------------------------------------------------------
Config Porta.1 = Output : Reset Porta.1
Config Portb.0 = Output : Led1 Alias Portb.0
'-------------------------------------------------------------------------------
Deflcdchar 0 , 7 , 5 , 7 , 32 , 32 , 32 , 32 , 32
'-------------------------------------------------------------------------------
On Urxc Rec_isr
Enable Urxc
Enable Interrupts
'-------------------------------------------------------------------------------
'GPS variables
Dim Urx_buff As String * 550
Dim Cnt As Word
Dim M As String * 5
Dim Gpgga As String * 80
Dim Gpvtg As String * 80
Dim Gpgga_flag As Bit
Dim Gpvtg_flag As Bit
Dim V_counter As Byte
Dim I As Byte
Dim L As Byte
Dim F_utc_time As Byte
Dim E_utc_time As Byte
Dim F_longitude As Byte
Dim E_longitude As Byte
Dim F_latitude As Byte
Dim E_latitude As Byte
Dim F_altitude As Byte
Dim E_altitude As Byte
Dim F_speed As Byte
Dim E_speed As Byte
Dim F_sat_num As Byte
Dim E_sat_num As Byte
Dim Utc_time As String * 10
Dim Utc_time_k As String * 10
Dim Longitude As String * 12
Dim Latitude As String * 12
Dim Altitude As String * 8
Dim Speed As String * 8
Dim Sat_num As String * 4
Dim Sat_inuse As Byte
Dim S_k1 As Single
Dim S_k2 As Single
Dim R_k1 As String * 15
Dim N As Byte
'-------------------------------------------------------------------------------
Locate 1 , 1 : Lcd "GPS"
Locate 2 , 1 : Lcd "connecting..."
Locate 3 , 1 : Lcd "Please wait..."

Do
'-------------------------------------------------------------------------------
If Cnt > 520 Then
Set Led1
Disable Urxc
Gosub Get_nmeapaket
Gosub Extract
Reset Led1
Urx_buff = ""
Cnt = 0
Enable Urxc
End If
'--------------------------------------------------
Loop
End
'-------------------------------------------------------------------------------
Get_nmeapaket:
For Cnt = 1 To 500
M = Mid(urx_buff , Cnt , 5)
If M = "GPGGA" Then
Gpgga = ""
V_counter = 0
Do
M = Mid(urx_buff , Cnt , 1)
Incr V_counter
Incr Cnt
Gpgga = Gpgga + M
Loop Until V_counter > 78 Or M = "*"
Exit For
End If
Next
For Cnt = 1 To 500
M = Mid(urx_buff , Cnt , 5)
If M = "GPVTG" Then
Gpvtg = ""
V_counter = 0
Do
M = Mid(urx_buff , Cnt , 1)
Incr V_counter
Incr Cnt
Gpvtg = Gpvtg + M
Loop Until V_counter > 78 Or M = "*"
Exit For
End If
Next
Urx_buff = ""
Cnt = 0
Return
'-------------------------------------------------------------------------------
Extract:
V_counter = 0
L = Len(gpgga)
For I = 1 To L
M = Mid(gpgga , I , 1)
If M = "," Then
Incr V_counter
If V_counter = 1 Then
F_utc_time = I + 1

Elseif V_counter = 2 Then
E_utc_time = I - F_utc_time
F_latitude = I + 1

Elseif V_counter = 3 Then
E_latitude = I - F_latitude

Elseif V_counter = 4 Then
F_longitude = I + 1

Elseif V_counter = 5 Then
E_longitude = I - F_longitude

Elseif V_counter = 7 Then
F_sat_num = I + 1

Elseif V_counter = 8 Then
E_sat_num = I - F_sat_num

Elseif V_counter = 9 Then
F_altitude = I + 1

Elseif V_counter = 10 Then
E_altitude = I - F_altitude
End If

End If
Next
Utc_time = Mid(gpgga , F_utc_time , E_utc_time) : Utc_time = Left(utc_time , 6)
Latitude = Mid(gpgga , F_latitude , E_latitude)
Longitude = Mid(gpgga , F_longitude , E_longitude)
Altitude = Mid(gpgga , F_altitude , E_altitude)
Sat_num = Mid(gpgga , F_sat_num , E_sat_num)

R_k1 = Left(latitude , 2)
S_k1 = Val(r_k1)
Latitude = Mid(latitude , 3 , 7)
S_k2 = Val(latitude)
S_k2 = S_k2 / 60
S_k2 = S_k2 + S_k1
Latitude = Fusing(s_k2 , "#.######")

R_k1 = Left(longitude , 3)
S_k1 = Val(r_k1)
Longitude = Mid(longitude , 4 , 7)
S_k2 = Val(longitude)
S_k2 = S_k2 / 60
S_k2 = S_k2 + S_k1
Longitude = Fusing(s_k2 , "#.######")
N = Val(sat_num)

If S_k2 <> 0 And N > 1 Then
Locate 1 , 1 : Lcd "Latitude=" ; Latitude ; Chr(0) ; " "
Locate 2 , 1 : Lcd "Longitud=" ; Longitude ; Chr(0) ; " "
Locate 3 , 1 : Lcd "Utc_time=" ; Utc_time
Locate 4 , 1 : Lcd "Altitud=" ; Altitude ; "m N=" ; Sat_num
End If
Return
'-------------------------------------------------------------------------------
Rec_isr:
Incr Cnt
Urx_buff = Urx_buff + Chr(udr)
Return








and GSM programme:




$regfile = "m16def.dat"
$crystal = 11059200
$baud = 9600
'$sim

Declare Sub Getline(s As String)
Declare Sub Flushbuf()
Declare Sub Showsms(s As String )


Dim I As Byte , B As Byte
Dim Sret As String * 200 , Stemp As String * 6 , W As Word
Dim S1 As String * 200 , S2 As String * 200



Ddrb.0 = 1
Ddrd.4 = 1

Config Lcdpin = Pin , Db4 = Pinc.4 , Db5 = Pinc.5 , Db6 = Pinc.6 , Db7 = Pinc.7 , E = Pinc.3 , Rs = Pinc.2
Config Lcd = 16 * 2

Cls
Home
Lcd "nEW"
'---------------------------------------------

Lowerline : Lcd "ON Process"
Toggle Portd.4
Portb.0 = 1
Wait 2
Toggle Portd.4
Portb.0 = 0
Wait 4
Toggle Portd.4
Portb.0 = 1
Wait 15
Toggle Portd.4

Print "AT" ; Chr(13)
Wait 1

Print "AT" ; Chr(13)
Wait 1

Print "AT" ; Chr(13)
Wait 1
Print "AT" ; Chr(13)
Wait 1
Print "AT" ; Chr(13)
Wait 1
Print "ATE0" ; Chr(13)
Wait 1



'----------------------------------------------
'sms settings

Cls : Home : Lcd "send sms"
Wait 1
Print "AT+CMGF=1" ; Chr(13)
Wait 1
Print "AT+CMGS=" ; Chr(34) ; "0913322222" ; Chr(34) ; Chr(13)
Wait 1
Print "SIM IS Restarted" ; Chr(26)
Lowerline : Lcd "sent sms1"
Getline Sret
Cls : Lowerline
Lcd Sret
Wait 4

Print "AT+CGATT=1" ; Chr(13)
Getline Sret
' get data from modem
Cls : Lowerline
Lcd Sret
Wait 4
Print "AT+CIPSTART=" ; Chr(34) ; "UDP" ; Chr(34) ; "," ; Chr(34) ; "91.98.32.182" ; Chr(34) ; "," ; Chr(34) ; "8830" ; Chr(34) ; Chr(13)
Getline Sret
Cls : Lowerline
Lcd Sret
Wait 4
Print "AT+CIPSEND" ; Chr(13)
Wait 1
Print Chr(01) ; Chr(02) ; Chr(03) ; Chr(26)
Getline Sret
Cls : Lowerline
Lcd Sret
Wait 4

Print "AT+CIPSEND" ; Chr(13)
Wait 1
Print 123
Getline Sret
Cls : Lowerline
Lcd Sret
Wait 4

Print "AT+CIPSEND" ; Chr(13)
Wait 1
Print "123"
Getline Sret
Cls : Lowerline
Lcd Sret
Wait 4


'--------------------------------------------------


Do
Getline Sret ' get data from modem
Cls : Lowerline
Lcd Sret
Wait 1
I = Instr(sret , ":") ' look for :
If I > 0 Then 'found it
Stemp = Left(sret , I)
Select Case Stemp
Case "+CMTI:" : Showsms Sret ' we received an SMS
' hanle other cases here
End Select
End If

Loop
Flushbuf




End



Sub Showsms(s As String )
Cls : Home
I = Instr(s , ",") ' find comma
I = I + 1
Stemp = Mid(s , I) ' s now holds the index number
Lcd "Number=" ; Stemp
Wait 1

Print "AT+CMGR=" ; Stemp ' get the message
Getline S1
Getline S2 ' header +CMGR: "REC READ","+316xxxxxxxx",,"02/04/05,01:42:49+00"
Cls : Home : Lcd "back sms"
Wait 1
Print "AT+CMGF=1" ; Chr(13)
Wait 1
Print "AT+CMGS=" ; Chr(34) ; "0913333333" ; Chr(34) ; Chr(13)
Wait 1
Print S1
Wait 1
Print S2 ; Chr(26)
Lowerline : Lcd "backed sms1"
Wait 4
Cls : Home
Lcd "remove sms"
Print "AT+CMGD=" ; Stemp ' delete the message
End Sub


Sub Getline(s As String)
S = ""
Do
B = Inkey()
Select Case B
Case 0 'nothing
Case 13 : If S <> "" Then Exit Do ' we do not need this one
Case 10 : If S <> "" Then Exit Do ' if we have received something
Case Else
S = S + Chr(b) ' build string
End Select
Loop
End Sub


'flush input buffer
Sub Flushbuf()
Waitms 100 'give some time to get data if it is there
Do
B = Inkey() ' flush buffer
Loop Until B = 0
End Sub
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top