Hello.
I'm trying to read time from the GPS module "Neo-6"
I asked AI to generate the code and here it is (with hardware config and DEFINEs by me):
It does not work, but I added this: serout2 GPS_TX, 84, [gps_char,","]Code:;----[16F886 Hardware Configuration]-------------------------------------------- #CONFIG cfg1 = _INTRC_OSC_NOCLKOUT ; INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN cfg1&= _WDT_ON ; WDT enabled cfg1&= _PWRTE_OFF ; PWRT disabled cfg1&= _MCLRE_OFF ; RE3/MCLR pin function is digital input, MCLR internally tied to VDD cfg1&= _CP_OFF ; Program memory code protection is disabled cfg1&= _CPD_OFF ; Data memory code protection is disabled cfg1&= _BOR_OFF ; BOR disabled cfg1&= _IESO_ON ; Internal/External Switchover mode is enabled cfg1&= _FCMEN_ON ; Fail-Safe Clock Monitor is enabled cfg1&= _LVP_OFF ; RB3 pin has digital I/O, HV on MCLR must be used for programming cfg1&= _DEBUG_OFF ; In-Circuit Debugger disabled, RB6/ICSPCLK and RB7/ICSPDAT are general purpose I/O pins __CONFIG _CONFIG1, cfg1 cfg2 = _BOR40V ; Brown-out Reset set to 4.0V cfg2&= _WRT_OFF ; Write protection off __CONFIG _CONFIG2, cfg2 #ENDCONFIG TRISA=%00000001 'SET A TO OUTPUT 1=input TRISC=%00001000 'set C3 for gps TRISB=%00011000 'set PortB to output ANSELH=%00000000 ' ADC OFF B ANSEL=%000000000 'configure PortA as digital except first 2 ADCON1=%10000000 'adc justify OSCCON=%01110101 'SET FREQUENCY TO 8MHZ WPUB=%00000000 'turn off Pullups CM1CON0=0 'DISABLE COMPARATORS CM2CON0=0 'SAME HERE 'CCP1CON=%01000000 ' configure pwm 'PSTRCON=%00010110 'disable C pwm DEFINE OSC 8 DEFINE ADC_BITS 12 DEFINE ADC_CLOCK 5 DEFINE ADC_SAMPLEUS 5 'aska: serout2 portc.5,84,[" test-"," ",10,13] 'pause 100 'goto aska gps_data VAR BYTE[80] ' Buffer to store GPS data gps_char VAR BYTE ' Character received from GPS time_data VAR BYTE[6] ' Array to store the extracted time i VAR BYTE ' Loop variable start_found VAR BIT ' Flag to indicate start of time data ' Define the serial pins GPS_RX var PORTC.2 ' RX pin for GPS (Adjust according to your setup) GPS_TX var PORTC.5 ' TX pin for GPS (Adjust according to your setup) ' Initialize variables start_found = 0 i = 0 main: ' Wait for data from GPS SERIN2 GPS_RX, 84, [gps_char] ' 9600 baud rate with N, 8, 1 settings (84 represents the baud rate) serout2 GPS_TX, 84, [gps_char,","] 'also added by me for debugging ' Store data in buffer gps_data[i] = gps_char i = i + 1 ' Check if we have a complete line of data IF gps_char = 10 THEN ' Look for the $GPRMC sentence IF (gps_data[1] = "G") AND (gps_data[2] = "P") AND (gps_data[3] = "R") AND (gps_data[4] = "M") AND (gps_data[5] = "C") THEN ' Extract time from the sentence start_found = 1 FOR i = 7 TO 12 time_data[i-7] = gps_data[i] NEXT i ENDIF ' Reset buffer i = 0 ENDIF 'SEROUT2 GPS_TX, 84, ["Waiting...",10,13] 'added by myself for testing purposes ' Display time data IF start_found = 1 THEN SEROUT2 GPS_TX, 84, ["Time: ", time_data[0], time_data[1], ":", time_data[2], time_data[3], ":", time_data[4], time_data[5], 13, 10] start_found = 0 ENDIF GOTO main
and it outputs series of chars and digits, and these digits do change, here's sample
,G,M,1,1,.,4,,,,,,,,,5,,,,*,
,N,A,8,3,9,,,,,4,
,$,G,,,0,2,7,,,,,0,,,,,,,6,
,P,A,,,,,,,,,
,P,A,,,,,,,,,,G,M,1,9,.,4,,,,,,,,,5,,,,*,
,N,A,8,4,9,,,,,4,
,$,G,,,2,0,7,,,,,0,,,,,,,6,
So what I'm doing wrong?
I tried to set GPS port speed to 4800 - it outputs garbage then.




Bookmarks