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 write a code for reading the whole string from GPS

Status
Not open for further replies.

DrWhoF

Advanced Member level 1
Advanced Member level 1
Joined
May 6, 2005
Messages
402
Helped
24
Reputation
48
Reaction score
11
Trophy points
1,298
Activity points
4,388
Reading GPS

Can someone help me in writing a code (asm for 8051) which will read the whole string from GPS through one serial port and output only Lat-Long information without other characters through another serial port.
Thanks
DrWhoF
 

Re: Reading GPS

What you need to implement and what will be very handy later is serial port interrupt subroutine. If you don't know how to do this check out this code:
https://www.pjrc.com/tech/8051/uartintr.asm
Make sure that it is working correctly. To do this connect your µP ( I assume that you have RS-232 driver such as MAX202, 232 ..) to a PC and start any terminal software. Write a short program that will read a ASCII character, for example "A" (code 41h) and if your microcontroller reads it then it should send back another ASCII character, say, "B" (code 42h).
Once you have this done, come back, and we can go into reading GPS strings..
Regards,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
Re: Reading GPS

Thanks veryt much for your help.
I am trying to figure out what actually should be in the Main Routine. This link has several subroutines, but I couldn't find any code which calls routines such as num_recv , num_xmit and others.
Thanks.
 

Re: Reading GPS

I hope yoy have done all initial steps such as declarations, memory organization for the main code and serial port interrupt, set SP etc. etc.
Next, you will have to call "init_uart_intr" (from the link provided previously).
After all this you can start your Main Loop; here is an example:
Main: NOP

SETB EA ; Enable global interrupt..IE.7
SETB ES ; Ser Port Int..IE.4..
SETB PS ; SerPort Int high priority..
SETB SBuffEmpty

Main_Loop: NOP

Cin_0: CLR ES
MOV A, RxBuffTail
CJNE A, RxBuffHead, Cin_20
JNB SBuffEmpty, Cont_32
CLR SBuffEmpty

Cont_32: SETB ES ; Ser Port Int On..
LJMP Main_Loop

Cin_20: LCALL Cin_2
LCALL Ser_Rout
SETB SBuffEmpty
LJMP Main_Loop

The microcontroller will be spendig here most of its time, interrupted by the serial port when a character arrives.
If RxBuffTail is not equal to RxBuffHead the program will branch to Ser_Rout.

We are not calling "cin" subroutine but "cin2" instead.
In the "cin2" after:
MOV A, @R0
add line:
MOV SerData, A
and also declere SerData as BYTE.

So now the Ser_Rout may look like this:
Ser_Rout:
MOV A, SerData
LCALL Count .. Count puts this byte in the Tx buffer and sets serial interrupt for transmission ..
RET .. ends this short routine ...

Try this and let us know how it goes ..
Regards,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
Re: Reading GPS

The code you suggested seems to be working fine. My circuit echoes characters which are pressed on the keyboard.
Can you help me with GPS reading?
Thanks
DrWhoF
 

Re: Reading GPS

Which NMEA sentence will you be decoding:
$GPGLL, $GPGGA, $GPBWC ... ?
I would suggest the first one, GLL that is:
$GPGLL
Geographic Position, Latitude / Longitude and time.

eg1. $GPGLL,3751.65,S,14507.36,E*77
eg2. $GPGLL,4916.4539,N,12311.1234,W,225444,A

4916.4539,N Latitude 49 deg. 16.45 min. North
12311.1234,W Longitude 123 deg. 11.12 min. West
225444 Fix taken at 22:54:44 UTC
A Data valid

eg3. $GPGLL,5133.8910,N,00042.2555,W*75
1 2 3 4 5

1 5133.8910 Current latitude
2 N North/South
3 00042.2555 Current longitude
4 W East/West
5 *75 checksum

$--GLL,lll.ll,a,yyyyy.yy,a,hhmmss.ss,A llll.ll = Latitude of position

