PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > English forum on PICs

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

English forum on PICs Forum for foreigners -only English in this forum - Do not need to register or login

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 05-05-2012, 02:30 AM   #1
mastero
Nhập môn đệ tử
 
Tham gia ngày: May 2012
Bài gửi: 1
:
Need help with Sim908 GPS code

Hello friends,

I am building a SIM908 GPS module with SMS control.

The problem i am facing is i need to convert deg min.min latidude to deg decimal.

I have the formula but dont know how to put it in the code

This is what the GPS module sends 4,1234.123456,N,7890.123456,E,123123.000,A,A

I can receive it and resend it as it is with the below code but i need some maths to be done before sending.

eg: 1234.123456 div by 100 = 12.34123456

Once i have this i need to divide the numbers on the right of the decimal by 60

eg: 34123456 div by 60 = 568724.266666

now i want this number to be sent out 12.568724

How can i do it below is my code.

************************************************** ***********

'Gps Read And Write SIM908
'**********************************
TRISA = %00000000
TRISB = %00000000
TRISC = %11000000

CMCON = %00000111 'turn off comparators 16F876A
ADCON1 = %00000110 'turn off analog inputs 16F876A

'Declare variables
Dim i As Word
Dim j As Byte
Dim k As Byte
Dim x As Byte
Dim y As Byte
Dim n As Byte
Dim a As Byte
Dim h As Byte
Dim t As Byte

Dim temp As Byte
Dim data(64) As Byte 'buffer for serial data
Dim serdata As Byte
Dim startmark As Bit
Dim gpsreceived As Bit

'************************************************* ****

'Definition of OUTPUTS ports

Symbol led = PORTC.4 'status LED
led = 0
WaitMs 3000

'**** MAIN PROGRAM ****
main:
led = 1

Hseropen 9600 'initialize serial hw port - port used for modem
Gosub wait
Hserout "AT+CGPSPWR=1", CrLf 'start gps
Gosub wait
Hserout "AT+CGPSRST=1", CrLf 'reset gps
Gosub wait

'********** Main loop ******************
menu:
WaitMs 500 'waiting time
Gosub get_location
Gosub send_location
Toggle led
Goto menu
End


get_location:
'***********************************
h = 0
i = 0
k = 0
startmark = False
gpsreceived = False

Hserout "AT+CGPSINF=4", CrLf 'CODE TO RECEIVE GPS INFO

loop1:
Gosub hserget2
If serdata > 0 Then
If serdata = "4" Then
gpsreceived = True
Endif
If serdata = 0x2c And gpsreceived = True Then
startmark = True
Endif
temp = LookUp(0x2c, 0x4e), k 'search for , And Then For N
If serdata = temp Then
k = k + 1
If k = 2 Then
Return
Endif
Endif
If startmark = True Then
data(h) = serdata 'store data in buffer
If h = 64 Then 'handle buffer overflow
h = 0
Else
h = h + 1
Endif
Endif
Endif
i = i + 1
If i = 65000 Then Return 'timeout
Goto loop1


send_location:
'***********************************
If h > 0 Then
h = h - 1 'number of digits
For k = 1 To h Step 1
temp = data(k)
If temp = 0x2c Then
Hserout 0x1a, CrLf
For k = 0 To 40 Step 1
data(k) = 0x00
Next k
Return
Endif
Hserout temp
Next k

Endif
Return

wait:
'*******************************************
WaitMs 350
Return

hserget2:

hserget serdata

Return

************************************************** ***********
Any help will be nice.

Matero
mastero vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 07:33 AM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam