本程序用于太陽能同步霧燈,可通過DMA+USART1接收移遠(yuǎn)GPS模塊(L76C)實(shí)現(xiàn)同步閃爍。
單片機(jī)源程序如下:
- #include "stm8l15x.h"
- #include "led.h"
- #include "lamp.h"
- #include "adc.h"
- #include "usart1.h"
- #include "timer.h"
- #include "switch.h"
- #include "gps.h"
- #include "dma.h"
- void main()
- {
- disableInterrupts(); //關(guān)閉系統(tǒng)總中斷
- CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); //內(nèi)部時鐘為1分頻 = 16Mhz
-
- LEDInit();
- LAMPInit();
- SWITCHInit();
- ADCInit();
- USART1Init(9600);
- DMAInit();
- GPSInit();
- TIM4_Init(); //調(diào)用定時器4初始化函數(shù)
- enableInterrupts(); //使能系統(tǒng)總中斷
-
- while(1)
- {
- AdcHandler(); //AD采樣
- GPSHandler(); //GPS數(shù)據(jù)解析
- }
- }
復(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)
2020-11-18 18:45 上傳
點(diǎn)擊文件名下載附件
L76-C.7z
(2.31 MB, 下載次數(shù): 28)
2020-11-18 18:45 上傳
點(diǎn)擊文件名下載附件
|