|
|
|
|
#include "stm32f10x.h"
|
|
|
|
|
#include "bluetooth.h"
|
|
|
|
|
#include "sys.h"
|
|
|
|
|
|
|
|
|
|
u8 i;
|
|
|
|
|
int flag; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
|
|
|
|
|
char flag2='W'; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ2
|
|
|
|
|
int speed=75;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>speed PWMռ<EFBFBD>ձ<EFBFBD>
|
|
|
|
|
void USART2_IRQHandler(void)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
if(USART_GetITStatus(USART2, USART_IT_RXNE) == SET) //USART2 <EFBFBD>жϷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
USART_ClearITPendingBit(USART2, USART_IT_RXNE); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
|
|
|
|
|
i= USART_ReceiveData(USART2); //<EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(i=='0')
|
|
|
|
|
{ flag=0;}
|
|
|
|
|
if(i=='1')
|
|
|
|
|
{ flag=1;}
|
|
|
|
|
if(i=='2')
|
|
|
|
|
{ flag=2;}
|
|
|
|
|
if(i=='3')
|
|
|
|
|
{ flag=3;}
|
|
|
|
|
if(i=='4')
|
|
|
|
|
{ flag=4;} //<EFBFBD>ƶ<EFBFBD>ָ<EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
if(i=='W')
|
|
|
|
|
{ flag2='W';}
|
|
|
|
|
if(i=='B')
|
|
|
|
|
{ flag2='B';}
|
|
|
|
|
if(i=='U')
|
|
|
|
|
{ flag2='U';} //״ָ̬<EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
if(i=='H')
|
|
|
|
|
{ speed=100;
|
|
|
|
|
TIM_SetCompare1(TIM1,speed);
|
|
|
|
|
TIM_SetCompare4(TIM1,speed);}
|
|
|
|
|
if(i=='L')
|
|
|
|
|
{ speed=75;
|
|
|
|
|
TIM_SetCompare1(TIM1,speed);
|
|
|
|
|
TIM_SetCompare4(TIM1,speed);} //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
if(i=='J')
|
|
|
|
|
{ PAout(5)=!PAout(5);} //<EFBFBD>̵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BluetoothInit(void)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>շ<EFBFBD>
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
|
USART_InitTypeDef USART_InitStructure;
|
|
|
|
|
NVIC_InitTypeDef NVIC_InitStructure;
|
|
|
|
|
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE );
|
|
|
|
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE );//ʹ<EFBFBD><EFBFBD>USART3<EFBFBD><EFBFBD>GPIOCʱ<EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
//USART1_TX PA2
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA2
|
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
GPIO_Init(GPIOA, &GPIO_InitStructure); //<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>PA2
|
|
|
|
|
|
|
|
|
|
//USART1_RX PA3
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
|
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
GPIO_Init(GPIOA, &GPIO_InitStructure); //<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>PA3
|
|
|
|
|
|
|
|
|
|
//GPIO_PinRemapConfig(GPIO_PartialRemap_USART3,ENABLE);
|
|
|
|
|
|
|
|
|
|
USART_InitStructure.USART_BaudRate = 38400;
|
|
|
|
|
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(USART2, USART_IT_RXNE, ENABLE);//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|
|
|
|
|
|
|
|
|
//Usart1 NVIC <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;//<EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>
|
|
|
|
|
NVIC_Init(&NVIC_InitStructure); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>VIC<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
USART_Cmd(USART2, ENABLE); //ʹ<EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|