//********************************************************************** /*   【NMEA-0183簡易モニタ】 */ //********************************************************************** #define LED PORTB.F3 #define CR 0x0D #define LF 0x0A //********************************************************************** void interrupt() { if (INTCON.T0IF == 1) { INTCON.T0IF = 0; } if (PIR1.TMR1IF == 1) { LED = ~LED; PIR1.TMR1IF = 0; } } //********************************************************************** void Pwm_Change_DutyEx(unsigned int duty_ratio) { CCPR1L = duty_ratio >> 2; CCP1CON.F6 = duty_ratio & 0b00000001; CCP1CON.F7 = (duty_ratio & 0b00000010) >> 1; } //********************************************************************** void Usart_Write_String(char *buf) { static int len, i; len = strlen(buf); for (i = 0; i < len; i++) { Usart_Write(buf[i]); } } //********************************************************************** void GetFieldData(char* msg, short number, char* result) { short cnt1, cnt2, pnt1, pnt2, len; // len = StrLen(msg); cnt2 = 0; pnt1 = 0; pnt2 = 0; for (cnt1 = 0; cnt1 < len; cnt1++) { if (msg[cnt1] == ',') { pnt1 = pnt2; pnt2 = cnt1 + 1; cnt2++; if (cnt2 == number) break; } } strncpy(result, msg + pnt1, pnt2 - 1 - pnt1); result[pnt2 - pnt1] = 0x00; } /* 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 $GPGGA,235948.000,3600.0000,N,13600.0000,E,0,00,99.9,00000.0,M,0000.0,M,000.0,0000*4A */ //********************************************************************** void main() { static char rd, buf[50], tmp[20], cnt, cnt2, mode; // OSCCON = 0b01110000; // クロックは8Mhz CMCON = 0b00000111; // コンパレータは使用しない。 ANSEL = 0b00000000; // A/D変換は使用しない。 TRISA = 0b01111100; TRISB = 0b00000100; OPTION_REG = 0b10000111; PIE1.TMR1IE = 1; PIR1.TMR1IF = 0; T1CON = 0b00110001; INTCON = 0b01100000; // Pwm_Init(3000); // 3Khz Pwm_Change_DutyEx(1024 / 2); // Lcd_Custom_Config(&PORTB, 4, 6, 7, 1, &PORTA, 1, 0, 7); TRISA = 0b01111100; Lcd_Custom_Cmd(LCD_CURSOR_OFF); for (cnt = 0; cnt < 5; cnt++) { Lcd_Custom_Out(1, 1, "NMEA0183 Monitor"); Pwm_Start(); Delay_ms(300); Pwm_Stop(); Lcd_Custom_Cmd(LCD_CLEAR); Delay_ms(300); } // Usart_Init(9600); // INTCON.GIE = 1; // これ以降の処理で割り込みを許可する。 // Pwm_Start(); Delay_ms(300); Pwm_Stop(); // cnt = 0; mode = 0; while (1) { if (Usart_Data_Ready() == 0) continue; rd = Usart_Read(); buf[cnt] = rd; if (cnt < 49) cnt++; buf[cnt] = 0x00; // if (rd == LF) { if (strncmp(buf, "$GPGGA", 6) == 0) { Pwm_Start(); Delay_ms(100); Pwm_Stop(); // GetFieldData(buf, 3, tmp); //緯度の表示 Lcd_Custom_Out(1, 1, "N="); Lcd_Custom_Out(1, 3, tmp); // GetFieldData(buf, 5, tmp); //経度の表示 Lcd_Custom_Out(2, 1, "E="); Lcd_Custom_Out(2, 3, tmp); // GetFieldData(buf, 7, tmp); //GPSクオリティの表示 Lcd_Custom_Out(1, 16, tmp); // GetFieldData(buf, 8, tmp); //受信衛星数 Lcd_Custom_Out(2, 15, tmp); } cnt = 0; if (mode == 0) { Usart_Write_String("$PSRF106,21*0F\r\n"); //測地系:WGS-84に設定 mode = 1; } } } } //**********************************************************************