主控制器為STM32F103C8T6單片機,GPS模塊為NEO-6M模塊,語音播報模塊是JQ6500;
在GPS獲取到信號的情況下,按下播報按鍵,系統(tǒng)會播報出當前的時間和經(jīng)緯度信息。
附件為完整代碼工程和電路原理圖以及JQ6500模塊資料包。
電路原理圖如下:
51hei.png (24.19 KB, 下載次數(shù): 47)
下載附件
2021-4-24 17:50 上傳
單片機源程序如下:
- /**********************************************************
-
- 接線說明:
- STM32 GPS
- VCC ------> VCC
- GND ------> GND
- RX1 <------ TXD
- STM32 USB-TTL模塊
- GND ------> GND
- TX1 ------> RXD
- ***********************************************************/
- #include "stm32f10x.h"
- #include "delay.h"
- #include "usart.h"
- #include "led.h"
- //聲明
- void errorLog(int num);
- void parseGpsBuffer(void);
- void printGpsBuffer(void);
- void uart2_init(u32 bound);
- u16 get_cmd(char input);
- void Voice_Play(u16 cmd);
- void Voice_GpsBuffer(void);
- void KEY_Init(void);
- #define KEY GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_8)
- int main(void)
- {
- delay_init();
-
- NVIC_Configuration(); //設置NVIC中斷分組2:2位搶占優(yōu)先級,2位響應優(yōu)先級
- uart_init(9600); //串口初始化為9600
- uart2_init(9600);
- KEY_Init();
- delay_init();
- Init_LEDpin();
- LED1 = 1;
-
- clrStruct();
-
- printf("Welcome to use!\r\n");
- printf("ILoveMcu.taobao.com!\r\n");
- while(1)
- {
- parseGpsBuffer();
- Voice_GpsBuffer();
- printGpsBuffer();
-
-
- }
- }
- void errorLog(int num)
- {
-
- while (1)
- {
- printf("ERROR%d\r\n",num);
- }
- }
- void parseGpsBuffer()
- {
- char *subString;
- char *subStringNext;
- char i = 0;
- if (Save_Data.isGetData)
- {
- Save_Data.isGetData = false;
- printf("**************\r\n");
- printf(Save_Data.GPS_Buffer);
-
- for (i = 0 ; i <= 6 ; i++)
- {
- if (i == 0)
- {
- if ((subString = strstr(Save_Data.GPS_Buffer, ",")) == NULL)
- errorLog(1); //解析錯誤
- }
- else
- {
- subString++;
- if ((subStringNext = strstr(subString, ",")) != NULL)
- {
- char usefullBuffer[2];
- switch(i)
- {
- case 1:memcpy(Save_Data.UTCTime, subString, subStringNext - subString);break; //獲取UTC時間
- case 2:memcpy(usefullBuffer, subString, subStringNext - subString);break; //獲取UTC時間
- case 3:memcpy(Save_Data.latitude, subString, subStringNext - subString);break; //獲取緯度信息
- case 4:memcpy(Save_Data.N_S, subString, subStringNext - subString);break; //獲取N/S
- case 5:memcpy(Save_Data.longitude, subString, subStringNext - subString);break; //獲取經(jīng)度信息
- case 6:memcpy(Save_Data.E_W, subString, subStringNext - subString);break; //獲取E/W
- default:break;
- }
- subString = subStringNext;
- Save_Data.isParseData = true;
- if(usefullBuffer[0] == 'A')
- Save_Data.isUsefull = true;
- else if(usefullBuffer[0] == 'V')
- Save_Data.isUsefull = false;
- }
- else
- {
- errorLog(2); //解析錯誤
- }
- }
- }
- }
- }
- void printGpsBuffer()
- {
- if (Save_Data.isParseData)
- {
- Save_Data.isParseData = false;
-
- printf("Save_Data.UTCTime = ");//當前時間
- printf(Save_Data.UTCTime);
- printf("\r\n");
- if(Save_Data.isUsefull)
- {
- Save_Data.isUsefull = false;
- printf("Save_Data.latitude = ");//緯度,范圍0-90
- printf(Save_Data.latitude);
- // printf("*************************");
- // printf("\r\n");
- // printf("%c",Save_Data.latitude[0]);
- // printf("\r\n");
- // printf("%c",Save_Data.latitude[1]);
- // printf("\r\n");
- // printf("%c",Save_Data.latitude[2]);
- // printf("\r\n");
- // printf("%c",Save_Data.latitude[3]);
- printf("\r\n");
- printf("*************************");
- printf("\r\n");
- printf("Save_Data.N_S = ");
- printf(Save_Data.N_S);
- printf("\r\n");
- printf("Save_Data.longitude = "); //經(jīng)度 ,范圍0-180
- printf(Save_Data.longitude);
- printf("\r\n");
- printf("Save_Data.E_W = ");
- printf(Save_Data.E_W);
- printf("\r\n");
- }
- else
- {
- printf("GPS DATA is not usefull!\r\n");
- }
-
- }
- }
- u16 get_cmd(char input)
- {
- u16 CMD;
- switch(input)
- {
- case 0:
- CMD = 0x11;
- break;
- case 1:
- CMD = 0x01;
- break;
- case 2:
- CMD = 0x02;
- break;
- case 3:
- CMD = 0x03;
- break;
- case 4:
- CMD = 0x04;
- break;
- case 5:
- CMD = 0x05;
- break;
- case 6:
- CMD = 0x06;
- break;
- case 7:
- CMD = 0x07;
- break;
- case 8:
- CMD = 0x08;
- break;
- case 9:
- CMD = 0x09;
- break;
- }
- return CMD;
- }
- void Voice_GpsBuffer(void)
- {
- u16 cmd_voice;
- if(KEY==0)
- {
- delay_ms(10);
- if(KEY==0)
- {
- Voice_Play(0x0a); //當前時間為
- delay_ms(1000);
- delay_ms(1000);
- delay_ms(1000);
- cmd_voice=get_cmd(Save_Data.UTCTime[0]);
- printf("cmd_voice : %02x",cmd_voice&0x0f);
- printf("\r\n");
- Voice_Play(cmd_voice&0x0f);
- delay_ms(500);
- cmd_voice=get_cmd(Save_Data.UTCTime[1]);
- printf("cmd_voice : %02x",cmd_voice&0x0f);
- printf("\r\n");
- Voice_Play(cmd_voice&0x0f);
- delay_ms(500);
- Voice_Play(0x0b); //點
- delay_ms(500);
- cmd_voice=get_cmd(Save_Data.UTCTime[2]);
- printf("cmd_voice : %02x",cmd_voice&0x0f);
- printf("\r\n");
- Voice_Play(cmd_voice&0x0f);
- delay_ms(500);
- cmd_voice=get_cmd(Save_Data.UTCTime[3]);
- printf("cmd_voice : %02x",cmd_voice&0x0f);
- printf("\r\n");
- Voice_Play(cmd_voice&0x0f);
- delay_ms(500);
- Voice_Play(0x0c); //分
- delay_ms(500);
-
- Voice_Play(0x0d); //當前位置經(jīng)度為
- delay_ms(1000);
- delay_ms(1000);
- delay_ms(1000);
- cmd_voice=get_cmd(Save_Data.longitude[0]);
- printf("cmd_voice : %02x",cmd_voice&0x0f);
- printf("\r\n");
- Voice_Play(cmd_voice&0x0f);
- delay_ms(500);
- cmd_voice=get_cmd(Save_Data.longitude[1]);
- printf("cmd_voice : %02x",cmd_voice&0x0f);
- printf("\r\n");
- Voice_Play(cmd_voice&0x0f);
- delay_ms(500);
- cmd_voice=get_cmd(Save_Data.longitude[2]);
- printf("cmd_voice : %02x",cmd_voice&0x0f);
- printf("\r\n");
- Voice_Play(cmd_voice&0x0f);
- delay_ms(500);
- Voice_Play(0x0f); //度
- delay_ms(500);
- cmd_voice=get_cmd(Save_Data.longitude[3]);
- printf("cmd_voice : %02x",cmd_voice&0x0f);
- printf("\r\n");
- Voice_Play(cmd_voice&0x0f);
- delay_ms(500);
- cmd_voice=get_cmd(Save_Data.longitude[4]);
- printf("cmd_voice : %02x",cmd_voice&0x0f);
- printf("\r\n");
- Voice_Play(cmd_voice&0x0f);
- delay_ms(500);
- Voice_Play(0x0c); //分
- delay_ms(500);
-
- Voice_Play(0x0e); //當前位置緯度為
- delay_ms(1000);
- delay_ms(1000);
- delay_ms(1000);
- cmd_voice=get_cmd(Save_Data.latitude[0]);
- printf("cmd_voice : %02x",cmd_voice&0x0f);
- printf("\r\n");
- Voice_Play(cmd_voice&0x0f);
- delay_ms(500);
- cmd_voice=get_cmd(Save_Data.latitude[1]);
- printf("cmd_voice : %02x",cmd_voice&0x0f);
- printf("\r\n");
- Voice_Play(cmd_voice&0x0f);
- delay_ms(500);
- Voice_Play(0x0f); //度
- delay_ms(500);
- cmd_voice=get_cmd(Save_Data.latitude[2]);
- printf("cmd_voice : %02x",cmd_voice&0x0f);
- printf("\r\n");
- Voice_Play(cmd_voice&0x0f);
- delay_ms(500);
- cmd_voice=get_cmd(Save_Data.latitude[3]);
- printf("cmd_voice : %02x",cmd_voice&0x0f);
- printf("\r\n");
- Voice_Play(cmd_voice&0x0f);
- delay_ms(500);
- Voice_Play(0x0c); //分
- delay_ms(500);
- }
- }
- }
- void KEY_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//??PORTA,PORTC??
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;//PA15
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //???????
- GPIO_Init(GPIOA, &GPIO_InitStructure);//???GPIOA15
- }
- void uart2_init(u32 bound){
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
- //USART2_TX
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- //USART2_RX
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- USART_InitStructure.USART_BaudRate = bound;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- USART_Init(USART2, &USART_InitStructure);
- // USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
- USART_Cmd(USART2, ENABLE);
- }
- // 7e 04 03 00 cmd ef
- void Voice_Play(u16 cmd)
- {
- USART_SendData(USART2,0x7E);
- delay_ms(1);
- USART_SendData(USART2,0x04);
- delay_ms(1);
- USART_SendData(USART2,0x03);
- delay_ms(1);
- USART_SendData(USART2,0x00);
- delay_ms(1);
- USART_SendData(USART2,cmd);
- delay_ms(1);
- USART_SendData(USART2,0xEF);
- delay_ms(1);
- }
復制代碼
51hei.png (2.76 KB, 下載次數(shù): 46)
下載附件
2021-4-24 17:50 上傳
51hei.png (10.8 KB, 下載次數(shù): 53)
下載附件
2021-4-24 17:50 上傳
所有資料51hei提供下載:
STM32-GPS位置信息語音播報.7z
(7.66 MB, 下載次數(shù): 103)
2021-4-24 17:51 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|