/*************************************
GPS½aÂëÏÔê¾3ìDò,
***************************************/
#include<reg52.h>
#include "1602.h"
#include"math.h"
#include <stdlib.h>
sbit fmq=P1^5;
sbit GPS_SPD=P1^1; //GPSÄ£¿éËùÂêéèÖÃ
sbit KEY1=P1^0; //ÏÔê¾ÄúèY·ÖÆáÇD»»,(T0,T1òy½Å μÄμú¶t1|ÄüÎa¼ÆêyÆ÷¡£)
char code TIME_AREA= 8; //ê±Çø
/***************************************
ÕaêÇ×öμÄ2¿·Ö¸ü¸Ä
************************************/
unsigned long maxspeed,b;
unsigned int count=0;
unsigned int a[5];
unsigned char hspeed[5];
unsigned int dot_count; //D¡êyμã¼ÆêyÆ÷
//unsigned char x;
//GPSêy¾Y′æ′¢êy×é
unsigned char JD[10]; //¾-¶è
unsigned char JD_a; //¾-¶è·½Ïò
unsigned char WD[9]; //Î3¶è
unsigned char WD_a; //Î3¶è·½Ïò
unsigned char date[6]; //èÕÆú
unsigned char time[6]; //ê±¼ä
unsigned char speed[5]={'0','0','0','.','0'}; //Ëù¶è
unsigned char high[6]; //¸ß¶è
unsigned char angle[5]={'0','0','0','0','0'}; //·½Î»½Ç
unsigned char use_sat[2]; //ê1óÃμÄÎàDÇêy
unsigned char total_sat[2]; //ìì¿ÕÖD×üÎàDÇêy
unsigned char lock; //¶¨Î»×′ì¬
//′®¿úÖD¶ÏDèòaμıäá¿
unsigned char seg_count; //¶oożÆêyÆ÷
unsigned char byte_count; //λêy¼ÆêyÆ÷
unsigned char cmd_number; //ÃüáîààDí
unsigned char mode; //0£o½áêøģ꽣¬1£oÃüáîģ꽣¬2£oêy¾YÄ£ê½
unsigned char buf_full; //1£oÕû¾ä½óêÕíê3飬Ïàó|êy¾YóDD§¡£0£o»o′æêy¾YÎTD§¡£
unsigned char cmd[5]; //ÃüáîààDí′æ′¢êy×é
//ÏÔê¾Dèòaμıäá¿
unsigned int dsp_count; //Ë¢DÂ′Îêy¼ÆêyÆ÷
//unsigned char time_count;
bit page;
void sys_init(void);
bit chk_key(void);
main()
{
unsigned char i;
char Bhour;
sys_init();
fmq=0;
lock=1;
use_sat[0]='0';
use_sat[1]='0';
total_sat[0]='0';
total_sat[1]='0';
while(1){
if(buf_full==0) //ÎTGPSDÅoÅê±
{
dsp_count++;
if(dsp_count>=65000){
LCD_cls(); //ÇåÆá
LCD_write_string(0,0,"No GPS connect..");
LCD_write_string(0,1,"Please Check..");
while(buf_full==0);
LCD_cls();
dsp_count=0;
}
}
else{ //óDGPSDÅoÅê±
/*************************************
×î′óËù¶è′|àí
*************************************/
dot_count=0;
b=0;
for(i=0;i<5;i++)
{
if(speed[i]!='.')
dot_count++;
else
break ;
}
switch(dot_count)
{
case 1:
b=((speed[0]-'0')*10+(speed[2]-'0'))*1.852;
break;
case 2:
b=((speed[0]-'0')*100+(speed[1]-'0')*10+(speed[4]-'0'))*1.852;
break;
case 3:
b=((speed[0]-'0')*1000+(speed[1]-'0')*100+(speed[2]-'0')*10+(speed[4]-'0'))*1.852;
break;
}
if(b>maxspeed)
{
maxspeed=b;
}
/*************************************
×î′óËù¶è′|àí
*************************************/
if(chk_key()){ //¼ì2aμ½°′¼üÇD»»ÏÔê¾
page=!page;
LCD_cls();
}
if(!page){ //ò3Ãæ1
if(buf_full|0x01){ //GGAóï¾ä
if(lock==0){ //èç1ûÎ′¶¨Î»
LCD_write_string(0,0,"*---.--.---- ");
LCD_write_string(0,1,"* --.--.---- ");
}else{ //èç1ûòѶ¨Î»
LCD_write_char(0,0,JD_a); //ÏÔê¾¾-¶è
for(i=0;i<3;i++)
{
LCD_write_char(i+1,0,JD[i]);
}
LCD_write_char(4,0,'.');
for(i=3;i<10;i++)
{
LCD_write_char(i+2,0,JD[i]);
}
LCD_write_char(0,1,WD_a); //ÏÔê¾Î3¶è
LCD_write_char(1,1,' ');
for(i=0;i<2;i++)
{
LCD_write_char(i+2,1,WD[i]);
}
LCD_write_char(4,1,'.');
for(i=2;i<9;i++)
{
LCD_write_char(i+3,1,WD[i]);
}
}
LCD_write_char(14,1,use_sat[0]); //ÏÔê¾½óêÕÎàDÇêy
LCD_write_char(15,1,use_sat[1]);
buf_full&=~0x01;
dsp_count=0;
}
if(buf_full|0x02){ //GSVóï¾ä
LCD_write_char(14,1,total_sat[0]);
LCD_write_char(15,1,total_sat[1]);
buf_full&=~0x02;
dsp_count=0;
}
if(buf_full|0x04){
if(lock==0){ //èç1ûÎ′¶¨Î»
LCD_write_string(0,0,"*---.--.---- ");
LCD_write_string(0,1,"* --.--.---- ");
}else{ //èç1ûòѶ¨Î»
LCD_write_char(0,0,JD_a); //ÏÔê¾¾-¶è
for(i=0;i<3;i++)
{
LCD_write_char(i+1,0,JD[i]);
}
LCD_write_char(4,0,'.');
for(i=3;i<10;i++)
{
LCD_write_char(i+2,0,JD[i]);
}
LCD_write_char(0,1,WD_a); //ÏÔê¾Î3¶è
LCD_write_char(1,1,' ');
for(i=0;i<2;i++)
{
LCD_write_char(i+2,1,WD[i]);
}
LCD_write_char(4,1,'.');
for(i=2;i<9;i++)
{
LCD_write_char(i+3,1,WD[i]);
}
}
LCD_write_char(14,0,use_sat[0]); //ÏÔê¾½óêÕÎàDÇêy
LCD_write_char(15,0,use_sat[1]);
buf_full&=~0x04;
dsp_count=0;
}
}
else{ //ò3Ãæ2
if(buf_full|0x01){ //GGAóï¾ä
buf_full&=~0x01;
dsp_count=0;
}
if(buf_full|0x02){
buf_full&=~0x02;
dsp_count=0;
}
if(buf_full|0x04){ //RMCóï¾ä
Bhour=((time[0]-0x30)*10+time[1]-0x30)+TIME_AREA;
if(Bhour>=24){
Bhour-=24;
}else if(Bhour<0){
Bhour+=24;
}
LCD_write_char(0,1,date[4]);
LCD_write_char(1,1,date[5]);
LCD_write_char(2,1,date[2]);
LCD_write_char(3,1,date[3]);
LCD_write_char(4,1,date[0]);
LCD_write_char(5,1,date[1]);
LCD_write_char(8,1,Bhour/10+0x30);
LCD_write_char(9,1,Bhour%10+0x30);
LCD_write_char(10,1,':');
LCD_write_char(11,1,time[2]);
LCD_write_char(12,1,time[3]);
LCD_write_char(13,1,':');
LCD_write_char(14,1,time[4]);
LCD_write_char(15,1,time[5]);
LCD_write_string(5,0,"knot A");
if(lock=='0'){ //èç1ûÎ′¶¨Î»
LCD_write_string(0,0,"---.-");
LCD_write_string(11,0,"---.-");
}else{ //òѾ-¶¨Î»,Ôú′Ë′|×öμĸĶˉ¡£
/*******************************************************************************/
if(count<10)
{
for(i=0;i<5;i++)
{
LCD_write_char(i,0,speed[i]);//knotÏÔê¾
}
count++;
}
else
{
if(count>15)
{
count=0;
}
hspeed[0]=maxspeed/1000+0x30; //°ÑD¡êy×a3é×Ö·ûêy×é
hspeed[1]=(maxspeed/100)%10+0x30;
hspeed[2]=(maxspeed/10)%10+0x30;
hspeed[3]='.';
hspeed[4]= maxspeed%10+0x30;
count++;
LCD_write_string(5,0,"Km/h A");
LCD_write_char(0,0,hspeed[0]);
LCD_write_char(1,0,hspeed[1]);
LCD_write_char(2,0,hspeed[2]);
LCD_write_char(3,0,hspeed[3]);
LCD_write_char(4,0,hspeed[4]); //×î′óËù¶èÏÔ */
}
/*******************************************************************************/
for(i=0;i<5;i++){
LCD_write_char(11+i,0,angle[i]);
}
}
buf_full&=~0x04;
dsp_count=0;
}
}
}
}
}
bit chk_key(void)
{
if(!KEY1){
delayms(10);
if(!KEY1){
while(!KEY1);
delayms(10);
return(1);
}
}
LCD_cls(); //ÇåÆá
return(0);
}
//Ïμí33õê¼»ˉ
void sys_init() {
unsigned char i;
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD = 0x21; /* TMOD: timer 1, mode 2, 8-bit reload */
//SCON = 0x50;
//PCON = 0;
//TMOD &= 0xf0;
//TMOD = 0x20;
//TH1 = 0xfd; //??,???9600
//TL1 = 0xfd;
//TR1= 1;
if(GPS_SPD){ //Õaàïê1óÃ4800μÄ2¨ìØÂê ¾§Õñ±ØDë 11.0592MHz
TH1 = 0xfd; /* TH1: reload value for 9600 baud @ 11.059MHz */
}else{
TH1 = 0xfa; /* TH1: reload value for 4800 baud @ 11.059MHz */
}
TR1 = 1; /* TR1: timer 1 run */
LCD_init(8); //3õê¼»ˉLCD
LCD_write_string(0,0," GPS WELCOME ");
LCD_write_string(0,1," 16-05-05 3514 ");
for(i=1;i<4;i++){
delayms(250);
}
IE=0x90; //¿a×üÖD¶Ï¡¢′®¿úÖD¶Ï
}
//′®¿ú½óêÕÖD¶Ï
void uart(void) interrupt 4
{
unsigned char tmp;
if(RI){
tmp=SBUF;
switch(tmp){
case '$':
cmd_number=0; //ÃüáîààDíÇå¿Õ
mode=1; //½óêÕÃüáîÄ£ê½
byte_count=0; //½óêÕλêyÇå¿Õ
break;
case ',':
seg_count++; //¶oożÆêy¼ó1
byte_count=0;
break;
case '*':
switch(cmd_number){
case 1:
buf_full|=0x01;
break;
case 2:
buf_full|=0x02;
break;
case 3:
buf_full|=0x04;
break;
}
mode=0;
break;
default:
if(mode==1){
//ÃüáîÖÖààÅD¶Ï
cmd[byte_count]=tmp; //½óêÕ×Ö·û·ÅèëààDí»o′æ
if(byte_count>=4){ //èç1ûààDíêy¾Y½óêÕíê±Ï£¬ÅD¶ÏààDí
if(cmd[0]=='G'){
if(cmd[1]=='P'){
if(cmd[2]=='G'){
if(cmd[3]=='G'){
if(cmd[4]=='A'){
cmd_number=1;
mode=2;
seg_count=0;
byte_count=0;
}
}
else if(cmd[3]=='S'){
if(cmd[4]=='V'){
cmd_number=2;
mode=2;
seg_count=0;
byte_count=0;
}
}
}
else if(cmd[2]=='R'){
if(cmd[3]=='M'){
if(cmd[4]=='C'){
cmd_number=3;
mode=2;
seg_count=0;
byte_count=0;
}
}
}
}
}
}
}
else if(mode==2){
//½óêÕêy¾Y′|àí
switch (cmd_number){
case 1: //ààDí1êy¾Y½óêÕ¡£GPGGA
switch(seg_count){
case 2: //Î3¶è′|àí
if(byte_count<9){
WD[byte_count]=tmp;
}
break;
case 3: //Î3¶è·½Ïò′|àí
if(byte_count<1){
WD_a=tmp;
}
break;
case 4: //¾-¶è′|àí
if(byte_count<10){
JD[byte_count]=tmp;
}
break;
case 5: //¾-¶è·½Ïò′|àí
if(byte_count<1){
JD_a=tmp;
}
break;
case 6: //¶¨Î»ÅD¶Ï
if(byte_count<1){
lock=tmp;
}
break;
case 7: //¶¨Î»ê1óÃμÄÎàDÇêy
if(byte_count<2){
use_sat[byte_count]=tmp;
}
break;
case 9: //¸ß¶è′|àí
if(byte_count<6){
high[byte_count]=tmp;
}
break;
}
break;
case 2: //ààDí2êy¾Y½óêÕ¡£GPGSV
switch(seg_count){
case 3: //ìì¿ÕÖDμÄÎàDÇ×üêy
if(byte_count<2){
total_sat[byte_count]=tmp;
}
break;
}
break;
case 3: //ààDí3êy¾Y½óêÕ¡£GPRMC
switch(seg_count){
case 1: //ê±¼ä′|àí
if(byte_count<6){
time[byte_count]=tmp;
}
break;
case 2: //¶¨Î»ÅD¶Ï
if(byte_count<1){
if (tmp=='A') {lock=1;}
else{
lock=0;}
}
break;
case 3: //Î3¶è′|àí
if(byte_count<9){
WD[byte_count]=tmp;
}
break;
case 4: //Î3¶è·½Ïò′|àí
if(byte_count<1){
WD_a=tmp;
}
break;
case 5: //¾-¶è′|àí
if(byte_count<10){
JD[byte_count]=tmp;
}
break;
case 6: //¾-¶è·½Ïò′|àí
if(byte_count<1){
JD_a=tmp;
}
break;
case 7: //Ëù¶è′|àí
if(byte_count<5){
speed[byte_count]=tmp;
}
break;
case 8: //·½Î»½Ç′|àí
if(byte_count<5){
angle[byte_count]=tmp;
}
break;
case 9: //·½Î»½Ç′|àí
if(byte_count<6){
date[byte_count]=tmp;
}
break;
}
break;
}
}
byte_count++; //½óêÕêyλ¼ó1
break;
}
}
RI=0;
}
这是一整串助手收到的gps信息:
$GPRMC,100913.00,A,3448.42349,N,11347.80444,E,0.109,,060516,,,A*79 $GPVTG,,T,,M,0.109,N,0.202,K,A*2B $GPGGA,100913.00,3448.42349,N,11347.80444,E,1,09,1.00,66.9,M,-14.5,M,,*45
$GPGSA,A,3,28,17,08,11,30,22,01,07,03,,,,1.96,1.00,1.69*01
$GPGSV,3,1,11,01,74,084,25,03,16,142,19,07,42,199,31,08,26,060,40*75 $GPGSV,3,2,11,11,62,048,26,13,02,294,,17,29,271,33,19,03,257,08*71
$GPGSV,3,3,11,22,24,113,27,28,46,321,22,30,56,242,11*45
$GPGLL,3448.42349,N,11347.80444,E,100913.00,A,A*6C /*****一带上这一行就不显示了********/
求大神看看是什么问题?
|