'18LF4520 8MHzx4 HC12 to 18LF2520 TX 200418 1100 Define CONFIG1L = 0x00 Define CONFIG1H = 0x08 'INT OSC Define CONFIG2L = 0x1e Define CONFIG2H = 0x00 Define CONFIG3L = 0x00 Define CONFIG3H = 0x80 'Set for HVP Define CONFIG4L = 0x80 Define CONFIG4H = 0x00 Define CONFIG5L = 0x0f Define CONFIG5H = 0xc0 Define CONFIG6L = 0x0f Define CONFIG6H = 0xe0 Define CONFIG7L = 0x0f Define CONFIG7H = 0x40 'Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC Define CLOCK_FREQUENCY = 8 Define SINGLE_DECIMAL_PLACES = 2 Define STRING_MAX_LENGTH = 40 AllDigital 'SET PIN IN/OUT TRISA = %00000001 TRISB = %00000000 TRISC = %10010000 '7=RX=1 4=SDI=1 1=RST=0 TRISD = %00000000 '7=compss c/s=0 5=altmtr c/s=0 4=lcd5110 c/s=0 TRISE = %00000001 '1=Button 'SET BITS ON/OFF PORTA = %00000000 'ON/OFF PORTB = %00000000 PORTC = %00000000 PORTD = %01110000 'ALL C/S HIGH PORTE = %00000000 'POSS MCLR RE3 ADCON0 = 0x03 'AN0-1-2-3 Can be used as Analogue inputs. ADCON1 = 0x0e ADCON2 = %10100100 PIR1 = 0 PIR2 = 0 PIE1 = 0 PIE2 = 0 PIE1.RCIE = 1 'rxd Intr , used for GPS serial input work IPR1 = 0 IPR2 = 0 RCON.IPEN = 1 'This MUST be included when using Interrupts OSCCON = %01110010 'internal 8Mhz clock OSCTUNE.PLLEN = 1 '*4 PLL enabled so Fosc = 32MHZ WaitMs 10 Symbol yled = PORTA.4 'yled Symbol rled = PORTA.5 'rled Symbol button = PORTE.0 rled = 1 WaitMs 500 rled = 0 yled = 1 WaitMs 500 yled = 0 Dim msg1 As String 'any msg data will be passed via this string 'GPS Dim str1(80) As Byte 'GPGGA STR1 ARRAY Dim strchr As String 'GPGGA msg Dim csv As Byte 'COMMA POSITION in GPS msg Dim sinlat As Single Dim sinlong As Single Dim strtim As String Dim strlat As String Dim strlong As String Dim char As Byte Dim rxi As Byte Dim txi As Byte Disable High Disable Low msg1 = "" Hseropen 9600 Hserout "Ready!", CrLf 'SET UP HC12 'PRESS BUTTON PORTE.0 = 0 'SET HC-12 COMMAND ON Hserout "AT+C001", CrLf PORTE.0 = 1 'SET HC-12 RUN OFF main: If button = 1 Then 'BUTTON NOT PRESSED rled = 0 yled = 1 Hserout "$0", CrLf Endif WaitMs 500 If button = 0 Then 'BUTTON PRESSED rled = 1 yled = 0 Hserout "$1", CrLf Endif WaitMs 500 Goto main End 'Await NEO GPS RXD (PIN1) get_neo: ''$GPGGA,123459.00,5001.00000,N,00059.00000,W,1,04,1.80,1.2,M,47.7,M,,*7F? rxi = 0 If RCSTA.OERR = 1 Then 'RCSTA BIT1-if over run error then flush RXD buffer RCSTA.CREN = 0 RCSTA.CREN = 1 char = RCREG PIR1.RCIF = 0 Endif sync1: 'wait for a $ start of string If PIR1.RCIF = 0 Then Goto sync1 char = RCREG If char <> 0x24 Then Goto sync1 '$' str1(1) = char 'STR1 ARRAY rxi = 2 get_msg: 'read and save GPGGA msg If PIR1.RCIF = 0 Then Goto get_msg char = RCREG str1(rxi) = char 'STR1 ARRAY rxi = rxi + 1 If rxi > 79 Then Goto get_neo 'msg bfr over run If char = 0x0a Or char = 0x3f Then Goto msg_end 'tests for either LF or ? Goto get_msg If rxi < 60 Then 'invalid msg msg1 = "" Goto get_neo Endif msg_end: If str1(5) = 0x47 Then 'G' csv = 0 For txi = 1 To 73 char = str1(txi) strchr = Chr(char) If strchr <> "," Then msg1 = msg1 + strchr Else csv = csv + 1 Gosub get_val Endif Next txi Else msg1 = "" Goto get_neo Endif Return 'This subr extracts the main values from the GPS string, into named value messages 'also converts the string to a named numeric value, for maths 'NOTE: hserouts for demo test only get_val: Select Case csv 'COMMA POSITION VALUES Case 1 Case 2 strtim = LeftStr(msg1, 2) + ":" + MidStr(msg1, 3, 2) + ":" + MidStr(msg1, 5, 2) Case 3 strlat = LeftStr(msg1, 10) sinlat = StrValS(strlat) Case 5 strlong = RightStr(msg1, 11) sinlong = StrValS(strlong) Case 12 Case Else EndSelect msg1 = "" Return