本程序用于太阳能同步雾灯,可通过DMA+USART1接收移远GPS模块(L76C)实现同步闪烁。
单片机源程序如下:
- #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(); //关闭系统总中断
- CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); //内部时钟为1分频 = 16Mhz
-
- LEDInit();
- LAMPInit();
- SWITCHInit();
- ADCInit();
- USART1Init(9600);
- DMAInit();
- GPSInit();
- TIM4_Init(); //调用定时器4初始化函数
- enableInterrupts(); //使能系统总中断
-
- while(1)
- {
- AdcHandler(); //AD采样
- GPSHandler(); //GPS数据解析
- }
- }
复制代码
#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)
|