久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標(biāo)題:
51單片機(jī)藍(lán)牙智能小車源碼
[打印本頁]
作者:
YLX
時間:
2017-11-27 16:02
標(biāo)題:
51單片機(jī)藍(lán)牙智能小車源碼
代碼附上來了
前燈 PB12
右燈pb13
zuo pb14
蜂鳴器 PB15
/*
硬件鏈接:
左電機(jī)控制端口:PA3、PA4
右電機(jī)控制端口: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);
}
//前進(jìn)子程序
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)向燈
}
//前進(jì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)向燈
}
//前進(jì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)向燈
}
//前進(jì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)向燈
}
//前進(jì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)向燈
}
//前進(jì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)//如果是就前進(jìn)
go1();
if(a==0x16||a==0x17||a==0x56||a==0x57||a==0x66||a==0x67)//如果是就前進(jìn)
go2();
if(a==0x18||a==0x19||a==0x58||a==0x59||a==0x68||a==0x69)//如果是就前進(jìn)
go3();
if(a==0x1a||a==0x1b||a==0x5a||a==0x5b||a==0x6a||a==0x6b)//如果是就前進(jìn)
go4();
if(a==0x1c||a==0x1d||a==0x5c||a==0x5d||a==0x6c||a==0x6d)//如果是就前進(jìn)
go5();
if(a==0x1e||a==0x1f||a==0x5e||a==0x5f||a==0x6e||a==0x6f)//如果是就前進(jìn)
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= ;//讀取單片機(jī)串口接受的藍(lán)牙模塊發(fā)送的數(shù)據(jù)
a = DataToSend;
}
/*
硬件鏈接:
左電機(jī)控制端口:PA3、PA4
右電機(jī)控制端口: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);
}
//前進(jìn)子程序
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)向燈
}
//前進(jì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)向燈
}
//前進(jì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)向燈
}
//前進(jì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)向燈
}
//前進(jì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)向燈
}
//前進(jì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)//如果是就前進(jìn)
go1();
if(a==0x16||a==0x17||a==0x56||a==0x57||a==0x66||a==0x67)//如果是就前進(jìn)
go2();
if(a==0x18||a==0x19||a==0x58||a==0x59||a==0x68||a==0x69)//如果是就前進(jìn)
go3();
if(a==0x1a||a==0x1b||a==0x5a||a==0x5b||a==0x6a||a==0x6b)//如果是就前進(jìn)
go4();
if(a==0x1c||a==0x1d||a==0x5c||a==0x5d||a==0x6c||a==0x6d)//如果是就前進(jìn)
go5();
if(a==0x1e||a==0x1f||a==0x5e||a==0x5f||a==0x6e||a==0x6f)//如果是就前進(jìn)
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= ;//讀取單片機(jī)串口接受的藍(lán)牙模塊發(fā)送的數(shù)據(jù)
a = DataToSend;
}
復(fù)制代碼
歡迎光臨 (http://www.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
日韩不卡一区二区三区
|
中文一区
|
91视频免费在观看
|
亚洲精品一区中文字幕乱码
|
国产精品99视频
|
日韩三级精品
|
中文字幕欧美一区二区
|
久久精品视频9
|
日韩影院在线
|
久久成人国产精品
|
亚洲久久一区
|
久久久久国产一区二区三区
|
aa级毛片毛片免费观看久
|
成人在线观看免费视频
|
亚洲成人精品久久
|
日韩av在线中文字幕
|
一区观看
|
每日更新av
|
日韩无
|
国产精品久久久久久久久免费樱桃
|
夜夜操av
|
国产高清一区二区三区
|
免费在线h视频
|
久久成人国产精品
|
美日韩免费
|
亚洲午夜精品在线观看
|
亚洲欧美在线观看
|
日韩欧美视频
|
欧美中文在线
|
国产福利在线视频
|
一区二区免费在线观看
|
天天干天天操天天爽
|
天堂av在线影院
|
欧美日韩成人在线
|
91亚洲国产成人精品一区二三
|
国产欧美精品在线观看
|
7799精品视频天天看
|
国产精品视频网
|
精品美女
|
美国十次成人欧美色导视频
|
国产在线资源
|