• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need help with Sim908 GPS code

Status
Not open for further replies.

mastero

Member
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:eek:vererror: 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
 

ericgibbs

Well-Known Member
Most Helpful Member
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
hi,
Ref our Chat,
1234.123456,,, say d(1)='1' and d(2)='2' are in the array [also d(5)='.' ;;save as is.

Assign LONG WORD as say LW1 [ you will need the Oshonsoft 32bit Maths Option for this LONG]

For the part '34123456'
LW1 = d(3)*10,000,000 + d(4) *1,000,000 .... thru +d(10)

Divided LW1/60 to give 568724 [ the decimal part will be lost]
NOTE: the dividend will be Binary 8AD94h

Load this number into the COUNT2 = 08h, COUNT1= ADh, COUNT0= 94h
and then CALL the 24bin2ASC1 subr.

On Exit from the subr, these buffers will contain the ASCII value
DIGIT0 EQU 0X30 ; LSD DIGITAL CONVERSION
DIGIT1 EQU 0X31
DIGIT2 EQU 0X32
DIGIT3 EQU 0X33
DIGIT4 EQU 0X34
DIGIT5 EQU 0X35
DIGIT6 EQU 0X36
DIGIT7 EQU 0X37 ; MSD DIGITAL CONVERSION

Transmit via Serial d(1),d(2),d(5), DIGIT7 thru DIGIT0

This should be 12.568724
 

mastero

Member
Hello

I got the 32bit Maths option, Floating point done.

i am lost with this part

NOTE: the dividend will be Binary 8AD94h

Load this number into the COUNT2 = 08h, COUNT1= ADh, COUNT0= 94h
and then CALL the 24bin2ASC1 subr.

How to load and call ?

regards
Mastero
 
Status
Not open for further replies.

EE World Online Articles

Loading

 
Top