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

📄 picture.c

📁 GPS开发
💻 C
字号:
//========================================================
//	文件名称:	picture.c
//	功能描述:	地图定位,日历显示,经纬度显示
//	维护记录:	2007-08-9	v1.0
//========================================================
#include "./c501/SPLC501User.h"
#include "gps.h"
#include "picture.h"
#include "china.h"
#include "Queue.h"
#include "spce061a.h"
#include "Key.h"
#include "china.h"
#include "Speak.h"

GPS_INFO	GPS;  														// 用于存放解析后的GPS信息
char Buf[100];															//="$GPRMC,091400,A,3958.9870,N,11620.3278,E,000.0,000.0,120302,005.6,W*62"; //存放GPS消息
//========================================================
//	语法格式:	void delay(int x)
//	实现功能:	延时
//	参数:		延时时间
//	返回值:	无
//========================================================
void delay( unsigned int x)
{
	for(;x > 0;x --)
		*P_Watchdog_Clear = 1;
}

//========================================================
//	语法格式:	void Show_Map(void)
//	实现功能:	显示并在地图上定位当前位置
//	参数:		无
//	返回值:	无
// 	说明:		show_map()的作用是已知一个地区的经纬度,计算出这个地区在地图上大体的位置
//	并通过闪烁标记出来,计算的方法是,先找到地图在经纬度与像素点之间的对应关系
//	再通过已知地区的经纬度标记出相应的像素点
//	中国所跨越的经度为东经74-134度(60)、纬度为北纬18-54(36):
//	液晶屏像素点为128*64由于液晶屏
//	上还有一些空白区域,因此地图实际跨度为:上下:0-63像素;左右:9-116,即跨度为(107,64)
//	。每个经度对应的像素点跨度为1.78,对应的纬度跨度为1.778
//	假设某一地区的经纬度为(N,E)则它对应的像素点为(N-74)*1.78,64-((E-18)*1.556) */
//========================================================
void Show_Map(void)
{
	int Queue_Solid=1	;
	int Key	;
	int adr_x = 0,adr_y = 0	;
	float latitude, longitude ;
	
	LCD501_ClrScreen(0);
	LCD501_ReverseColor();
	LCD501_Bitmap(0,0,encoding_0f);
	while(1)
	{
		*P_Watchdog_Clear = 1;
	 	Queue_Solid=Queue_Delete(Buf);  									// 通过队列与串口中断交换信息
		if(Queue_Solid == 1)
		{
			if('$' == Buf[0] && 'G' == Buf[1] && 'P' == Buf[2])				// 防止并没没有从串口接收到一条完整的信息而使程序跑飞
            {
            	GPS_Parse(Buf, &GPS);										// 对GPS接收的信息进行分析
            	latitude = GPS.latitude_Degree + GPS.latitude_Cent / 60;   	// 直接从GPS接收的经纬度是度和分组合的形式,因此需要转化成以度为单位。
            	adr_y = (int)64 - ((latitude - 18) * 1.778);					// 计算当前经纬度,要在地图上显示的位置.
            	longitude = GPS.longitude_Degree + GPS.longitude_Cent / 60;
				adr_x = (int)(longitude - 74) * 1.78 + 10;
				
				LCD501_Bitmap(adr_x,adr_y,encoding_1b);  					// 在LCD上实现闪烁功能
				delay(0xffff);
				LCD501_Bitmap(adr_x,adr_y,encoding_1c);
				delay(0xffff);
				if(GPS.status != 'A')     									// GPS模组并没有得到有效的消息
				{
					LCD501_PutChar(112, 48,'V');
				}
				else
				{
					LCD501_PutChar(112,48,'A');
				}			
            }
 			Queue_Solid = 0;
		}	
		Key=Key_GetValue();
		switch(Key)
		{
			case C_KEY1 :
				LCD501_ClrScreen(0);
				LCD501_ReverseColor();
				return ;	
			case C_KEY2:
				break;
			case C_KEY3:
				break;			
		}		
	}
}

