#include <12F675.h> #device adc=8 #FUSES WDT //Watch Dog Timer #FUSES EC_IO #FUSES NOCPD //No EE protection #FUSES NOPROTECT //Code not protected from reading #FUSES NOMCLR //Master Clear pin used for I/O #FUSES PUT //Power Up Timer #FUSES NOBROWNOUT //No brownout reset #FUSES BANDGAP_HIGH #use delay(clock=10M) #use rs232(baud=4800,parity=N,xmit=PIN_A4,rcv=PIN_A1,bits=8,stream=1,restart_wdt,invert) char utc[6],status,lat[8],lon[8],speed[6]={'0'}, bearing[6]={'0'}, date[6], checksum[2]; void calc_cs() {int cs=0x35; int i; for(i=0;i<6;i++)cs^=utc[i]; cs^=status; for(i=0;i<8;i++)cs^=lat[i]; for(i=0;i<8;i++)cs^=lon[i]; for(i=0;i<4;i++)cs^=speed[i]; for(i=0;i<6;i++)cs^=bearing[i]; for(i=0;i<6;i++)cs^=date[i]; checksum[0]=(cs/16)+48; checksum[1]=(cs%16)+48; if(checksum[0]>57)checksum[0]+=7; if(checksum[1]>57)checksum[1]+=7; } void main() { int i; char temp; setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_wdt(WDT_2304MS); setup_timer_1(T1_DISABLED); setup_comparator(NC_NC); setup_vref(FALSE); delay_ms(10); //printf("\n\rnmea converter for th-d7 by TB2HL \n\r"); while(true) {start: restart_wdt(); speed[2]='0'; speed[3]='0'; speed[4]='0'; bearing[0]='0'; bearing[1]='0'; bearing[2]='0'; bearing[3]='0'; bearing[4]='0'; while(getch()!='$') restart_wdt(); if(getch()!='G') goto start; if(getch()!='P') goto start; if(getch()!='R') goto start; if(getch()!='M') goto start; if(getch()!='C') goto start; getch(); // , for(i=0;i<6;i++)utc[i]=getch(); while(getch()!=','); status=getch(); getch(); lat[0]=getch(); lat[1]=getch(); lat[2]=getch(); lat[3]=getch(); getch(); lat[4]=getch(); lat[5]=getch(); lat[6]=getch(); getch(); //4.hane getch(); //virgül lat[7]=getch(); //N-S getch(); getch(); lon[0]=getch(); lon[1]=getch(); lon[2]=getch(); lon[3]=getch(); getch(); // . lon[4]=getch(); lon[5]=getch(); lon[6]=getch(); getch(); // 4. hane getch(); //virgül lon[7]=getch(); // E-W getch();// , i=0; while(i<6) {temp=getch(); if(temp==',') break; speed[i++]=temp; } i=0; while(i<6) {temp=getch(); if(temp==',') break; bearing[i++]=temp; } date[0]=getch(); while(date[0]==',') {date[0]=getch();} for(i=1;i<6;i++)date[i]=getch(); restart_wdt(); calc_cs(); printf("$GPRMC,"); for(i=0;i<6;i++) printf("%c",utc[i]); printf(",%c,",status); printf("%c%c%c%c.%c%c%c,%c,",lat[0],lat[1],lat[2],lat[3],lat[4],lat[5],lat[6],lat[7]); printf("0%c%c%c%c.%c%c%c,%c,",lon[0],lon[1],lon[2],lon[3],lon[4],lon[5],lon[6],lon[7]); for(i=0;i<4;i++) printf("%c",speed[i]); printf(","); for(i=0;i<6;i++) printf("%c",bearing[i]); printf(","); for(i=0;i<6;i++) printf("%c",date[i]); printf(",,,N*%c%c\r\n",checksum[0],checksum[1]); } }