STC89C58串口接收GPS信號
/******************************************************************************
Copyright 2007
All rights reserved.
文件名:gps1602.c
模塊名稱:
功能概要:
取代版本:0.0.1
升級說明:create
cpu:stc89c58 晶振頻率:11.0592Mhz
硬件連接:
---------------------------------------------------------------
|DB0-----P0.0 | DB4-----P0.4 | WR-------P2.2 | A0--------P2.1 |
|DB1-----P0.1 | DB5-----P0.5 | RD-------P2.4 | Vo懸空 |
|DB2-----P0.2 | DB6-----P0.6 | CS-------P2.5 |
|DB3-----P0.3 | DB7-----P0.7 | RST-------P2.3 |
---------------------------------------------------------------
******************************************************************************/
#include
#include
#define LCM_Data P0
#define Busy 0x80 //用于檢測LCM狀態(tài)字中的Busy標(biāo)識
sbit LCM_RW = P2^2; //1602定義引腳
sbit LCM_RS = P2^1;
sbit LCM_E = P2^5;
//sbit GPS_SPD=P1^2;
//sbit SPD_TYPE=P1^3;
sbit KEY1=P1^1;
char code TIME_AREA= 8; //時(shí)區(qū)
//GPS數(shù)據(jù)存儲數(shù)組
unsigned char JD[10]; //經(jīng)度
unsigned char JD_a; //經(jīng)度方向
unsigned char WD[9]; //緯度
unsigned char WD_a; //緯度方向
unsigned char time[6]; //時(shí)間
unsigned char date[6]; //日期
unsigned char speed[5]; //速度
unsigned char high[6]; //高度
unsigned char angle[5]; //方位角
unsigned char use_sat[2]; //使用的衛(wèi)星數(shù)
unsigned char total_sat[2]; //天空中總衛(wèi)星數(shù)
unsigned char lock; //定位狀態(tài)
//串口中斷需要的變量
unsigned char seg_count; //逗號計(jì)數(shù)器
unsigned char dot_count; //小數(shù)點(diǎn)計(jì)數(shù)器
unsigned char byte_count; //位數(shù)計(jì)數(shù)器
unsigned char cmd_number; //命令類型
unsigned char mode; //0:結(jié)束模式,1:命令模式,2:數(shù)據(jù)模式
unsigned char buf_full; //1:整句接收完成,相應(yīng)數(shù)據(jù)有效。0:緩存數(shù)據(jù)無效。
unsigned char cmd[5]; //命令類型存儲數(shù)組
//顯示需要的變量
unsigned int dsp_count; //刷新次數(shù)計(jì)數(shù)器
unsigned char time_count;
bit page;
bit spd_type;
void sys_init(void);
bit chk_key(void);
void WriteDataLCM(unsigned char WDLCM);
void WriteCommandLCM(unsigned char WCLCM,BuysC);
unsigned char ReadDataLCM(void);
unsigned char ReadStatusLCM(void);
void LCMInit(void);
void LCD_cls(void);
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData);
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData);
void Delay5Ms(void);
void Delay400Ms(void);
/******************************************************************************************
* 函數(shù)名稱 :
* 功能描述 :
* 參數(shù) : 參數(shù)名稱:輸入/輸出?類型描述
*
* 返回值 :
* 全局變量 :
* 全局靜態(tài)變量:
* 局部靜態(tài)變量:
*----------------------------------------修改歷史------------------------------------------
* 當(dāng)前版本 :
* 修改說明 :
******************************************************************************************/
main()
{
unsigned char i;
char Bhour;
// unsigned int Knots;
sys_init();
while(1)
{
if(buf_full==0) //無GPS信號時(shí)
{
dsp_count++;
if(dsp_count>=65000)
{
LCD_cls(); //清屏
DisplayListChar(0,0,"No GPS connect..");
while(buf_full==0);
LCD_cls();
dsp_count=0;
}
}
else if(lock=='V') //GPRMC語句
{ //如果未定位
DisplayListChar(0,2,"No Positioning");
LCD_cls();
}
else
{ //如果已定位
DisplayOneChar(0,0,JD_a); //顯示經(jīng)度
DisplayOneChar(1,0,' ');
for(i=0;i<3;i++)
{
DisplayOneChar(i+1,0,JD[i]);
}
DisplayOneChar(4,0,'.');
for(i=3;i<10;i++)
{
DisplayOneChar(i+2,0,JD[i]);
}
DisplayOneChar(0,1,WD_a); //顯示緯度
DisplayOneChar(1,1,' ');
for(i=0;i<2;i++)
{
DisplayOneChar(i+2,1,WD[i]);
}
DisplayOneChar(4,1,'.');
for(i=2;i<9;i++)
{
DisplayOneChar(i+3,1,WD[i]);
}
DisplayOneChar(1,2,'2'); //日期2009-03-24
DisplayOneChar(2,2,'0');
DisplayOneChar(3,2,date[4]);
DisplayOneChar(4,2,date[5]);
DisplayOneChar(5,2,'-');
DisplayOneChar(6,2,date[2]);
DisplayOneChar(7,2,date[3]);
DisplayOneChar(8,2,'-');
DisplayOneChar(9,2,date[0]);
DisplayOneChar(10,2,date[1]);
Bhour=((time[0]-0x30)*10+time[1]-0x30)+TIME_AREA;
if(Bhour>=24)
{
Bhour-=24;
}
else if(Bhour<0)
{
Bhour+=24;
}
// DisplayListChar(2,3,"BJT ");
DisplayOneChar(1,3,Bhour/10+0x30);
DisplayOneChar(2,3,Bhour%10+0x30);
DisplayOneChar(3,3,':');
DisplayOneChar(4,3,time[2]);
DisplayOneChar(5,3,time[3]);
DisplayOneChar(6,3,':');
DisplayOneChar(7,3,time[4]);
DisplayOneChar(8,3,time[5]);
// if(spd_type)
// {
// DisplayListChar(5,3,"km/h A");
// }
// else
// {
// DisplayListChar(5,3,"knot A");
// }
// if(spd_type)
// { //km/h顯示
// for(i=0;i<5;i++)
// {
// DisplayOneChar(i,0,speed[i]);
// }
// }
// else
//{ //knot顯示
// Knots= (((speed[0]-0x30)*1000
// +(speed[1]-0x30)*100
// +(speed[2]-0x30)*10
// +(speed[4]-0x30))*1000)/1852;
// DisplayOneChar(0,3,Knots/1000+0x30);
// DisplayOneChar(1,3,(Knots%1000)/100+0x30);
// DisplayOneChar(2,3,(Knots%100)/10+0x30);
// DisplayOneChar(3,3,'.');
// DisplayOneChar(4,3,Knots%10+0x30);
// }
// for(i=0;i<5;i++)
// {
// DisplayOneChar(11+i,0,angle[i]);
// }
}
dsp_count=0;
}
}