中电网移动|移动中电网|高清图滚动区

基于51的单片机GPS定位系统设计

一.硬件方案

本设计主要是制作出一款基于51单片机的GPS定位器,根据设计需求,硬件部分主要由51单片机+GPS定位模块+LCD12864液晶+LED指示灯+3.3V稳压电路+天线设计而成;如图:

二.设计功能

(1)单片机选用:51单片机(STC89C51/52、AT89C51/52、AT90C51/52均可兼容),GPS定位模块(带天线)。
(2)采用LCD12864液晶显示当前的时间、日期、经度、速度、航向、高度、海拔等信息。
(3)采用了3颗LED指示灯,红灯为GPS接收数据指示灯,黄灯为GPRNC数据有效指示灯,绿灯为GPGGA数据有效指示灯。

三.设计原理图

(1)原理图主要采用AD软件进行设计,如图:

(2)PCB图如下:

四.软件设计

主程序源码

/****************************************
主函数    
/****************************************/
void main(void)
{
      uchar error_num = 0;
      Uart_Init();  //初始化串口
      Lcd_Init();       //初始化LCD
      GPS_Init();   //初始化GPS
      rev_stop=0;
      REV_NO;
      while(1)
      {
           if (rev_stop)   //如果接收完一行
           {
                 TR0 = 1;   //开启定时器
                 REV_YES;
                 if (change_page % 2 == 1)  //换页
                 {
                      if (GPS_GGA_Parse(rev_buf, &GPS))  //解析GPGGA
                      {
                            GGA_YES;
                            GPS_DisplayTwo();  //显示第二页信息
                            error_num = 0;
                            gps_flag = 0;
                            rev_stop  = 0;
                            REV_NO;
                      }
                      else
                      {
                            error_num++;
                            if (error_num >= 20) //如果数据无效超过20次
                            {
                                  GGA_NO;
                                  error_num = 20;
                                  GPS_Init();     //返回初始化
                            }
                            gps_flag = 0;
                            rev_stop  = 0;
                            REV_NO;
                      }
                 }
                 else
                 {
                      if (GPS_RMC_Parse(rev_buf, &GPS)) //解析GPRMC
                      {
                            RMC_YES;
                            GPS_DisplayOne();   //显示GPS第一页信息
                            error_num = 0;
                            gps_flag = 0;
                            rev_stop  = 0;
                            led1 = 1;  
                      }
                      else
                      {
                            error_num++;
                            if (error_num >= 20) //如果数据无效超过20次
                            {
                                  RMC_NO;
                                  error_num = 20;
                                  GPS_Init();     //返回初始化
                            }
                            gps_flag = 0;
                            rev_stop  = 0;
                            REV_NO;
                      }
                 }
           }
      }
}

猜你喜欢
中电网移动|移动中电网|频道导航区