'18LF2520 INT4MHz TIMESIN SERVOOUT 300518 0800 Define CONFIG1H = 0x08 Define CONFIG2L = 0x1e Define CONFIG2H = 0x00 Define CONFIG3L = 0x00 Define CONFIG3H = 0x80 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 Define CLOCK_FREQUENCY = 4 Define SINGLE_DECIMAL_PLACES = 2 Define STRING_MAX_LENGTH = 40 'Needs setting to fit the message for transmit msg1 = "" Hseropen 9600 Hserout "Ready!", CrLf 'GET MESSAGE Dim msg1 As String 'any msg data will be passed via this string Dim ascval As String Dim y As Byte Dim row As Byte 'lcd row pointer Dim xp As Byte 'sml font horiz Dim yp As Byte 'vert lcd location Dim str1(34) As Byte 'MESSAGE STR1 ARRAY Dim strchr As String 'msg Dim csv As Byte 'COMMA POSITION VALUES msg Dim char As Byte Dim rxi As Byte Dim txi As Byte Dim binval As Single Dim tim0 As Word tim0 = 1500 Dim strtim0 As String strtim0 = #tim0 Dim tim1 As Word tim1 = 1500 Dim strtim1 As String strtim1 = #tim1 Dim tim2 As Word tim2 = 1500 Dim strtim2 As String strtim2 = #tim2 Dim tim3 As Word tim3 = 1500 Dim strtim3 As String strtim3 = #tim3 Dim tim4 As Word tim4 = 1500 Dim strtim4 As String strtim4 = #tim4 Dim tim5 As Word tim5 = 1500 Dim strtim5 As String strtim5 = #tim5 Symbol yled = RC1 Symbol rled = RC2 yled = 0 'YLED OFF rled = 0 'RLED OFF AllDigital 'SET PIN IN/OUT TRISA = %00100000 TRISB = %00000000 TRISC = %10010000 'SET BITS ON/OFF PORTA = %00000000 'ON/OFF PORTB = %00000000 PORTC = %00000000 PORTE = %00000000 'POSS MCLR RE3 INTCON.GIE = 1 'Global Interrupt Enable bit INTCON.PEIE = 1 'Peripheral Interrupt Enable bit INTCON.TMR0IE = 1 'TMR0 Overflow Interrupt Enable bit INTCON.INT0IE = 0 'INT0IE: INT0 External Interrupt Enable bit'' INTCON.RBIE = 0 'RBIE: RB Port Change Interrupt Enable bit 'INTCON.TMR0IF = 1 'TMR0IF: TMR0 Overflow Interrupt Flag bit 'INTCON.INT0IF = 0 'INT0IF: INT0 External Interrupt Flag bit INTCON.RBIF = 0 'RBIF: RB Port Change Interrupt Flag bit(0 = PORTB off) T0CON.TMR0ON = 1 'Bit7 = enables timer0 T0CON.T08BIT = 1 'Bit6 = timer0 is configured As an 8-Bit timer/TIME T0CON.T0CS = 0 'Bit5 = Internal clock (FOSC/4) T0CON.T0SE = 0 'Bit4 = 0 = Increment on low-to-high transition on T0CKI pin T0CON.PSA = 0 'Bit3 = Timer0 prescaler is assigned.from prescaler output T0CON.T0PS2 = 1 'Bit2 = 1:128 Prescale value T0CON.T0PS1 = 1 'Bit1 = 1:128 Prescale value T0CON.T0PS0 = 0 'Bit0 = 1:128 Prescale value Enable High 'TIMER 'TMR0H = %11111111 'TMR0L = %00000000 TMR0 = %01100011 '99 or 0x63 loop: Toggle rled 'RC1 WaitMs 1000 INTCON.TMR0IE = 1 Gosub get_mess Goto loop End On High Interrupt Save System RB0 = 1 WaitUs strtim0 RB0 = 0 RB1 = 1 WaitUs strtim1 RB1 = 0 RB2 = 1 WaitUs strtim2 RB2 = 0 RB3 = 1 WaitUs strtim3 RB3 = 0 RB4 = 1 WaitUs strtim4 RB4 = 0 RB5 = 1 WaitUs strtim5 RB5 = 0 INTCON.TMR0IF = 0 'Switches at TMR0 rollover Toggle yled 'RC2 'TMR0H = %11111111 'Watch HIGH BYTE not TMR0H>>>>>>>>>>>>>>>>> 'TMR0L = %00000000 TMR0 = %01100011 '99 or 0x63 Resume 'RESETS GIEH GIEL 'Await RXD MESSAGE get_mess: 'PASTE INTO UART: $,1100,1200,1300,1400,1500,1600,? 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 > 40 Then Goto get_mess 'msg bfr over run If char = 0x0a Or char = 0x3f Then Goto msg_end 'tests for either LF or ? Goto get_msg If rxi < 32 Then 'invalid msg msg1 = "" Goto get_mess Endif msg_end: If str1(1) = 0x24 Then '$' 'If str1(5) = 0x47 Then 'G' csv = 0 For txi = 1 To 33 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_mess Endif msg1 = "TIM0=" + strtim0 '5110 NOT USED YET>>>>>>>>>>>>>>>>>> ''Call wr_msg(0, 0, msg1) msg1 = "TIM1=" + strtim1 '5110 ''Call wr_msg(0, 0, msg1) msg1 = "TIM2=" + strtim2 '5110 ''Call wr_msg(0, 0, msg1) msg1 = "TIM3=" + strtim3 '5110 ''Call wr_msg(0, 0, msg1) msg1 = "TIM4=" + strtim4 '5110 ''Call wr_msg(0, 0, msg1) msg1 = "TIM5=" + strtim5 '5110 ''Call wr_msg(0, 0, msg1) Hserout "T0 ", strtim0, " T1 ", strtim1, " T2 ", strtim2, " T3 ", strtim3, " T4 ", strtim4, " T5 ", strtim5, CrLf 'strtim0 = "" 'strtim1 = "" 'strtim2 = "" 'strtim3 = "" 'strtim4 = "" 'strtim5 = "" msg1 = "" Return 'goto get_mess???????????????????????????? '----------------------------------------------------------------------------------- '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 2 strtim0 = RightStr(msg1, 4) '+ ":" + MidStr(msg1, 3, 2) + ":" + MidStr(msg1, 5, 2) Case 3 strtim1 = RightStr(msg1, 4) Case 4 strtim2 = RightStr(msg1, 4) Case 5 strtim3 = RightStr(msg1, 4) Case 6 strtim4 = RightStr(msg1, 4) Case 7 strtim5 = RightStr(msg1, 4) Case Else EndSelect msg1 = "" Return