//========================================================
//	语法格式:	void Show_Num(void)
//	实现功能:	显示经纬度
//	参数:		无
//	返回值:	无
//========================================================
void Show_Num(void)
{
	int adr_x,adr_y;    												// LCD显示坐标
	int Queue_Solid=1;													// 用来判断是否从队列中取出了数据.  
	int Key,i;
	char ch;
	char Info[10];
	
	adr_x = 0;
	adr_y = 0 ;
	LCD501_FontSet(1);   //8*16	
	LCD501_ClrScreen(0);
	while(1)
	{
		*P_Watchdog_Clear = 1;
	 	 Queue_Solid=Queue_Delete(Buf);
		if( Queue_Solid == 1)
		{
			if('$' == Buf[0] && 'G' == Buf[1] &&'P' == Buf[2])			// 防止并没没有从串口接收到一条完整的信息而使程序跑飞
           {
           		GPS_Parse(Buf,&GPS);									// 对GPS接收的信息进行分析
           		LCD501_Bitmap(2 * SIZE, 0, encoding_10); 				// 凌	
				LCD501_Bitmap(3 * SIZE, 0, encoding_11); 				// 阳	
				LCD501_Bitmap(4 * SIZE, 0, encoding_12); 				// 科	
 				LCD501_Bitmap(5 * SIZE, 0, encoding_13);				// 技
       		  	LCD501_Bitmap(0 * SIZE, 1 * SIZE, encoding_06); 		// 经
				LCD501_Bitmap(1 * SIZE, 1 * SIZE, encoding_07); 		// 度

				adr_x = 2 * SIZE;
				adr_y = 1 * SIZE;
				Int_To_Str(GPS.longitude_Degree,Info);
				i = 0;
				while(Info[i] != '\0')             						// 把一个字符串显示到LCD上 
				{
					*P_Watchdog_Clear = 1;
					ch=Info[i++];
					LCD501_PutChar(adr_x,adr_y,ch);
					adr_x = adr_x + 8;
				}
				LCD501_Bitmap(adr_x,adr_y,encoding_22); 				// 。
				adr_x += 8;
			 	Show_Float(GPS.longitude_Cent,&adr_x,&adr_y);
			 	
				LCD501_Bitmap(0 * SIZE, 2 * SIZE,encoding_08); 			// 纬
				LCD501_Bitmap(1 * SIZE, 2 * SIZE,encoding_07); 			// 度
				adr_x = 2*SIZE;
				adr_y = 2*SIZE;
				Int_To_Str(GPS.latitude_Degree,Info);
				i = 0;
				while(Info[i] != '\0')									// 把一个字符串显示到LCD上 
				{
					*P_Watchdog_Clear = 1;
					ch=Info[i++];
					LCD501_PutChar(adr_x,adr_y,ch);
					adr_x = adr_x + 8;
				}
				LCD501_Bitmap(adr_x,adr_y,encoding_22); 				// 。
				adr_x += 8;
		 		Show_Float(GPS.latitude_Cent,&adr_x,&adr_y);
            	
				if(GPS.status != 'A')     								// GPS模组并没有得到有效的消息
				{
					LCD501_PutChar(112, 0,'V');
				}
				else
				{
					LCD501_PutChar(112,0,'A');
				}
            }
 			 Queue_Solid = 0;
		}
		Key=Key_GetValue();
		switch(Key)
		{
			case C_KEY1 :                  								// key1 键 退出
				LCD501_ClrScreen(0);
				return;
			case C_KEY2:
				break;
			case C_KEY3:
				PlayRespond(C_WEIZHI);
				if( GPS.EW == 'E')                 						// 播报经度
					PlayRespond(C_DONGJING);
				else
					PlayRespond(C_XIJING);	
				PlaySpeakDegree(GPS.longitude_Degree);
				PlaySpeakCent(GPS.longitude_Cent);	
				*P_Watchdog_Clear = 1 ;				
				if( GPS.NS == 'N')										// 播报纬度
					PlayRespond(C_BEIWEI);
				else
					PlayRespond(C_NANWEI);
				PlaySpeakDegree(GPS.latitude_Degree);
				PlaySpeakCent(GPS.latitude_Cent);					
				break;			
		}		
	}
}

