#include <pic.h>
#include "globals.h"
#include "serial.h"
#undef GPSRECV_DEBUG
void gps_gprmc() {
unsigned char i, devnull;
for (;;) {
do {
getch();
} while(RCREG != '$');
for (i = 0; i < 5; i++) {
getch();
devnull = RCREG; // this *must* be done, otherwise RCIF does not get cleared, *overflow*
}
if (RCREG == 'C') {
getch();
devnull = RCREG;
for (i = 0; i < 60; i++) {
getch();
TXREG = RCREG;
}
break;
}
}
}
void gps_init() {
SPEN = 1; // set serial port enable : SPEN RCSTA<7> = 1
TRISC = TRISC | 0b01000000; // set tristate TRISC<6> high, for rx
SPBRG = BRGSPEED;
BRGH = 1;
SYNC = 0;
RCIE = 0;
RX9 = 0;
CREN = 0;
CREN = 1;
}
void gps_packet_limiter() {
unsigned int timewaster;
putstc("$PGRMO,GPGGA,0"); // disable $GPGGA sentence
putlf();
putstc("$PGRMO,GPGSA,0"); // disable $GPGSA sentence
putlf();
putstc("$PGRMO,GPGSV,0"); // disable $GPGSV sentence
putlf();
putstc("$PGRMO,PGRMT,1"); // enable $PGRMT sentence
putlf();
for (timewaster = 0; timewaster < 50000; timewaster++);
}
void getch_r() {
if (OERR || FERR) {
CREN = 0;
CREN = 1;
}
while (!RCIF) {
}
}
void putch_r(unsigned char cout) {
TXREG = cout;
while (!TRMT); // this is the fastest way of doing this.
}
#ifdef GPSRECV_DEBUG
main() {
setup_interrupts();
serial_init();
// gps_packet_limiter();
gps_init();
RCIE = 1;
PEIE = 1;
GIE = 1;
CREN = 1;
for(;;) { }
}
#endif
void interrupt inthdl() {
unsigned char t1 = TMR1H;
unsigned char t2 = TMR1L;
// TXREG=RCREG;
RCIE = 0;
PEIE = 0;
GIE = 0;
do {
TXREG = RCREG;
getch_r();
} while(RCREG != 10);
TXREG = 10;
// putch_r('$');
// putch_r(13);
// putch_r(10);
RCIE = 1;
PEIE = 1;
GIE = 1;
TMR1H = t1;
TMR1L = t2;
}