标题: STM8L0单片机+L76C GPS+DMA+串口源程序 [打印本页]

作者: 小提莫真可爱    时间: 2020-11-18 16:04
标题: STM8L0单片机+L76C GPS+DMA+串口源程序
本程序用于太阳能同步雾灯,可通过DMA+USART1接收移远GPS模块(L76C)实现同步闪烁。

单片机源程序如下:
  1. #include "stm8l15x.h"
  2. #include "led.h"
  3. #include "lamp.h"
  4. #include "adc.h"
  5. #include "usart1.h"
  6. #include "timer.h"
  7. #include "switch.h"
  8. #include "gps.h"
  9. #include "dma.h"

  10. void main()
  11. {
  12.   disableInterrupts();   //关闭系统总中断
  13.   CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); //内部时钟为1分频 = 16Mhz
  14.   
  15.   LEDInit();
  16.   LAMPInit();
  17.   SWITCHInit();
  18.   ADCInit();
  19.   USART1Init(9600);
  20.   DMAInit();
  21.   GPSInit();
  22.   TIM4_Init();   //调用定时器4初始化函数
  23.   enableInterrupts();   //使能系统总中断

  24.   while(1)
  25.   {  
  26.     AdcHandler(); //AD采样
  27.     GPSHandler(); //GPS数据解析
  28.   }   
  29. }
复制代码

#include "GPS.h"

void GPSInit(void)
{
  L76C_CFG_GGA(0);//关闭GGA
  L76C_CFG_GLL(0);//关闭GLL
  L76C_CFG_GSA(0);//关闭GSA
  L76C_CFG_GSV(0);//关闭GSV
  L76C_CFG_RMC(0);//关闭RMC
  L76C_CFG_VTG(0);//关闭VTG
  L76C_CFG_ZDA(5);//ZDA数据5秒发送一次
  L76C_CFG_GST(0);//关闭GST
  L76C_CFG_SAVE();//保存配置信息
}

void L76C_CFG_GGA(unsigned char temp)
{
  unsigned char tempBuf[15]={'$','C','F','G','M','S','G',',','0',',','0',',','0',0x0A,0x0D};
  if(temp!=0)
  {
    tempBuf[12]=temp;
  }
  
  Uart1_SendString(tempBuf,15);
}

void L76C_CFG_GLL(unsigned char temp)
{
  unsigned char tempBuf[15]={'$','C','F','G','M','S','G',',','1',',','0',',','0',0x0A,0x0D};
  if(temp!=0)
  {
    tempBuf[12]=temp;
  }
  
  Uart1_SendString(tempBuf,15);
}

void L76C_CFG_GSA(unsigned char temp)
{
  unsigned char tempBuf[15]={'$','C','F','G','M','S','G',',','2',',','0',',','0',0x0A,0x0D};
  if(temp!=0)
  {
    tempBuf[12]=temp;
  }
  
  Uart1_SendString(tempBuf,15);
}

void L76C_CFG_GSV(unsigned char temp)
{
  unsigned char tempBuf[15]={'$','C','F','G','M','S','G',',','3',',','0',',','0',0x0A,0x0D};
  if(temp!=0)
  {
    tempBuf[12]=temp;
  }
  
  Uart1_SendString(tempBuf,15);
}

void L76C_CFG_RMC(unsigned char temp)
{
  unsigned char tempBuf[15]={'$','C','F','G','M','S','G',',','4',',','0',',','0',0x0A,0x0D};
  if(temp!=0)
  {
    tempBuf[12]=temp;
  }
  
  Uart1_SendString(tempBuf,15);
}

void L76C_CFG_VTG(unsigned char temp)
{
  unsigned char tempBuf[15]={'$','C','F','G','M','S','G',',','5',',','0',',','0',0x0A,0x0D};
  if(temp!=0)
  {
    tempBuf[12]=temp;
  }
  
  Uart1_SendString(tempBuf,15);
}

void L76C_CFG_ZDA(unsigned char temp)
{
  unsigned char tempBuf[15]={'$','C','F','G','M','S','G',',','6',',','0',',','0',0x0A,0x0D};
  if(temp!=0)
  {
    tempBuf[12]=temp;
  }
  
  Uart1_SendString(tempBuf,15);
}

void L76C_CFG_GST(unsigned char temp)
{
  unsigned char tempBuf[15]={'$','C','F','G','M','S','G',',','7',',','0',',','0',0x0A,0x0D};
  if(temp!=0)
  {
    tempBuf[12]=temp;
  }
  
  Uart1_SendString(tempBuf,15);
}

void L76C_CFG_SAVE(void)
{
  unsigned char tempBuf[14]={'$','C','F','G','S','A','V','E',',','h','0','F',0x0A,0x0D};
  
  Uart1_SendString(tempBuf,14);
}


所有资料51hei提供下载:
GPS.7z (810.72 KB, 下载次数: 32)
L76-C.7z (2.31 MB, 下载次数: 28)







欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1