#includereg52.h#includeintrins.h#defineucharunsignedchar#defineuintunsignedintsbitE=P2^7;//1602ʹÄܶËsbitRW=P2^6;//1602¶ÁдѡÔñsbitRS=P2^5;//bitReceivingF=0;//¿ªÊ¼½ÓÊÕ±êÖ¾bitEndF=0;//½áÊø±êÖ¾bitRMCF=0;//$GPRMCbitGGAF=0;//$GPGGAbitVTGF=0;//$GPVTGbitGSAF=0;//$GPGSAbitNewByteF;ucharGPS_time[9];//UTCʱ¼äucharGPS_wd[12];//γ¶ÈucharGPS_jd[13];//¾¶ÈucharGPS_warn;//¶¨Î»¾¯¸æucharGPS_quality;//¶¨Î»ÖÊÁ¿ucharGPS_status;//¶¨Î»×´Ì¬ucharGPS_alt[8];//º£°ÎucharGPS_sv[3];//ʹÓÃÎÀÐÇucharGPS_speed[10];//ËÙ¶ÈucharGPS_date[9];//UTCÈÕÆÚucharSegment;//¶ººÅ¼ÆÊýucharBytes_counter;ucharCommand;ucharnum=10;//1602Öظ´´ÎÊývoidGPRMC(uchar);voidGPGGA(uchar);voidGPVTG(uchar);voidGPGSA(uchar);voidGPS(uchar);voiddelay_10ms(uintdel)//ÑÓʱ10ms*del{uinti,j;for(i=0;idel;i++)for(j=0;j1827;j++);}voiddelay(){inti,j;for(i=0;i=10;i++)for(j=0;j=2;j++);}voidenable(uchardel){P0=del;RS=0;RW=0;E=0;delay();E=1;delay();}voidwrite(uchardel){P0=del;RS=1;RW=0;E=0;delay();E=1;delay();}voidL1602_init(void){enable(0x01);enable(0x38);enable(0x0c);enable(0x06);enable(0xd0);}voidL1602_string(ucharhang,ucharlie,uchar*p){uchara;if(hang==1)a=0x80;if(hang==2)a=0xc0;a=a+lie-1;enable(a);while(1){if(*p=='\0')break;write(*p);p++;}}voidCom_init(void){TMOD=0x20;PCON=0x00;SCON=0x50;TH1=0xFd;//ÉèÖò¨ÌØÂÊ9600TL1=0xFd;TR1=1;//Æô¶¯¶¨Ê±Æ÷1ES=1;//¿ª´®¿ÚÖжÏEA=1;//¿ª×ÜÖжÏ}voidGPS_interrupt()interrupt4{if(RI==1){EA=0;GPS(SBUF);}RI=0;EA=1;}voidGPS(uchartmp){if(tmp=='$')//Æðʼ±êÖ¾{Command=0;ReceivingF=1;Bytes_counter=0;Segment=0;//Çå¿ÕÓï¾ä¶Î¼ÆÊýÆ÷return;}if(ReceivingF){if(tmp==','){++Segment;Bytes_counter=0;//Çå¿Õ¶Î×Ö½Ú¼ÆÊýÆ÷return;}if(tmp=='*')//ÊÕµ½½áÊø±êÖ¾{ReceivingF=0;EndF=1;return;}if(Segment==0){if(Bytes_counter==3)//¶Î0£¬Óï¾äÀàÐÍÅжÏswitch(tmp){case'G':Command=1;//Óï¾äÀàÐÍ$GPGGAGGAF=1;break;case'M':Command=2;//Óï¾äÀàÐÍ$GPRMCRMCF=1;break;case'T':Command=3;//Óï¾äÀàÐÍ$GPVTGVTGF=1;break;case'S':break;default:Command=0;//·ÇÓÐЧÊý¾ÝÀàÐÍ£¬ÖÕÖ¹µ±Ç°Êý¾Ý½ÓÊÕReceivingF=0;break;}if(Bytes_counter==4)if(Command==0&&tmp=='A'){Command=4;//Óï¾äÀàÐÍ$GPGSAGSAF=1;}}else{switch(Command){case1:GPGGA(tmp);break;case2:GPRMC(tmp);break;case3:GPVTG(tmp);break;case4:GPGSA(tmp);break;default:break;}}++Bytes_counter;}NewByteF=0;return;}voidGPGGA(uchartmp){switch(Segment){case1:if(Bytes_counter==2||Bytes_counter==5)//$GPGGA¶Î1£¬UTCʱ¼ä£¬hhmmss£¨Ê±·ÖÃ룩¸ñʽ,È¡Ç°6λת»»ÎªHH:MM:SS¸ñʽ{GPS_time[Bytes_counter]=':';++Bytes_counter;}if(Bytes_counter8)GPS_time[Bytes_counter]=tmp;GPS_time[8]='\0';break;case2:if(Bytes_counter==3)//$GPGGA¶Î2´¦Àíγ¶Èddmm.mmmm£¨¶È·Ö£©¸ñʽ{GPS_wd[Bytes_counter]='.';//½ÓÊÕµÚ¶þ¸ö×Ö½Úºó²åÈë'.'++Bytes_counter;GPS_wd[11]='\0';}if(Bytes_counter==0)++Bytes_counter;GPS_wd[Bytes_counter]=tmp;break;case3:GPS_wd[0]=tmp;//$GPGGAµÚ3¶Î´¦Àíγ¶È°ëÇòN£¨±±°ëÇò£©»òS£¨ÄÏ°ëÇò£©break;case4:if(Bytes_counter==4)//$GPGGA¶Î4´¦Àí¾¶Èdddmm.mmmm£¨¶È·Ö£©¸ñʽ{GPS_jd[Bytes_counter]='.';//½ÓÊÕµÚ3¸ö×Ö½Úºó²åÈë'.'++Bytes_counter;GPS_jd[12]='\0';}if(Bytes_counter==0)++Bytes_counter;GPS_jd[Bytes_counter]=tmp;break;case5:GPS_jd[0]=tmp;//$GPGGAµÚ5¶Î´¦Àí¾¶È°ëÇòE£¨¶«¾£©»òW£¨Î÷¾£©break;case6:GPS_quality=tmp;break;case7:if(Bytes_counter2)//$GPGGAµÚ7¶Î´¦ÀíÕýÔÚʹÓýâËãλÖõÄÎÀÐÇÊýÁ¿£¨00~12£©£¨Ç°ÃæµÄ0Ò²½«±»´«Ê䣩GPS_sv[Bytes_counter]=tmp;GPS_sv[2]='\0';break;case9:if(Bytes_counter7)//$GPGGAµÚ9¶Î´¦Àíº£°Î¸ß¶È£¨-9999.9~99999.9£©{GPS_alt[Bytes_counter]=tmp;GPS_alt[Bytes_counter+1]='\0';}break;default:break;}}voidGPRMC(uchartmp){switch(Segment){case9:if(Bytes_counter2)//$GPRMCµÚ9¶Î´¦ÀíUTCÈÕÆÚ£¬ddmmyy£¨ÈÕÔÂÄ꣩¸ñʽת»»Îªyy-mm-dd{GPS_date[6+Bytes_counter]=tmp;}if(Bytes_counter1&&Bytes_counter4)//ÔÂ{GPS_date[1+Bytes_counter]=tmp;GPS_date[5]='-';}if(Bytes_counter3&&Bytes_counter6)//Äê{GPS_date[Bytes_counter-4]=tmp;GPS_date[2]='-';GPS_date[8]='\0';}break;default:break;}}voidGPGSA(uchartmp){switch(Segment){case2:GPS_status=tmp;//$GPGSAµÚ2¶Î´¦Àí¶¨Î»ÀàÐÍ£¬1=ûÓж¨Î»£¬2=2D¶¨Î»£¬3=3D¶¨Î»break;default:break;}}voidGPVTG(uchartmp){switch(Segment){case7:if(Bytes_counter7)//µØÃæËÙÂÊ£¨0000.0~1851.8¹«Àï/Сʱ£¬Ç°ÃæµÄ0Ò²½«±»´«Ê䣩{GPS_speed[Bytes_counter]=tmp;GPS_speed[Bytes_counter+1]='$';//ÕâÀï4¸ö×Ö·ûÊÇKm/hGPS_speed[Bytes_counter+2]='';GPS_speed[Bytes_counter+3]='/';GPS_speed[Bytes_counter+4]='#';GPS_speed[Bytes_counter+5]='\0';}break;default:break;}}voidmain(){L1602_init();L1602_string(1,1,GPSinitializing);L1602_string(2,1,Pleasewait);delay_10ms(100);while(num){L1602_string(2,12,.);delay_10ms(100);L1602_string(2,13,.);delay_10ms(100);L1602_string(2,14,.);delay_10ms(100);L1602_string(2,12,);L1602_string(2,13,);L1602_string(2,14,);delay_10ms(100);num--;}L1602_string(1,1,);L1602_string(2,1,);Com_init();while(1){L1602_string(1,1,GPS_wd);L1602_string(2,1,GPS_jd);L1602_string(2,14,);delay_10ms(400);L1602_string(1,1,);L1602_string(2,1,);L1602_string(1,1,Date:);L1602_string(2,1,Time:);L1602_string(1,6,GPS_date);L1602_string(2,6,GPS_time);delay_10ms(400);L1602_string(1,1,);L1602_string(2,1,);L1602_string(1,1,speed:);L1602_string(2,1,alt:);L1602_string(1,7,GPS_speed);L1602_string(2,5,GPS_alt);L1602_string(2,10,m);delay_10ms(400);L1602_string(1