It is currently 23 Jan 2018 17:46

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: 04 May 2012 11:01 
Offline

Joined: 14 Aug 2006 01:32
Posts: 66
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 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
'more uart specific initialization
ASM: bcf status,rp0
ASM: bsf rcsta,spen
ASM: bcf rcsta,rx9
ASM: bcf rcsta,sren
ASM: bsf rcsta,cren
ASM: bcf rcsta,ferr
ASM: bcf rcsta,rx9d
'clear peripheral flags
ASM: clrf pir1
'clear uart receiver
ASM: movf RCREG,W
ASM: movf RCREG,W
ASM: movf RCREG,W
'initiating txif flag by sending anything
ASM: movlw 0
ASM: movwf txreg
'disable interrupts
ASM: clrf pie1

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 N And Then For +
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:
'*******************************************
'serial input routine with error handling.
'returns 0 in variable "serdata" if no data read
ASM:ser_in: btfsc rcsta,oerr
ASM: goto overerror
ASM: btfsc rcsta,ferr
ASM: goto frameerror
ASM: clrw 'return 0 if no data
ASM: btfss pir1,rcif
ASM: goto end_call
ASM:uart_gotit: bcf intcon,gie 'clear gie before read
ASM: btfsc intcon,gie
ASM: goto uart_gotit
ASM: movf rcreg,w
ASM: bsf intcon,gie
ASM: goto end_call
ASM:overerror: bcf intcon,gie 'turn gie off
ASM: btfsc INTCON,GIE
ASM: goto overerror
ASM: bcf rcsta,cren
ASM: movf rcreg,w 'flush fifo
ASM: movf rcreg,w
ASM: movf rcreg,w
ASM: bsf rcsta,cren 'turn cren on, clear oerr flag
ASM: bsf intcon,gie
ASM: goto ser_in
ASM:frameerror: bcf intcon,gie
ASM: btfsc intcon,gie
ASM: goto frameerror
ASM: movf rcreg,w
ASM: bsf intcon,gie
ASM: goto ser_in
ASM:end_call: movwf serdata
Return

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

Regards
Mastero


Top
 Profile  
 
PostPosted: 07 May 2012 09:44 
Offline
mikroElektronika team
User avatar

Joined: 25 Jan 2008 09:56
Posts: 9495
Hi,

Well, this seems like a custom project which exceeds Support scope, but I guess some of our users may help you.

Regards,
Filip.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: