A program for collecting and writing GPS Serial Port Data

Source: Internet
Author: User
GPS serial port data receptionProgramInstance

Abstract: At present, the GPS (global positioning system) Positioning Application market has become increasingly mature and is entering a period of rapid development of applications. This paper takes an evermore company's GM-X205GPS receiving module as an example, introduces its data format, as well as the application of the program of data receiving through the RS232 serial port of pic16f874 microcontroller.

1. Introduction to GPS applications In recent years, the GPS system has been widely used in many fields, such as land ing, marine fishery, vehicle positioning and monitoring, construction, and agriculture. Since the introduction of GPS Positioning Technology in China in 1990s, after more than a decade of market cultivation, GPS positioning has entered the best time for development, over the next decade, GPS-based applications will change our way of life and work. Currently, most GPS receiving modules on the market use RS232 serial port to transmit data with MCU. The data includes basic information such as longitude, latitude, altitude, time, and satellite usage. Based on the basic data, developers can process the data to complete the entire positioning system software. 2. GM-X205 module data format Before Programming Data acceptance, we will first introduce the data format of this module. It supports the NMEA-0183 output format. The information is as follows: Global Positioning System Fix Data)
GSV navigation satellite data (GPS satellites in view)
Specific simplified RMC Navigation Satellite Data)
Vtg direction and speed (Course over ground and ground speed)
Because Article Due to the length issue, I will only receive GGA data here. The format is as follows:
$ Gpgga, hhmmss, dddmm. mmmm, A, dddmm. mmmm, A, X, XX, X. x, X. x, M, M, X. x, xxxx * cs
Example: $ gpgga, 033744,244 6.5241, N, 12100.1536, E, 0.8, 133.4, M, and * 1f are described in the table:

