|
我最近暑假得空做一下智能小車,這個(gè)藍(lán)牙控制是其中一部分,后面我會(huì)再添加oled,wifi和語(yǔ)音等模塊
帖子里面包括主函數(shù)和藍(lán)牙的部分代碼,整個(gè)工程詳細(xì)代碼我放在附件里面,你們有需要可以下載。里面代碼親試有效,有疑問(wèn)歡迎來(lái)我帖子下面留言,我會(huì)一一回復(fù)的。
- #include "led.h"
- #include "delay.h"
- #include "sys.h"
- #include "pwm.h"
- #include "Motor.h"
- #include "key.h"
- #include "BlueTooth.h"
- #include "Engine.h"
- #include "ultrasonic.h"
- int main(void)
- {
- Motor_Init(); //電機(jī)初始化
- delay_init();
- time3_initer(65535,7); //pwm初始化
- BlueBooth_Init(); //藍(lán)牙初始化
- sg90_Init(); //舵機(jī)初始化
- Wave_IO_Init(); //超聲波初始化
- while(1)
- {
復(fù)制代碼 藍(lán)牙初始化代碼
- #include "BlueTooth.h"
- #include "stm32f10x.h"
- #include "motor.h"
- #include "pwm.h"
- #include "Engine.h"
- #include "ultrasonic.h"
- #ifdef __GNUC__
- /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
- set to 'Yes') calls __io_putchar() */
- #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
- #else
- #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
- #endif /* __GNUC__ */
- u8 flag,i;
- void BlueBooth_Init(void) //藍(lán)牙初始化
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);
-
- // USART_DeInit(USART1);
- // USART1_TX PA.9 //串口發(fā)送
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //推挽輸出
- GPIO_Init(GPIOA, &GPIO_InitStructure); //gpio初始化
-
- //USART1_RX PA.10 //串口接收
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空輸入
- GPIO_Init(GPIOA, &GPIO_InitStructure); //gpio初始化
- USART_InitStructure.USART_BaudRate = 9600; //串口波特率
-
- USART_InitStructure.USART_WordLength = USART_WordLength_8b; //字長(zhǎng)為8位數(shù)據(jù)格式
- USART_InitStructure.USART_StopBits = USART_StopBits_1; //一位停止位
- USART_InitStructure.USART_Parity = USART_Parity_No; //無(wú)奇偶校驗(yàn)和
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //無(wú)硬件數(shù)據(jù)流控制
- USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收發(fā)模式
- USART_Init(USART1, &USART_InitStructure); //串口1初始化
- USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //開(kāi)始串口接收中斷
- //Usart1 NVIC
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //分組0
- NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//3位搶占優(yōu)先級(jí)
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //3位子優(yōu)先級(jí)
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ中斷使能
- NVIC_Init(&NVIC_InitStructure); //NVIC初始化
-
- USART_Cmd(USART1, ENABLE); //串口初始化
復(fù)制代碼
下面這個(gè)是我上一篇帖子,里面是超聲波加舵機(jī)的測(cè)距代碼,里面有詳細(xì)工程,你們也可以看一下
http://www.torrancerestoration.com/bbs/dpj-210799-1.html
|
評(píng)分
-
查看全部評(píng)分
|