⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gps.c

📁 GPS信号接收程序
💻 C
字号:
#include<reg52.h>
#include"GPS.h"
/**********************************************************
	LCD1602.c (GPS)
	
	Created by Cao Jian 
	email: cj19870223@sina.com 	
*************************************************************/
sbit P07=P0^7;

unsigned char idata GPS[6];
unsigned char idata GPSBuf0[60];
unsigned char idata m_sTime[9];			 		//提取时间所用
unsigned char idata m_sPositionY[8];		    //提取纬度所用
unsigned char idata m_sPositionX[9];			//提取经度所用
unsigned char idata m_sData[9];					//提取日期所用
unsigned char j=8;
unsigned char x=0;
unsigned char y=0;
unsigned char m=0;
unsigned char n=0;

void inituart()
{
	TMOD=0x20;//定时器1,方式2 
	TH1=0xfa;//波特率9600 
	TCON=0x40;//启动定时器1 

	SCON=0x50;//方式1,允许串行接收 
	IE=0x90;//开总中断,允许串行中断 
}

void uart() interrupt 4 using 1
{
	unsigned char i;
	unsigned char SectionID=0;

	if(RI==1)
	{
		RI=0;//清除中断 
		GPS[0]=SBUF;	

		if(GPS[0]=='$')
		{
			RI=0;
			SectionID=0;
			for(i=1;i<6;i++)
			{
				while(!RI);	//等待该次八位数据接收完毕 
				RI=0;//清除中断  
				GPS[i]=SBUF;
			}

			if(GPS[3]=='R')
			{
				if(j==9)
				{
					for(i=0;i<70;i++)
					{
						while(!RI);	//等待该次八位数据接收完毕 
						RI=0;//清除中断  
						GPSBuf0[i]=SBUF;
						if(GPSBuf0[i]=='*')break;//校验位不再接收
						if(SBUF==',')
							SectionID++;		  //提取逗号个数
						else
						{
							switch(SectionID)
							{
								case 1: m_sTime[x++]=SBUF; 		   break;	   //提取时间
								case 3: m_sPositionY[y++]=SBUF;    break;	   //提取纬度
								case 5: m_sPositionX[m++]=SBUF;    break;	   //提取经度
								case 9: m_sData[n++]=SBUF;         break;	   //提取日期
								default: break;
							}
						}
					}
					//等待校验位发送完毕
					while(!RI);
					RI=0;
					while(!RI);
					RI=0;
							
					j=0;
				}
				else j=j+1;
			}
		}
	}
}

void main()
{
	unsigned int m,n;
	unsigned char temp;

	LCD_init();

	LCD_write_string("Welcome!");
	LCD_en_com(0xc3);
	LCD_write_string("Show you these!!!");

	inituart();
	while(1)
	{
		if(j==0)
		{
			//调整时间 
			m_sTime[0]=m_sTime[0]-'0';
			m_sTime[1]=m_sTime[1]-'0';

			temp=m_sTime[0]*10+m_sTime[1];
			if(temp>=16)				
			{//如果大于等于16就-16 
					
				temp=temp-16;
				m_sTime[0]=temp/10;
				m_sTime[1]=temp%10;
			}
			else  
			{//否则就+8 
				temp=temp+8;
				m_sTime[0]=temp/10;
				m_sTime[1]=temp%10;
			}
			m_sTime[0]=m_sTime[0]+0x30;
			m_sTime[1]=m_sTime[1]+0x30;	
			//显示数据
			LCD_en_com(0x01);
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			LCD_en_com(0x7d);						//???
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			//LCD_write_string("$GPRMC");
			LCD_write_string(m_sTime);
			LCD_write_string(m_sPositionY);
			LCD_write_string(m_sPositionX);
			LCD_write_string(m_sData);
			//LCD_write_string("It's Over....");
				 
			j=1;
			P07=!P07;
			for(m=0;m<280;m++)
				for(n=0;n<200;n++);
		}

		for(m=0;m<280;m++)
			for(n=0;n<200;n++);

		LCD_en_com(0x18);//整屏左移 
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -