標(biāo)題: STM8L0單片機(jī)+L76C GPS+DMA+串口源程序 [打印本頁(yè)]

作者: 小提莫真可愛(ài)    時(shí)間: 2020-11-18 16:04
標(biāo)題: STM8L0單片機(jī)+L76C GPS+DMA+串口源程序
本程序用于太陽(yáng)能同步霧燈,可通過(guò)DMA+USART1接收移遠(yuǎn)GPS模塊(L76C)實(shí)現(xiàn)同步閃爍。

單片機(jī)源程序如下:
  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();   //關(guān)閉系統(tǒng)總中斷
  13.   CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); //內(nèi)部時(shí)鐘為1分頻 = 16Mhz
  14.   
  15.   LEDInit();
  16.   LAMPInit();
  17.   SWITCHInit();
  18.   ADCInit();
  19.   USART1Init(9600);
  20.   DMAInit();
  21.   GPSInit();
  22.   TIM4_Init();   //調(diào)用定時(shí)器4初始化函數(shù)
  23.   enableInterrupts();   //使能系統(tǒng)總中斷

  24.   while(1)
  25.   {  
  26.     AdcHandler(); //AD采樣
  27.     GPSHandler(); //GPS數(shù)據(jù)解析
  28.   }   
  29. }
復(fù)制代碼

#include "GPS.h"

void GPSInit(void)
{
  L76C_CFG_GGA(0);//關(guān)閉GGA
  L76C_CFG_GLL(0);//關(guān)閉GLL
  L76C_CFG_GSA(0);//關(guān)閉GSA
  L76C_CFG_GSV(0);//關(guān)閉GSV
  L76C_CFG_RMC(0);//關(guān)閉RMC
  L76C_CFG_VTG(0);//關(guān)閉VTG
  L76C_CFG_ZDA(5);//ZDA數(shù)據(jù)5秒發(fā)送一次
  L76C_CFG_GST(0);//關(guān)閉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, 下載次數(shù): 32)
L76-C.7z (2.31 MB, 下載次數(shù): 28)







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1