[mw_shl_code=c,true]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]);
lcddelay(5);
}//显示时间
}
}
//系统初始化
void sys_init()
{
// unsigned char i;
SCON = 0x40;
TMOD = 0x20;
TH1=TL1=0xfd;
TR1 = 1;
lcdinit(); //初始化LCD
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;
}[/mw_shl_code]
|