a = N or S
yyyyy.yy = Longitude of position
a = E or W
hhmmss.ss = UTC of position
A = status: A = valid data

So, before you decide which sentence you prefer, define bits for all digits in Latitude and Longitude strings including N/S and E/W.
So you will have something like this:
S1Flags DATA 20h ; Bits for ariving characters..in South string..
S1 BIT S1Flags.0
S2 BIT S1Flags.1
S3 BIT S1Flags.2
S4 BIT S1Flags.3
S5 BIT S1Flags.4
S6 BIT S1Flags.5
S7 BIT S1Flags.6
S8 BIT S1Flags.7

S2Flags DATA 21h ; Bits for ariving characters..in South/East string..
S9 BIT S2Flags.0
E1 BIT S2Flags.1
E2 BIT S2Flags.2
E3 BIT S2Flags.3
E4 BIT S2Flags.4
E5 BIT S2Flags.5
E6 BIT S2Flags.6
E7 BIT S2Flags.7
Also, define bytes for each Lat/Long digit:
South1 DATA 40h ; GPS LatS thousands..
South2 DATA 41h ; GPS LatS hundreds..
South3 DATA 42h ; GPS LatS tens..
South4 DATA 43h ; GPS LatS units..
South5 DATA 44h ; GPS..dec..point..
South6 DATA 45h ; GPS LatS ovtens..
South7 DATA 46h ; GPS LatS ovhundreds..
South8 DATA 47h ; GPS LatS overthousands..
South9 DATA 48h ; GPS LatS overtenthousands..
South0 DATA 49h ; S or N..

East1 DATA 50h ; GPS LongE tthousands..
East2 DATA 51h ; GPS LongE thousands..
East3 DATA 52h ; GPS LongE hundreds..
East4 DATA 53h ; GPS LongE tens..
East5 DATA 54h ; GPS LongE units..
East6 DATA 55h ; GPS..dec..point..
East7 DATA 56h ; GPS LongE ovtens..
East8 DATA 57h ; GPS LongE ovhundreds..
East9 DATA 58h ; GPS LongE overthousands..
East10 DATA 59h ; GPS LongE overtenthousands..
East0 DATA 5Ah ; E or W..

Other thing is that if you are going to use 8051 you may run out of available RAM as we need some bytes for TxBuffer and RxBuffer too.
My suggestion is that you use 8052 (or its version with EPROM, Flash ...)
Then you can shift Tx and Rx buffers to the second section of RAM, which is addressable by R0 and R1, and what is already implemented in the serial port interrupt routine.
I suggest thet we put these buffers here:
RxBuff DATA 0B0h
TxBuff DATA 0E0h

So make declarations, definitions etc. etc. and select the NMEA sentence ..

Regards,
IanP
 
Re: Reading GPS

Thanks for your help.
$GPGLL will be perfect.
In your example Latitude and logitude use 4 digits after the decimal point. What if my GPS receiver can produce only 3?
Thanks
DrWhoF
 

Re: Reading GPS

This program senses number of digits between commas and it really doesn't matter whether your GPS receiver sends 2, 3 or 4 digits after decimal pont ..
Post or PM your e-mail address so I can send it (the code) to you, as I don't think it is practical to discuss here another ≈400 lines of code ..
Regards,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
    V

    Points: 2
    Helpful Answer Positive Rating
Re: Reading GPS

Thanks for your help.
I will PM my e-mail address to both of you.
Please send C-code and ASM.
Thanks.
DrWhoF
 

Re: Reading GPS

2 files: gps.c and gps1.c, there are source to 8051 read from serial a gps protocoll nmea, used SDCC compiler
 
Re: Reading GPS

could u please send me the gps.c and gps1.c files
 

Re: Reading GPS

hi all,
i wanna update a bus clock with gps time signal. but i dont know which module can be usefull for me. any suggestion?
there are a lot of gps module at globalsources web site but no datasheet published:cry: well, can all modules get the time signal via satellite or this modules can be used only navigation?
please advise...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top