小白从零开始:小程序阿里云平台控制STM32-GPS经纬度显示(软件篇二)
小白从零开始:小程序阿里云平台控制stm32温湿度光照强度(软件篇)
【DIY】stm32f103c8t6+mqtt阿里云+小程序+n多外设
使用工具:
硬件:
PCB设计: 立创EDA+嘉立创
硬件外设:STM32F103C8T6最小系统+dht11+bh1750+mq2+mq7+gps+0.96oled+蓝牙hc06+esp8266-01s
设计出来的总体是这样
提示:以下是本篇文章正文内容,下面案例可供参考
首先将GPS的波特率调到我们所需波特率,一般为115200。
GPS资料包在这里!!!!!!!!
0.96OLED显示模块驱动部分代码
将OLED初始化
void OLED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE); //ʹÄÜB¶Ë¿ÚʱÖÓ
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//ËÙ¶È50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); //³õʼ»¯GPIOB8,9
GPIO_SetBits(GPIOB,GPIO_Pin_8|GPIO_Pin_9);
Delay_Ms(800);
OLED_WR_Byte(0xAE,OLED_CMD);//--display off
OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
OLED_WR_Byte(0x40,OLED_CMD);//--set start line address
OLED_WR_Byte(0xB0,OLED_CMD);//--set page address
OLED_WR_Byte(0x81,OLED_CMD); // contract control
OLED_WR_Byte(0xFF,OLED_CMD);//--128
OLED_WR_Byte(0xA1,OLED_CMD);//set segment remap
OLED_WR_Byte(0xA6,OLED_CMD);//--normal / reverse
OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
OLED_WR_Byte(0x3F,OLED_CMD);//--1/32 duty
OLED_WR_Byte(0xC8,OLED_CMD);//Com scan direction
OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset
OLED_WR_Byte(0x00,OLED_CMD);//
OLED_WR_Byte(0xD5,OLED_CMD);//set osc division
OLED_WR_Byte(0x80,OLED_CMD);//
OLED_WR_Byte(0xD8,OLED_CMD);//set area color mode off
OLED_WR_Byte(0x05,OLED_CMD);//
OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period
OLED_WR_Byte(0xF1,OLED_CMD);//
OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion
OLED_WR_Byte(0x12,OLED_CMD);//
OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh
OLED_WR_Byte(0x30,OLED_CMD);//
OLED_WR_Byte(0x8D,OLED_CMD);//set charge pump enable
OLED_WR_Byte(0x14,OLED_CMD);//
OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
}
GPS模块驱动代码
void USART1_IRQHandler(void) //´®¿Ú1ÖжϷþÎñ³ÌÐò
{
// char temp;
u8 Res;
if( USART_GetITStatus( USART1, USART_IT_RXNE) != RESET)
{
// temp = USART_ReceiveData( USART1);
Res = USART_ReceiveData( USART1);
if(Res == '$')
{
point1 = 0;
}
Usart1_RxBuff[point1++] = Res;
if(Usart1_RxBuff[0] == '$' && Usart1_RxBuff[4] == 'M' && Usart1_RxBuff[5] == 'C') //È·¶¨ÊÇ·ñÊÕµ½"GPRMC/GNRMC"ÕâÒ»Ö¡Êý¾Ý
{
if(Res == '\n')
{
memset(Save_Data.GPS_Buffer, 0, GPS_Buffer_Length); //Çå¿Õ
memcpy(Save_Data.GPS_Buffer, Usart1_RxBuff, point1); //±£´æÊý¾Ý
Save_Data.isGetData = true;
point1 = 0;
memset(Usart1_RxBuff, 0, USART1_RXBUFF_SIZE); //Çå¿Õ
}
}
if(point1 >= USART1_RXBUFF_SIZE)
{
point1 = USART1_RXBUFF_SIZE;
}
}
#if SYSTEM_SUPPORT_OS //Èç¹ûSYSTEM_SUPPORT_OSΪÕ棬ÔòÐèÒªÖ§³ÖOS.
OSIntExit();
#endif
}
u8 Hand(char *a) // ´®¿ÚÃüÁîʶ±ðº¯Êý
{
if(strstr(Usart1_RxBuff,a)!=NULL)
return 1;
else
return 0;
}
void CLR_Buf(void) // ´®¿Ú»º´æÇåÀí
{
memset(Usart1_RxBuff, 0, USART1_RXBUFF_SIZE); //Çå¿Õ
point1 = 0;
}
void clrStruct()
{
Save_Data.isGetData = false;
Save_Data.isParseData = false;
Save_Data.isUsefull = false;
memset(Save_Data.GPS_Buffer, 0, GPS_Buffer_Length); //Çå¿Õ
memset(Save_Data.UTCTime, 0, UTCTime_Length);
memset(Save_Data.latitude, 0, latitude_Length);
memset(Save_Data.N_S, 0, N_S_Length);
memset(Save_Data.longitude, 0, longitude_Length);
memset(Save_Data.E_W, 0, E_W_Length);
}
extern u8 KEY;
int receive_data[10];
本文仅仅简单介绍了软件驱动方面的配置,评论区欢迎讨论。GPS模块的资料包在文中通过CSDN积分下载即可。