完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include extern GPS_INFO GPS; //外部结构体 #define Buf1_Max 20 //串口1,PC缓存长度,存放命令数据#define Buf2_Max 80 //串口2,BD缓存长度,存放GNRMC数据 /*********定义变量********/// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27//******************************** " * 2 8 L 5 0 0 0 0 d 0 0 m 0 0 s 0 0 d 0 0 m 0 0 s * "unsigned char Location_Buf[29] = {0x22,0x2a,0x32,0x38,0x4c,0x35,0x30,0x30,0x30,0x30,0x64,0x30,0x30,0x6d,0x30,0x30,0x73,0x30,0x30,0x64,0x30,0x30,0x6d,0x30,0x30,0x73,0x2a,0x22,0x00};//******************************** " * 1 2 R 5 0 0 - * " unsigned char Times = 0,shijian = 0;unsigned char Val_CSQ = 0; //信号质量变量unsigned char Time_Refresh = 0; //刷新时间控制变量 /*********Uart1相关变量**********/unsigned char PC_NUM = 0; //数组下标unsigned char PC_REV_START = 0; //接收开始标志xdata unsigned char Uart1_Buf[Buf1_Max]; //接收缓存,数组累加变量//xdata unsigned char Temp_Buf1[Buf1_Max]; // /*********Uart2相关变量**********/unsigned char BD_NUM = 0; //数组下标unsigned char BD_REV_START = 0; //接收开始标志xdata unsigned char Uart2_Buf[Buf2_Max]; //接收缓存,数组累加变量xdata unsigned char Temp_Buf2[Buf2_Max]; // /*********各类标志**********/bdata unsigned int Flag; //定时器标志位,用bdata定义可以位寻址***it Timer0_Start = Flag^0; //定时器0延时启动计数器标志***it Display_CSQ = Flag^1; //CQS数值显示标志***it PC_FLAG = Flag^2; //PC处理标志***it BD_FLAG = Flag^3; //GPS处理标志 ***it REV_LOC_ASK = Flag^6; //接收坐标应答标志 unsigned char Val_Location = 5; //接收上位机坐标信息应答标志,初始值不为0/1的其他数 /*********定义接口********/***it Net_Led = P2^0; //网络运行状态灯 /*********函数声明********/void Timer0_Init(void); //定时器0初始化void CLR_Buf1(void); //清空串口1接收的数据void CLR_Buf2(void); //清空串口2接收的数据 void Report_Location(); //上PC上报坐标数据 void IO_mode(void); void main(){ unsigned char i = 0; IO_mode(); CLR_Buf1(); Uart1_PC_Init(); Uart2_BD_Init(); Timer0_Init(); Flag = 0; LcdInit(); /*********GSM模块初始设置************/ EA = 1; Write_Com(0x8A); HZkdis("Success! "); Delay_ms(3000); Lcd_clear(); LcdInit(); Write_Com(0x80); HZkdis("系统状态"); while(1) { if(Display_CSQ) //5秒种刷新1次CSQ值和坐标值 { Val_Location = GPS_RMC_Parse(Uart2_Buf,&GPS); //如果定位信息解析成功,返回1 if(Val_Location == 1) { GPS_Display(); if(!REV_LOC_ASK) //如果PC没有返回总控坐标回执,就再发一直发 { Report_Location(); Write_Com(0x98); HZkdis("消息: "); } CLR_Buf2(); } Display_CSQ = 0; Write_Com(0x9e); Write_Data(0x30 + Val_Location); //测试Val_Location值的,只第1次为1,之后就是0.不知为什么,求指教 } }} /******************************************************************************** 函数名 : Report_Location* 描述 : MCU收到BD的坐标数据后,发送给PC*******************************************************************************/void Report_Location(void){// 经度 Location_Buf[7] = GPS.longitude_Degree/100 + 0x30; Location_Buf[8] = GPS.longitude_Degree/10%10 + 0x30; Location_Buf[9] = GPS.longitude_Degree%10 + 0x30; Location_Buf[11] = GPS.longitude_Cent/10 + 0x30; Location_Buf[12] = GPS.longitude_Cent%10 + 0x30; Location_Buf[14] = GPS.longitude_Second/10 + 0x30; Location_Buf[15] = GPS.longitude_Second%10 + 0x30; // 纬度 Location_Buf[17] = GPS.latitude_Degree/10 + 0x30; Location_Buf[18] = GPS.latitude_Degree%10 + 0x30; Location_Buf[20] = GPS.latitude_Cent/10 + 0x30; Location_Buf[21] = GPS.latitude_Cent%10 + 0x30; Location_Buf[23] = GPS.latitude_Second/10 + 0x30; Location_Buf[24] = GPS.latitude_Second%10 + 0x30; UART1_PC_SendString(Location_Buf); REV_LOC_ASK = 0;}/******************************************************************************** 函数名 : Uart2_BD_Receive* 描述 : 串口2中断服务入口函数,处理BD模块发来的数据*******************************************************************************/void Uart2_BD_Receive(void) interrupt 8{ unsigned char ch; IE2 &= ~0X01; if (S2CON & S2RI) { S2CON &= ~S2RI; //清除S2RI位 ch = S2BUF; if ((ch == 'R') && (BD_FLAG == 0)) //如果收到字符'R',便开始接收 { Uart2_Buf[0] = '$';Uart2_Buf[1] = 'G';Uart2_Buf[2] = 'N'; BD_REV_START = 1; BD_NUM = 3; } if (BD_REV_START == 1) //标志位为1,开始接收 { Uart2_Buf[BD_NUM++] = ch; //字符存到数组中 SBUF=ch; while(TI!=1); //等待发送成功 TI=0; if (ch == '*') //如果接收到*号,说明接收完成。 { Uart2_Buf[BD_NUM] = ' |