主控制器为STM32F103C8T6单片机,GPS模块为NEO-6M模块,语音播报模块是JQ6500;
在GPS获取到信号的情况下,按下播报按键,系统会播报出当前的时间和经纬度信息。
附件为完整代码工程和电路原理图以及JQ6500模块资料包。
电路原理图如下:
单片机源程序如下:
- /**********************************************************
-
- 接线说明:
- 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位抢占优先级,2位响应优先级
- 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; //获取经度信息
- 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 = "); //经度 ,范围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); //当前位置经度为
- 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提供下载:
STM32-GPS位置信息语音播报.7z
(7.66 MB, 下载次数: 103)
|