//========================================================
//	语法格式:	void Show_Time(void)
//	实现功能:	显示时间
//	参数:		无
//	返回值:	无
//========================================================
void Show_Time(void)
{
	int adr_x,adr_y;
	int Queue_Solid=1;  												// 标记队列中是否有数据.
	int i = 0;
	int Key;
	char time[5];
	char ch;
	adr_x = 0;
	adr_y = 0;
	LCD501_FontSet(1);   //8*16
	LCD501_ClrScreen(0);
	while(1)
	{
		*P_Watchdog_Clear = 1;
 		Queue_Solid=Queue_Delete(Buf);
		if(Queue_Solid == 1)
		{
			if('$' == Buf[0] && 'G' == Buf[1] &&'P' == Buf[2])			//防止并没没有从串口接收到一条完整的信息而使程序跑飞
           {
           		GPS_Parse(Buf,&GPS);									// 对GPS接收的信息进行分析
				LCD501_Bitmap(2*SIZE,0,encoding_10); 					// 凌	
				LCD501_Bitmap(3*SIZE,0,encoding_11); 					// 阳	
				LCD501_Bitmap(4*SIZE,0,encoding_12); 					// 科	
				LCD501_Bitmap(5*SIZE,0,encoding_13); 					// 技
           		LCD501_Bitmap(0*SIZE,1*SIZE,encoding_0a); 				// 日
				LCD501_Bitmap(1*SIZE,1*SIZE,encoding_0b); 				// 期  
				adr_x = 2.5*SIZE;
				adr_y = 1*SIZE;
				Int_To_Str(GPS.D.year,time);      						// 显示年
				i = 0;
				while(time[i] != '\0')									// 在LCD上显示一个字符串
				{
					*P_Watchdog_Clear = 1;
					ch = time[i++];
					LCD501_PutChar(adr_x,adr_y,ch);
					adr_x = adr_x + 8;
				}
				LCD501_PutChar(adr_x,adr_y,'-');
				adr_x = adr_x + 8;
				
				Int_To_Str(GPS.D.month,time);							// 显示月
				i = 0;
				while(time[i] != '\0')									// 在LCD上显示一个字符串
				{
					*P_Watchdog_Clear = 1;
						ch = time[i++];
					LCD501_PutChar(adr_x,adr_y,ch);
					adr_x = adr_x + 8;
				}
				LCD501_PutChar(adr_x,adr_y,'-');
				adr_x = adr_x + 8;
				
				Int_To_Str(GPS.D.day,time);								// 显示天
				i = 0;
				while(time[i] != '\0')									// 在LCD上显示一个字符串
				{	
					*P_Watchdog_Clear = 1;
					ch=time[i++];
					LCD501_PutChar(adr_x,adr_y,ch);
					adr_x = adr_x + 8;
				}
		
				LCD501_Bitmap(0 * SIZE,2 * SIZE,encoding_0c); 			// 时
				LCD501_Bitmap(1 * SIZE,2 * SIZE,encoding_0d); 			// 间
				adr_x = 2.5*SIZE;
				adr_y = 2*SIZE;
				Int_To_Str(GPS.D.hour,time);							// 显示小时
				i=0;
				while(time[i] != '\0')									// 在LCD上显示一个字符串
				{	
					*P_Watchdog_Clear = 1;
					ch = time[i++];
					LCD501_PutChar(adr_x,adr_y,ch);
					adr_x = adr_x + 8;
				}
				LCD501_PutChar(adr_x,adr_y,':');
				adr_x = adr_x + 8;
				
				Int_To_Str(GPS.D.minute,time);							// 显示分钟
				i = 0;
				while(time[i] != '\0')									// 在LCD上显示一个字符串
				{
					*P_Watchdog_Clear = 1;
					ch = time[i ++];
					LCD501_PutChar(adr_x,adr_y,ch);
					adr_x = adr_x + 8;
				}
				LCD501_PutChar(adr_x,adr_y,':');
				adr_x = adr_x + 8;
				
				Int_To_Str(GPS.D.second,time);							// 显示秒
				i = 0;
				while(time[i] != '\0')									// 在LCD上显示一个字符串
				{
					*P_Watchdog_Clear = 1;
					ch = time[i++];
					LCD501_PutChar(adr_x,adr_y,ch);
					adr_x = adr_x + 8;
				}
					
				if(GPS.status != 'A')     								// GPS模组并没有得到有效的消息
				{
					LCD501_PutChar(112, 0,'V');
				}
				else
				{
					LCD501_PutChar(112,0,'A');
				}
            }
 			Queue_Solid = 0;
		}
		Key = Key_GetValue();
		switch(Key)
		{
			case C_KEY1 :												// 退出
				LCD501_ClrScreen(0);
				return;
			case C_KEY2:
				break;
			case C_KEY3:
				PlayRespond(C_SHIKE);
				PlaySpeakYear(GPS.D.year);								// 报时
				PlaySpeakMonth(GPS.D.month);
				PlaySpeakDay(GPS.D.day);
				PlayRespond(C_BELL);         				  			// 报时声       						  
 			   	PlaySpeakHour(GPS.D.hour);            		   			// 时
 			   	PlaySpeakMinute(GPS.D.minute);   			   			// 分			
				break;
		}		
	}
}

