欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
51單片機藍牙智能小車源碼
[打印本頁]
作者:
YLX
時間:
2017-11-27 16:02
標(biāo)題:
51單片機藍牙智能小車源碼
代碼附上來了
前燈 PB12
右燈pb13
zuo pb14
蜂鳴器 PB15
/*
硬件鏈接:
左電機控制端口:PA3、PA4
右電機控制端口:PA1、PA2
*/
#include "stm32f10x.h"//聲明頭文件
#include "stm32f10x_exti.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_usart.h"
#define uchar unsigned char//宏定義
#define uint unsigned int//宏定義
#define AA 35//左輪速度調(diào)節(jié)值
#define BB 35//右輪速度調(diào)節(jié)值
uchar a=0;//定義一個變量a,用來讀取串口的數(shù)據(jù)
/*有參數(shù)延時函數(shù)*/
void delay(__IO uint32_t nCount)
{
for (; nCount != 0; nCount--);
}
unsigned int temp=0;
unsigned char rebuf[5];
unsigned int start=0;
void GPIO_DengConfiguration()
{
GPIO_InitTypeDef GPIO_InitStructure;
/* 初始化LED的GPIO管腳,配置為推挽輸出 */ //設(shè)置端口
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; //車燈GPIO_Pin12,13,14端口 15蜂鳴器端口
//設(shè)置對端口的模式
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //設(shè)置為 推挽(Push-Pull)輸出
//
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //最大輸出速度為50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
//前進子程序
void go1()
{
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子正轉(zhuǎn)
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //關(guān)閉右邊輪子
delay(500000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//前進子程序
void go2()
{
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子正轉(zhuǎn)
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //關(guān)閉右邊輪子
delay(400000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//前進子程序
void go3()
{
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子正轉(zhuǎn)
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //關(guān)閉右邊輪子
delay(300000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//前進子程序
void go4()
{
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子正轉(zhuǎn)
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //關(guān)閉右邊輪子
delay(200000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//前進子程序
void go5()
{
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子正轉(zhuǎn)
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //關(guān)閉右邊輪子
delay(100000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//前進子程序
void go6()
{
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子正轉(zhuǎn)
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //關(guān)閉右邊輪子
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車后退的子程序
void hui1()
{
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_3);
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_1);
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_1); //關(guān)閉右邊輪子
delay(500000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車后退的子程序
void hui2()
{
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_3);
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_1);
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_1); //關(guān)閉右邊輪子
delay(400000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車后退的子程序
void hui3()
{
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_3);
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_1);
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_1); //關(guān)閉右邊輪子
delay(300000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車后退的子程序
void hui4()
{
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_3);
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_1);
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_1); //關(guān)閉右邊輪子
delay(200000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車后退的子程序
void hui5()
{
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_3);
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_1);
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_1); //關(guān)閉右邊輪子
delay(100000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車后退的子程序
void hui6()
{
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_3);
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_1);
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_1); //關(guān)閉右邊輪子
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車左轉(zhuǎn)彎子程序
void turnleft()
{
GPIO_ResetBits(GPIOB,GPIO_Pin_13);//轉(zhuǎn)向燈打開
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子停止
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子停止
delay(250000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車右轉(zhuǎn)彎子程序
void turnright()
{
GPIO_ResetBits(GPIOB,GPIO_Pin_14);//轉(zhuǎn)向燈打開
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子停止
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_ResetBits(GPIOA,GPIO_Pin_2); //右邊輪子正轉(zhuǎn)
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子停止
delay(250000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//停止子程序
void down()
{
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2);
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左右輪全部停止
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
int main()//主程序
{
while(1)//死循環(huán)
{
if(a==0x14||a==0x15||a==0x54||a==0x55||a==0x64||a==0x65)//如果是就前進
go1();
if(a==0x16||a==0x17||a==0x56||a==0x57||a==0x66||a==0x67)//如果是就前進
go2();
if(a==0x18||a==0x19||a==0x58||a==0x59||a==0x68||a==0x69)//如果是就前進
go3();
if(a==0x1a||a==0x1b||a==0x5a||a==0x5b||a==0x6a||a==0x6b)//如果是就前進
go4();
if(a==0x1c||a==0x1d||a==0x5c||a==0x5d||a==0x6c||a==0x6d)//如果是就前進
go5();
if(a==0x1e||a==0x1f||a==0x5e||a==0x5f||a==0x6e||a==0x6f)//如果是就前進
go6();
if(a==0x24||a==0x25||a==0x74||a==0x75||a==0x84||a==0x85)//如果是就后退
hui1();
if(a==0x26||a==0x27||a==0x76||a==0x77||a==0x86||a==0x87)//如果是就后退
hui2();
if(a==0x28||a==0x29||a==0x78||a==0x79||a==0x88||a==0x89)//如果是就后退
hui3();
if(a==0x2a||a==0x2b||a==0x7a||a==0x7b||a==0x8a||a==0x8b)//如果是就后退
hui4();
if(a==0x2c||a==0x2d||a==0x7c||a==0x7d||a==0x8c||a==0x8d)//如果是就后退
hui5();
if(a==0x2e||a==0x2f||a==0x7e||a==0x7d||a==0x8e||a==0x8f)//如果是就后退
hui6();
if(a==0x3f)//如果是0x3f就左轉(zhuǎn)
turnleft();
if(a==0x4f)//如果是0x4f就右轉(zhuǎn)
turnright();
if(a==0x00)//如果是0x00就停止
down();
if(a==0xa0)//如果是0xa0車燈打開
GPIO_ResetBits(GPIOB,GPIO_Pin_12); //打開轉(zhuǎn)向燈
if(a==0xb0)//如果是0xb0車燈關(guān)閉
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
if(a==0xc0)//如果是0xc0蜂鳴器鳴響
GPIO_ResetBits(GPIOB,GPIO_Pin_15); //打開蜂鳴器
if(a==0xd0)//如果是0xd0蜂鳴器關(guān)
GPIO_SetBits(GPIOB,GPIO_Pin_15); //關(guān)閉蜂鳴器
else
down();
}
}
void (unsigned char DataToSend) //串口中斷服務(wù)程序
{
// USART_SendData(USART1, (unsigned char) DataToSend);
// a= ;//讀取單片機串口接受的藍牙模塊發(fā)送的數(shù)據(jù)
a = DataToSend;
}
/*
硬件鏈接:
左電機控制端口:PA3、PA4
右電機控制端口:PA1、PA2
*/
#include "stm32f10x.h"//聲明頭文件
#include "stm32f10x_exti.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_usart.h"
#define uchar unsigned char//宏定義
#define uint unsigned int//宏定義
#define AA 35//左輪速度調(diào)節(jié)值
#define BB 35//右輪速度調(diào)節(jié)值
uchar a=0;//定義一個變量a,用來讀取串口的數(shù)據(jù)
/*有參數(shù)延時函數(shù)*/
void delay(__IO uint32_t nCount)
{
for (; nCount != 0; nCount--);
}
unsigned int temp=0;
unsigned char rebuf[5];
unsigned int start=0;
void GPIO_DengConfiguration()
{
GPIO_InitTypeDef GPIO_InitStructure;
/* 初始化LED的GPIO管腳,配置為推挽輸出 */ //設(shè)置端口
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; //車燈GPIO_Pin12,13,14端口 15蜂鳴器端口
//設(shè)置對端口的模式
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //設(shè)置為 推挽(Push-Pull)輸出
//
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //最大輸出速度為50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
//前進子程序
void go1()
{
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子正轉(zhuǎn)
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //關(guān)閉右邊輪子
delay(500000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//前進子程序
void go2()
{
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子正轉(zhuǎn)
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //關(guān)閉右邊輪子
delay(400000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//前進子程序
void go3()
{
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子正轉(zhuǎn)
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //關(guān)閉右邊輪子
delay(300000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//前進子程序
void go4()
{
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子正轉(zhuǎn)
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //關(guān)閉右邊輪子
delay(200000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//前進子程序
void go5()
{
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子正轉(zhuǎn)
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //關(guān)閉右邊輪子
delay(100000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//前進子程序
void go6()
{
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子正轉(zhuǎn)
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //關(guān)閉右邊輪子
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車后退的子程序
void hui1()
{
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_3);
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_1);
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_1); //關(guān)閉右邊輪子
delay(500000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車后退的子程序
void hui2()
{
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_3);
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_1);
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_1); //關(guān)閉右邊輪子
delay(400000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車后退的子程序
void hui3()
{
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_3);
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_1);
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_1); //關(guān)閉右邊輪子
delay(300000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車后退的子程序
void hui4()
{
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_3);
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_1);
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_1); //關(guān)閉右邊輪子
delay(200000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車后退的子程序
void hui5()
{
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_3);
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_1);
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_1); //關(guān)閉右邊輪子
delay(100000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車后退的子程序
void hui6()
{
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_3);
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子倒轉(zhuǎn)
GPIO_ResetBits(GPIOA,GPIO_Pin_1);
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_1); //關(guān)閉右邊輪子
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車左轉(zhuǎn)彎子程序
void turnleft()
{
GPIO_ResetBits(GPIOB,GPIO_Pin_13);//轉(zhuǎn)向燈打開
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子停止
delay(AA);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子停止
delay(250000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//小車右轉(zhuǎn)彎子程序
void turnright()
{
GPIO_ResetBits(GPIOB,GPIO_Pin_14);//轉(zhuǎn)向燈打開
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左邊輪子停止
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_ResetBits(GPIOA,GPIO_Pin_2); //右邊輪子正轉(zhuǎn)
delay(BB);
GPIO_SetBits(GPIOA,GPIO_Pin_2); //右邊輪子停止
delay(250000);
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
//停止子程序
void down()
{
GPIO_SetBits(GPIOA,GPIO_Pin_1);
GPIO_SetBits(GPIOA,GPIO_Pin_2);
GPIO_SetBits(GPIOA,GPIO_Pin_3);
GPIO_SetBits(GPIOA,GPIO_Pin_4); //左右輪全部停止
GPIO_SetBits(GPIOB,GPIO_Pin_13);
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
}
int main()//主程序
{
while(1)//死循環(huán)
{
if(a==0x14||a==0x15||a==0x54||a==0x55||a==0x64||a==0x65)//如果是就前進
go1();
if(a==0x16||a==0x17||a==0x56||a==0x57||a==0x66||a==0x67)//如果是就前進
go2();
if(a==0x18||a==0x19||a==0x58||a==0x59||a==0x68||a==0x69)//如果是就前進
go3();
if(a==0x1a||a==0x1b||a==0x5a||a==0x5b||a==0x6a||a==0x6b)//如果是就前進
go4();
if(a==0x1c||a==0x1d||a==0x5c||a==0x5d||a==0x6c||a==0x6d)//如果是就前進
go5();
if(a==0x1e||a==0x1f||a==0x5e||a==0x5f||a==0x6e||a==0x6f)//如果是就前進
go6();
if(a==0x24||a==0x25||a==0x74||a==0x75||a==0x84||a==0x85)//如果是就后退
hui1();
if(a==0x26||a==0x27||a==0x76||a==0x77||a==0x86||a==0x87)//如果是就后退
hui2();
if(a==0x28||a==0x29||a==0x78||a==0x79||a==0x88||a==0x89)//如果是就后退
hui3();
if(a==0x2a||a==0x2b||a==0x7a||a==0x7b||a==0x8a||a==0x8b)//如果是就后退
hui4();
if(a==0x2c||a==0x2d||a==0x7c||a==0x7d||a==0x8c||a==0x8d)//如果是就后退
hui5();
if(a==0x2e||a==0x2f||a==0x7e||a==0x7d||a==0x8e||a==0x8f)//如果是就后退
hui6();
if(a==0x3f)//如果是0x3f就左轉(zhuǎn)
turnleft();
if(a==0x4f)//如果是0x4f就右轉(zhuǎn)
turnright();
if(a==0x00)//如果是0x00就停止
down();
if(a==0xa0)//如果是0xa0車燈打開
GPIO_ResetBits(GPIOB,GPIO_Pin_12); //打開轉(zhuǎn)向燈
if(a==0xb0)//如果是0xb0車燈關(guān)閉
GPIO_SetBits(GPIOB,GPIO_Pin_14); //關(guān)閉轉(zhuǎn)向燈
if(a==0xc0)//如果是0xc0蜂鳴器鳴響
GPIO_ResetBits(GPIOB,GPIO_Pin_15); //打開蜂鳴器
if(a==0xd0)//如果是0xd0蜂鳴器關(guān)
GPIO_SetBits(GPIOB,GPIO_Pin_15); //關(guān)閉蜂鳴器
else
down();
}
}
void (unsigned char DataToSend) //串口中斷服務(wù)程序
{
// USART_SendData(USART1, (unsigned char) DataToSend);
// a= ;//讀取單片機串口接受的藍牙模塊發(fā)送的數(shù)據(jù)
a = DataToSend;
}
復(fù)制代碼
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1