Region Name Example Unit Description
1 Information ID $ Gpgga   GGA protocol started
2 UTC time 033744   Hhmmss
3 Latitude 2446.5241   Dddmm. Mmmm
4 South/Northern Hemisphere indication N   N = North; S = South
5 Longitude 12100.1536   Dddmm. Mmmm
6 Eastern/Western Hemisphere instructions E   E = east; W = West
7 Positioning instructions 1   0 = undetermined 1 = positioning SPS Mode 2 = positioning DGPS, SPS Mode
8 Satellite Number 10   00-12
9 Hdop 0.8 Meters  
10 Altitude 133.4 Meters  
11 Altitude Unit M Meters  
12 WGS84 level Division      
13 WGS-84 level division unit      
14 Cumulative GPS data Differentiation     Unavailable in this module
15 Reference workstation ID     Unavailable in this module
16 Check bit * 1f    
In the above example, we can read the location information: 24 degrees north latitude 46.5241 points, 121 degrees west longitude 00.1536 points
GMT: 03:37:44
3. Data receiving program of pic16f874
After processing the received data in the system, it is displayed on the graphic LCD screen. Only some programs that receive data are provided here, only the longitude and time information is received, and a conversion function for converting Greenwich Mean Time to Beijing time is provided. Other data receiving programs are similar.
; **************************************** ******************
; This is a GPS receiver Program *
; **************************************** ******************
List P = 16f874
Include p16f874. inc
********************
Temp1 equ 0x27
W_temp equ 0x54
Status_temp equ 0x55
Long1 equ 0x40; long1 --- 10-bit long10 longitude data
Long2 equ 0x41
Long3 equ 0x42
Long4 equ 0x43
Long5 equ 0x44
Long6 equ 0x45
Long7 equ 0x46
Long8 equ 0x47
Long9 equ 0x48
Long10 equ 0x49
T1 equ 0x58; 6-bit data for T1---T6 time
T2 equ 0x59
T3 equ 0x60
T4 equ 0x61
T5 equ 0x62
T6 equ 0x63
; **************************************** ****************
Org 00 h
NOP
NOP
Goto main
Org 04 H; set to start data acceptance by mid-range health
NOP
NOP
Goto interrupt
* Determines whether the header file is '$ gpgga '**********
Idmessage
BCF status, Rp0
Break0
Call pand
Movwf temp1
Movlw '$'; detect $
Subwf temp1, 0
Btfss status, Z
Goto break0
Call pand
Movwf temp1
Movlw 'G'; detect g
Subwf temp1, 0
Btfss status, Z
Goto break0
Call pand
Movwf temp1
Movlw 'P'; detect P
Subwf temp1, 0
Btfss status, Z
Goto break0
Call pand
Movwf temp1
Movlw 'G'; detect g
Subwf temp1, 0
Btfss status, Z
Goto break0
Call pand
Movwf temp1
Movlw 'G'; detect g
Subwf temp1, 0
Btfss status, Z
Goto break0
Call pand
Movwf temp1
Movlw 'a'; detect
Subwf temp1, 0
Btfss status, Z
Goto break0
Call pand; skip the comma
Return
******************
Receive
Call pand; Start time for receiving data
Movwf T1
Call pand
Movwf T2
Call pand
Movwf T3
Call pand
Movwf T4
Call pand
Movwf T5
Call pand
Movwf T6; time data received successfully
Call pand; skip the comma
Call pand; skip the 10-bit latitude data --- start
Call pand
Call pand
Call pand
Call pand
Call pand
Call pand
Call pand
Call pand
Call pand; skip the 10-bit latitude data --- end
Call pand; skip the comma
Call pand; skip the South/North Latitude judgment BIT data
Call pand; skip the comma
Call pand; start from receiving the longitude Signal
Movwf long1
Call pand
Movwf long2
Call pand
Movwf long3
Call pand
Movwf long4
Call pand
Movwf long5
Call pand
Movwf long6
Call pand
Movwf long7
Call pand
Movwf long8
Call pand
Movwf long9
Call pand
Movwf long10; end with the longitude Signal
Return
*****************
Pand
BCF status, Rp0
CC btfss pir1, 5
Goto CC
Movf rcreg, 0
Return
; ********************* ******
Interrupt
BCF intcon, 7; Set gie = 0 shield all middle ends
BCF status, Rp0
BCF rcsta, 1; clear overflow error bit
BSF status, Rp0
BCF txsta, 2; brgh = 0 Low Speed
BCF txsta, 4; Set asynchronous mode
Movlw 0x0c
Movwf spbrg; set the baud rate to 4800
BCF status, Rp0
Movlw B '10010000'
Movwf rcsta; settings related to serial port reception
BSF status, Rp0
BSF option_reg, 6; rb0/INT pin rising edge interrupt
Movwf w_temp
Swapl status, W
BCF status, Rp0
Movwf status_temp
BCF status, Rp0
Call idmessage
Call receive
BCF status, Rp0
Clrf rcsta; clear serial port settings
Call convert; call the time Conversion Function
Out BCF status, Rp0; jump out of the interrupt part and recover the Register
Swapl status_temp, W
Movwf status
Swapl w_temp, F
Swapl w_temp, W
BSF intcon, 7; Set gie = 1 allow all middle ends
NOP
Retfie
******************
Convert
Movlw A '0'
Subwf T2, 1
Subwf T1, 1
Movlw D '10'
Movwf temp1
Loop1 movf temp1, 0
Movf temp1, 1
Btfss status, Z
Goto add10
Movlw D '8'
Addwf T2, 1
Movlw D '24'
Subwf T2, 1
Btfsc status, c
Goto con1
Addwf T2, 1
Goto con1
Con1 movlw D '20'
Movwf temp1
Subwf T2, 0
Btfss status, c
Goto con2
Movwf T2
Movlw 0x02
Movwf T1
Goto halt1
Con2 movlw D '10'
Movwf temp1
Subwf T2, 0
Btfss status, c
Goto con3
Movwf T2
Movlw 0x01
Movwf T1
Goto halt1
Con3 movlw 0x00
Movwf T1
Halt1 movlw A '0'
Addwf T1, 1
Addwf T2, 1
Return
Add10 movf T1, 0
Addwf T2, 1
Decf temp1, 1
Goto loop1
Return
; * ***************** Main ********************* **
Main
BCF status, Rp0
Movlw B '10010000'
Movwf intcon; Enable interrupt
Loop NOP
BCF status, Rp0
Goto Loop
Goto main
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.