#include <reg52.H>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
//char code TIME_AREA= 8; //时区
//GPS数据存储数组
unsigned char JD[10]; //经度
unsigned char JD_a; //经度方向
unsigned char WD[9]; //纬度
unsigned char WD_a; //纬度方向
uchar time[6]; //时间
//串口中断需要的变量
unsigned char seg_count; //逗号计数器
//unsigned char dot_count; //小数点计数器
unsigned char byte_count; //位数计数器
unsigned char cmd_number; //命令类型
unsigned char mode; //0:结束模式,1:命令模式,2:数据模式
unsigned char buf_full; //1:整句接收完成,相应数据有效。0:缓存数据无效。
unsigned char cmd[5]; //命令类型存储数组
unsigned char speed[4];
unsigned char date[6];
uchar xianshi[]={'0','1','2','3','4','5','6','7','8','9'} ;
sbit lcden=P2^7;
sbit lcdrw=P2^5;
sbit lcdrd=P2^6;
void lcddelay(uint z);
void lcdwritecom(uchar com);
void lcdwritedata(uchar date);
void lcdinit();
//显示需要的变量
unsigned int dsp_count; //刷新次数计数器
unsigned char time_count;
void sys_init(void);
main()
{
unsigned char i;
sys_init();
while(1)
{
lcdwritecom(0x80);
lcdwritedata('s');
lcdwritedata('j');
lcdwritecom(0x80+0x40);
for(i=0;i<6;i++)
{
lcdwritedata(xianshi[time[i]]);
lcddelay(5);
}//显示时间
}
}
//系统初始化
void sys_init()
{
// unsigned char i;
SCON = 0x50;
TMOD = 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1=TL1=0xfd; /* TH1: reload value for 4800 baud [url=home.php?mod=space&uid=72445]@[/url] 11.059MHz */
TR1 = 1; /* TR1: timer 1 run */
lcdinit(); //初始化LCD
// ClearAS();
IE=0x90; //开总中断、串口中断
}
//串口接收中断
void uart(void) interrupt 4
{
unsigned char tmp;
if(RI){
tmp=SBUF;
switch(tmp)
{
case ':
cmd_number=0; //命令类型清空
mode=1; //接收命令模式
byte_count=0; //接收位数清空
break;
case ',':
seg_count++; //逗号计数加1
byte_count=0;
break;
case '*':
mode=0;
buf_full=1;
break;
default:
if(mode==1){//命令种类判断
cmd[byte_count]=tmp; //接收字符放入类型缓存
if(byte_count>=4){ //如果类型数据接收完毕,判断类型
if(cmd[0]=='G'){
if(cmd[1]=='P'){
if(cmd[2]=='R'){
if(cmd[3]=='M'){
if(cmd[4]=='C'){
cmd_number=1;
mode=2;
seg_count=0;
byte_count=0;
}
}
}
}
}
}
}
else if((mode==2)&cmd_number){
//接收数据处理 GPGGA,132920.487,,n,,w,0,00,,,M,0.0,M,,0000*56
//$GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120598, ,*10
//$GPGGA,161229.487,3723.2475,N,12158.3416,W,1,07,1.0,9.0,M, , , ,0000*18
switch(seg_count){
case 1:
if(byte_count<6){ //时间处理
time[byte_count]=tmp;
}
break;
case 3: //纬度处理
if(byte_count<9){
WD[byte_count]=tmp;
}
break;
case 4: //纬度方向处理
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: //speed
if(byte_count<4){
speed[byte_count]=tmp;
}
break;
// case 9: //date
// if(byte_count<6){
// date[byte_count]=tmp;
// }
// break;
}
}
byte_count++; //接收数位加1
break;
}
}
RI=0;
}