//========================================================
//	语法格式:	Int_To_Str(int x,char *Str)
//	实现功能:	转化整型值为字符串形式
//	参数:		x: 转化的整数
//				Str:转化后的字符串
//	返回值:	无
//========================================================
void Int_To_Str(int x,char *Str)
{
	int t;
	char *Ptr,Buf[5];
	int i = 0;
	Ptr = Str;
	if(x < 10)															// 当整数小于10时,转化为"0x"的格式
	{
		*Ptr ++ = '0';
		*Ptr ++ = x+0x30;
	}
	else
	{
		while(x > 0)
		{
			t = x % 10;
			x = x / 10;
			Buf[i++] = t+0x30;											// 通过计算把数字转化成ASCII码形式
		}
		i -- ;
		for(;i >= 0;i --) 												// 将到到的字符串倒序
		{
			*(Ptr++) = Buf[i];
		}
	}
	*Ptr = '\0';
}
//========================================================
//	语法格式:	void Show_AD(void)
//	实现功能:	循环显示广告信息
//	参数:		无
//	返回值:	无
//========================================================
void Show_AD(void)
{
	int adr_x,adr_y;
	char AD[100] = "                www.61job.cn        www.unsp.com.cn                ";
	char ch;
	static int Start = 0;													// 静态局部变量,会保留上一次调用时的值.
	int i;
	
	adr_x = 0;
	adr_y = 48;
	for(i = Start;i < Start + 16;i ++)
	{
		ch = AD[i];
		LCD501_PutChar(adr_x, adr_y, ch);
		adr_x += 8;
	}	
	Start ++;
	if(AD[i] == '\0') 
	  Start = 0;
}

//========================================================
//	语法格式:	void Print_Invalid_Info(int x,int y)
//	实现功能:	弹出对话框表示当前GPS正在搜寻信息
//	参数:		对话框显示的坐标
//	返回值:	无
//========================================================
void Print_Invalid_Info(int x,int y)
{
	LCD501_Rectangle(x - 5, y - 5, x + 5 * SIZE + 10, 2 * SIZE+10, PAINT_HOLLOW );
	LCD501_Bitmap(x,y,encoding_14); 								// G 
	LCD501_Bitmap(x + 1 * SIZE,y,encoding_15); 						// P 
	LCD501_Bitmap(x + 2 * SIZE,y,encoding_16); 						// S 
	LCD501_Bitmap(x + 3 * SIZE,y,encoding_1d); 						// 正 
	LCD501_Bitmap(x + 4 * SIZE,y,encoding_1e); 						// 在
	LCD501_Bitmap(x, y+SIZE, encoding_1f); 							// 搜
	LCD501_Bitmap(x + 1 * SIZE, y+SIZE, encoding_20); 				// 寻
	LCD501_Bitmap(x + 2 * SIZE, y+SIZE, encoding_21); 				// .
	LCD501_Bitmap(x + 3 * SIZE, y+SIZE, encoding_21); 				// .
	LCD501_Bitmap(x + 4 * SIZE, y+SIZE, encoding_21); 				// .
}

//========================================================
//	语法格式:	void Show_Float(float fla,int * adr_x,int *adr_y)
//	实现功能:	在LCD上显示浮点数
//	参数:		fla 要显示的浮点数
//				*adr_x	要显示的LCD坐标
//				*adr_y	由于接下来还要向LCD显示,因此使用指针的形式,返回LCD已显示的位置
//	返回值:	无
//========================================================
void Show_Float(float fla,int * adr_x,int *adr_y)
{
	int integar;
	char Info[10],ch;
	int i;
		
	integar = (int)fla;             							// 显示整数部分
	Int_To_Str(fla,Info);
	i = 0 ;
	while(Info[i] !='\0')
	{
		*P_Watchdog_Clear=1;
		ch=Info[i++];
		LCD501_PutChar(*adr_x,*adr_y,ch);
		*adr_x = *adr_x + 8;
	}
	LCD501_PutChar(*adr_x,*adr_y,'.');    						// 显示小数点
	*adr_x += 8;
	fla = fla - integar;
	
	fla =  fla * 10;                       						// 显示 0.1
	integar = (int) fla;
	fla = fla - integar;				 						// 改变fla的值,使fla总是小于1
	ch = integar + 0x30 ; 	
	LCD501_PutChar(*adr_x,*adr_y,ch); 
	*adr_x = *adr_x + 8;
	
	fla =  fla*10;						 						// 显示 0.01
	integar = (int) fla;
	fla = fla - integar;					 					// 改变fla的值,使fla总是小于1
	ch = integar + 0x30 ; 
	LCD501_PutChar(*adr_x,*adr_y,ch); 
	*adr_x = *adr_x + 8;
	
	fla =  fla*10;							 					// 显示 0.001
	integar = (int) fla; 										// 改变fla的值,使fla总是小于1
	fla = fla - integar;
	ch = integar + 0x30 ; 					
	LCD501_PutChar(*adr_x,*adr_y,ch); 
	*adr_x = *adr_x + 8;
	
	fla =  fla*10;						 						// 显示 0.0001
	integar = (int) fla;
	fla = fla - integar;
	ch = integar + 0x30 ; 
	LCD501_PutChar(*adr_x,*adr_y,ch); 
	*adr_x = *adr_x + 8;	
}

⌨️ 快捷键说明

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