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 PPortc.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_rxEnable 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 -----------------DoWhile Ok = 0: Wend
Reset Ok
If Pinc.3 = 0 Then 'Pinb.1 grounding also open up
'Switch to display the pageDoLoop Until Pinc.3 = 1
Incr P
If P> 2 Then
P = 1
End If
End If
Select Case P
'- P1Case 1Cls
Cursor Off
Locate 1, 1
Lcd Ns: Lcd "": Lcd Nss' first line to display latitude
Locate 1, 16
Lcd Dw 'location markEws = Ews + "" + KmLocate 2, 1 'second line shows the longitudeLcd Ew: Lcd Ews' and speed of'- P2Case 2Cls
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 DaEnd Select
LoopEnd'---------------------- Serial port interrupt reception subroutine ---------------------- ------Uart_rx:
If Run <> 0 Then
Run = Udr Xor 36If Run = 0 Then
Cntr = 0
Nss = ""Ews = ""Km = ""Ns = ""Ew = ""Dw = ""'2Hh = ""Mm = ""Ss = ""End If
ElseSelect Case Cntr
Case 0 To 4
Tudr = Lookup (cntr, Rmc) 'to determine whether the received characters include "GPRMC"Run = Udr Xor TudrCase 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 13Dw = Dw + Chr (udr) 'whether the location markCase 15 To 22
Nss = Nss + Chr (udr) 'latitudeCase 24Ns = Ns + Chr (udr) 'North latitude flagCase 26 To 34
Ews = Ews + Chr (udr) 'longitudeCase 36Ew = Ew + Chr (udr) 'stuff longitude flagCase 38 To 42
Km = Km + Chr (udr) 'speed, unit section, a = 1852M / H, is not converted into kilometersCase 50Set Ok: Run = 1Case Else
Tudr = Udr
End Select
Incr Cntr
End If
Return'GPS statement, the head of ASCII codeGga:
Data 71, 80, 71, 71, 65 'GPGGAVtg:
Data 71, 80, 86, 84, 71 'GPVTGRmc:
Data 71, 80, 82, 77, 67 'GPRMC
No comments:
Post a Comment