This article help you to interface GPS receiver with the AVR microcontroller. The GPS data's are displayed over an 16x2 LCD display. The program is written in Bascom Basic.
Program
'Project: M8 + GPS Module Decoder Test 'Results: M8 successful operation of a small board, display latitude and longitude and time 'Compiler version: bascom-avr 1.11.7.8 'avrprojects.info '-------- Compiler directives statement --------------------------- $ regfile = "M8def.dat" $ crystal = 3686400
$ baud = 4800 'by the GPS module output baud rate '------------- LCD connection, key definitions ------------------------------- --------- Config Lcdpin = Pin, Db4 = Portd.4, Db5 = Portd.5, Db6 = Portd.6, Db7 = Portd.7, E = Portd.3, Rs = Portd.2
Config Lcd = 16 * 2
Config Pinc.3 = Input 'defined PortB.1 as input control terminal P Portc.3 = 1'Portc .1 pull-up resistor and effective for the "1" '------------ Variables and constants are defined in --------------------------------- ------ Dim Ews As String * 16, Nss As String * 11, Km As String * 5 'definition of longitude, latitude, speed,
Dim Hh As String * 2, Mm As String * 2, Ss As String * 2 'definition of hours, minutes, seconds
Dim Ns As String * 1, Ew As String * 1, Dw As String * 1 'definition of latitude north and south signs, things longitude signs, whether the location
Dim Przecinek As Byte, P As Byte
Dim Run As Byte, Gprmc As Byte, Cntr As Byte, Tudr As Byte, Ok As Bit
Run = 1: Reset Ok
P = 1
'-------------- Defined and open the serial port interrupt subroutine interrupt --------------------------- -------------- On Urxc Uart_rx Enable Urxc
Enable Interrupts
Initial'--------------- program interface ------------------------------ -------------- Cls
Cursor Off
Locate 1, 4
Lcd "GPS Viewer" Lowerline
Lcd "avrprojects.info" Wait 1
'----------------- The main program display interface ----------------- Do While Ok = 0: Wend
Reset Ok
If Pinc.3 = 0 Then 'Pinb.1 grounding also open up
'Switch to display the page Do Loop Until Pinc.3 = 1
Incr P
If P> 2 Then
P = 1
End If
End If
Select Case P
'- P1 Case 1 Cls
Cursor Off
Locate 1, 1
Lcd Ns: Lcd "": Lcd Nss' first line to display latitude
Locate 1, 16
Lcd Dw 'location mark Ews = Ews + "" + Km Locate 2, 1 'second line shows the longitude Lcd Ew: Lcd Ews' and speed of '- P2 Case 2 Cls
Cursor Off
Locate 1, 1
Lcd "UTC": Lcd Hh: Lcd ":": Lcd Mm: Lcd ":": Lcd Ss' first line of the display UTC time
'Locate 2, 1 'Lcd "20": Lcd Ye: Lcd "-": Lcd Mo: Lcd "-": Lcd Da' second line shows the date, but there are problems 'Lcd Da End Select
Loop End '---------------------- Serial port interrupt reception subroutine ---------------------- ------ Uart_rx:
If Run <> 0 Then
Run = Udr Xor 36 If Run = 0 Then
Cntr = 0
Nss = "" Ews = "" Km = "" Ns = "" Ew = "" Dw = "" '2 Hh = "" Mm = "" Ss = "" End If
Else Select Case Cntr
Case 0 To 4
Tudr = Lookup (cntr, Rmc) 'to determine whether the received characters include "GPRMC" Run = Udr Xor Tudr Case 6 To 7
Hh = Hh + Chr (udr) 'UTC Time: "time" Case 8 To 9
Mm = Mm + Chr (udr) 'UTC Time: "Separation" Case 10 To 11
Ss = Ss + Chr (udr) 'UTC Time: "seconds" Case 13 Dw = Dw + Chr (udr) 'whether the location mark Case 15 To 22
Nss = Nss + Chr (udr) 'latitude Case 24 Ns = Ns + Chr (udr) 'North latitude flag Case 26 To 34
Ews = Ews + Chr (udr) 'longitude Case 36 Ew = Ew + Chr (udr) 'stuff longitude flag Case 38 To 42
Km = Km + Chr (udr) 'speed, unit section, a = 1852M / H, is not converted into kilometers Case 50 Set Ok: Run = 1 Case Else
Tudr = Udr
End Select
Incr Cntr
End If
Return 'GPS statement, the head of ASCII code Gga:
Data 71, 80, 71, 71, 65 'GPGGA Vtg:
Data 71, 80, 86, 84, 71 'GPVTG Rmc:
Data 71, 80, 82, 77, 67 'GPRMC

0 comments:
Post a Comment