久久久久久久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

  1. /*
  2. 硬件鏈接:
  3. 左電機(jī)控制端口:PA3、PA4
  4. 右電機(jī)控制端口:PA1、PA2            
  5. */

  6. #include "stm32f10x.h"//聲明頭文件
  7. #include "stm32f10x_exti.h"
  8. #include "stm32f10x_gpio.h"
  9. #include "stm32f10x_rcc.h"
  10. #include "stm32f10x_usart.h"


  11. #define uchar unsigned char//宏定義
  12. #define uint unsigned int//宏定義
  13. #define AA 35//左輪速度調(diào)節(jié)值
  14. #define BB 35//右輪速度調(diào)節(jié)值

  15. uchar a=0;//定義一個變量a,用來讀取串口的數(shù)據(jù)

  16. /*有參數(shù)延時函數(shù)*/
  17. void delay(__IO uint32_t nCount)
  18. {
  19.   for (; nCount != 0; nCount--);
  20. }


  21. unsigned int temp=0;
  22. unsigned char rebuf[5];
  23. unsigned int start=0;

  24. void GPIO_DengConfiguration()
  25. {
  26.     GPIO_InitTypeDef  GPIO_InitStructure;

  27.     /* 初始化LED的GPIO管腳,配置為推挽輸出 */         //設(shè)置端口
  28.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;         //車燈GPIO_Pin12,13,14端口 15蜂鳴器端口
  29. //設(shè)置對端口的模式
  30.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;         //設(shè)置為 推挽(Push-Pull)輸出
  31. //
  32.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         //最大輸出速度為50MHz

  33.     GPIO_Init(GPIOB, &GPIO_InitStructure);
  34. }




  35. //前進(jìn)子程序
  36. void go1()         
  37.   {
  38.     GPIO_SetBits(GPIOA,GPIO_Pin_3);
  39. GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
  40. delay(AA);

  41. GPIO_SetBits(GPIOA,GPIO_Pin_4);  //關(guān)閉左邊輪子

  42. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  43. GPIO_SetBits(GPIOA,GPIO_Pin_2);        //右邊輪子正轉(zhuǎn)
  44. delay(BB);

  45. GPIO_SetBits(GPIOA,GPIO_Pin_2);  //關(guān)閉右邊輪子

  46. delay(500000);
  47. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  48. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  49.   }

  50.   
  51. //前進(jìn)子程序
  52. void go2()
  53.   {
  54.     GPIO_SetBits(GPIOA,GPIO_Pin_3);
  55. GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
  56. delay(AA);

  57. GPIO_SetBits(GPIOA,GPIO_Pin_4);  //關(guān)閉左邊輪子

  58. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  59. GPIO_SetBits(GPIOA,GPIO_Pin_2);        //右邊輪子正轉(zhuǎn)
  60. delay(BB);

  61. GPIO_SetBits(GPIOA,GPIO_Pin_2);  //關(guān)閉右邊輪子

  62. delay(400000);
  63. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  64. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  65.   }

  66. //前進(jìn)子程序
  67. void go3()
  68.   {
  69.     GPIO_SetBits(GPIOA,GPIO_Pin_3);
  70. GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
  71. delay(AA);

  72. GPIO_SetBits(GPIOA,GPIO_Pin_4);  //關(guān)閉左邊輪子

  73. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  74. GPIO_SetBits(GPIOA,GPIO_Pin_2);        //右邊輪子正轉(zhuǎn)
  75. delay(BB);

  76. GPIO_SetBits(GPIOA,GPIO_Pin_2);  //關(guān)閉右邊輪子

  77. delay(300000);
  78. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  79. GPIO_SetBits(GPIOB,GPIO_Pin_14);         //關(guān)閉轉(zhuǎn)向燈

  80.   }

  81. //前進(jìn)子程序
  82. void go4()
  83.   {
  84.     GPIO_SetBits(GPIOA,GPIO_Pin_3);
  85. GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
  86. delay(AA);

  87. GPIO_SetBits(GPIOA,GPIO_Pin_4);  //關(guān)閉左邊輪子

  88. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  89. GPIO_SetBits(GPIOA,GPIO_Pin_2);        //右邊輪子正轉(zhuǎn)
  90. delay(BB);

  91. GPIO_SetBits(GPIOA,GPIO_Pin_2);  //關(guān)閉右邊輪子

  92. delay(200000);
  93. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  94. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  95.   }

  96. //前進(jìn)子程序
  97. void go5()
  98.   {
  99.     GPIO_SetBits(GPIOA,GPIO_Pin_3);
  100. GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
  101. delay(AA);

  102. GPIO_SetBits(GPIOA,GPIO_Pin_4);  //關(guān)閉左邊輪子

  103. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  104. GPIO_SetBits(GPIOA,GPIO_Pin_2);        //右邊輪子正轉(zhuǎn)
  105. delay(BB);

  106. GPIO_SetBits(GPIOA,GPIO_Pin_2);  //關(guān)閉右邊輪子

  107. delay(100000);
  108. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  109. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  110.   }


  111. //前進(jìn)子程序
  112. void go6()
  113.   {
  114.     GPIO_SetBits(GPIOA,GPIO_Pin_3);
  115. GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
  116. delay(AA);

  117. GPIO_SetBits(GPIOA,GPIO_Pin_4);  //關(guān)閉左邊輪子

  118. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  119. GPIO_SetBits(GPIOA,GPIO_Pin_2);        //右邊輪子正轉(zhuǎn)
  120. delay(BB);

  121. GPIO_SetBits(GPIOA,GPIO_Pin_2);  //關(guān)閉右邊輪子

  122. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  123. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  124.   }

  125. //小車后退的子程序
  126. void hui1()
  127.    {
  128. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左邊輪子倒轉(zhuǎn)
  129. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  130. delay(AA);

  131. GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子

  132.    GPIO_SetBits(GPIOA,GPIO_Pin_2);         //右邊輪子倒轉(zhuǎn)
  133. GPIO_ResetBits(GPIOA,GPIO_Pin_1);         
  134. delay(BB);

  135.    GPIO_SetBits(GPIOA,GPIO_Pin_1);  //關(guān)閉右邊輪子
  136.    delay(500000);

  137.            GPIO_SetBits(GPIOB,GPIO_Pin_13);
  138. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  139.    }

  140. //小車后退的子程序
  141. void hui2()
  142.    {
  143. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左邊輪子倒轉(zhuǎn)
  144. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  145. delay(AA);

  146. GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子

  147.    GPIO_SetBits(GPIOA,GPIO_Pin_2);         //右邊輪子倒轉(zhuǎn)
  148. GPIO_ResetBits(GPIOA,GPIO_Pin_1);         
  149. delay(BB);

  150.    GPIO_SetBits(GPIOA,GPIO_Pin_1);  //關(guān)閉右邊輪子
  151.    delay(400000);

  152.            GPIO_SetBits(GPIOB,GPIO_Pin_13);
  153. GPIO_SetBits(GPIOB,GPIO_Pin_14);   //關(guān)閉轉(zhuǎn)向燈

  154.    }
  155.    
  156. //小車后退的子程序
  157. void hui3()
  158.    {
  159. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左邊輪子倒轉(zhuǎn)
  160. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  161. delay(AA);

  162. GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子

  163.    GPIO_SetBits(GPIOA,GPIO_Pin_2);         //右邊輪子倒轉(zhuǎn)
  164. GPIO_ResetBits(GPIOA,GPIO_Pin_1);         
  165. delay(BB);

  166.    GPIO_SetBits(GPIOA,GPIO_Pin_1);  //關(guān)閉右邊輪子
  167.    delay(300000);

  168.            GPIO_SetBits(GPIOB,GPIO_Pin_13);
  169. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  170.    }  
  171.          
  172.   //小車后退的子程序
  173. void hui4()
  174.    {
  175. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左邊輪子倒轉(zhuǎn)
  176. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  177. delay(AA);

  178.     GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子

  179.    GPIO_SetBits(GPIOA,GPIO_Pin_2);         //右邊輪子倒轉(zhuǎn)
  180. GPIO_ResetBits(GPIOA,GPIO_Pin_1);         
  181. delay(BB);

  182.    GPIO_SetBits(GPIOA,GPIO_Pin_1);  //關(guān)閉右邊輪子
  183.    delay(200000);

  184.            GPIO_SetBits(GPIOB,GPIO_Pin_13);
  185. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  186.    }
  187.    
  188.    //小車后退的子程序
  189. void hui5()
  190.    {
  191. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左邊輪子倒轉(zhuǎn)
  192. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  193. delay(AA);

  194. GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子

  195.    GPIO_SetBits(GPIOA,GPIO_Pin_2);         //右邊輪子倒轉(zhuǎn)
  196. GPIO_ResetBits(GPIOA,GPIO_Pin_1);         
  197. delay(BB);

  198.    GPIO_SetBits(GPIOA,GPIO_Pin_1);  //關(guān)閉右邊輪子
  199.    delay(100000);

  200.            GPIO_SetBits(GPIOB,GPIO_Pin_13);
  201. GPIO_SetBits(GPIOB,GPIO_Pin_14);   //關(guān)閉轉(zhuǎn)向燈

  202.    }
  203.    
  204.    //小車后退的子程序
  205. void hui6()
  206.    {
  207. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左邊輪子倒轉(zhuǎn)
  208. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  209. delay(AA);

  210. GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子

  211.    GPIO_SetBits(GPIOA,GPIO_Pin_2);         //右邊輪子倒轉(zhuǎn)
  212. GPIO_ResetBits(GPIOA,GPIO_Pin_1);         
  213. delay(BB);

  214.    GPIO_SetBits(GPIOA,GPIO_Pin_1);  //關(guān)閉右邊輪子
  215.   

  216.            GPIO_SetBits(GPIOB,GPIO_Pin_13);
  217. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  218.    }  


  219. //小車左轉(zhuǎn)彎子程序   
  220. void turnleft()
  221.      {
  222. GPIO_ResetBits(GPIOB,GPIO_Pin_13);//轉(zhuǎn)向燈打開

  223. GPIO_SetBits(GPIOA,GPIO_Pin_3);
  224. GPIO_ResetBits(GPIOA,GPIO_Pin_4);        //左邊輪子正轉(zhuǎn)
  225.   
  226.   GPIO_SetBits(GPIOA,GPIO_Pin_1);
  227.   GPIO_SetBits(GPIOA,GPIO_Pin_2);        //右邊輪子停止
  228. delay(AA);

  229. GPIO_SetBits(GPIOA,GPIO_Pin_4);  //左邊輪子停止
  230. delay(250000);

  231. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  232. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈  

  233. }


  234. //小車右轉(zhuǎn)彎子程序
  235. void turnright()
  236. {
  237. GPIO_ResetBits(GPIOB,GPIO_Pin_14);//轉(zhuǎn)向燈打開
  238.   
  239. GPIO_SetBits(GPIOA,GPIO_Pin_3);
  240. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左邊輪子停止
  241.   
  242.   GPIO_SetBits(GPIOA,GPIO_Pin_1);
  243.   GPIO_ResetBits(GPIOA,GPIO_Pin_2);        //右邊輪子正轉(zhuǎn)
  244. delay(BB);

  245. GPIO_SetBits(GPIOA,GPIO_Pin_2);  //右邊輪子停止
  246. delay(250000);

  247. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  248. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈  

  249. }


  250. //停止子程序
  251. void down()
  252.   {
  253. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  254. GPIO_SetBits(GPIOA,GPIO_Pin_2);
  255. GPIO_SetBits(GPIOA,GPIO_Pin_3);
  256. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左右輪全部停止


  257. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  258. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈
  259.   }

  260. int main()//主程序
  261. {
  262. while(1)//死循環(huán)
  263. {
  264.    if(a==0x14||a==0x15||a==0x54||a==0x55||a==0x64||a==0x65)//如果是就前進(jìn)
  265. go1();
  266. if(a==0x16||a==0x17||a==0x56||a==0x57||a==0x66||a==0x67)//如果是就前進(jìn)
  267. go2();
  268. if(a==0x18||a==0x19||a==0x58||a==0x59||a==0x68||a==0x69)//如果是就前進(jìn)
  269. go3();
  270. if(a==0x1a||a==0x1b||a==0x5a||a==0x5b||a==0x6a||a==0x6b)//如果是就前進(jìn)
  271. go4();
  272. if(a==0x1c||a==0x1d||a==0x5c||a==0x5d||a==0x6c||a==0x6d)//如果是就前進(jìn)
  273. go5();
  274. if(a==0x1e||a==0x1f||a==0x5e||a==0x5f||a==0x6e||a==0x6f)//如果是就前進(jìn)
  275. go6();

  276.    if(a==0x24||a==0x25||a==0x74||a==0x75||a==0x84||a==0x85)//如果是就后退
  277. hui1();
  278. if(a==0x26||a==0x27||a==0x76||a==0x77||a==0x86||a==0x87)//如果是就后退
  279. hui2();
  280. if(a==0x28||a==0x29||a==0x78||a==0x79||a==0x88||a==0x89)//如果是就后退
  281. hui3();
  282. if(a==0x2a||a==0x2b||a==0x7a||a==0x7b||a==0x8a||a==0x8b)//如果是就后退
  283. hui4();
  284. if(a==0x2c||a==0x2d||a==0x7c||a==0x7d||a==0x8c||a==0x8d)//如果是就后退
  285. hui5();
  286. if(a==0x2e||a==0x2f||a==0x7e||a==0x7d||a==0x8e||a==0x8f)//如果是就后退
  287. hui6();

  288. if(a==0x3f)//如果是0x3f就左轉(zhuǎn)
  289. turnleft();
  290. if(a==0x4f)//如果是0x4f就右轉(zhuǎn)
  291. turnright();
  292. if(a==0x00)//如果是0x00就停止
  293. down();
  294. if(a==0xa0)//如果是0xa0車燈打開
  295. GPIO_ResetBits(GPIOB,GPIO_Pin_12);        //打開轉(zhuǎn)向燈
  296. if(a==0xb0)//如果是0xb0車燈關(guān)閉
  297. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈
  298. if(a==0xc0)//如果是0xc0蜂鳴器鳴響
  299. GPIO_ResetBits(GPIOB,GPIO_Pin_15);        //打開蜂鳴器
  300. if(a==0xd0)//如果是0xd0蜂鳴器關(guān)
  301.    GPIO_SetBits(GPIOB,GPIO_Pin_15);         //關(guān)閉蜂鳴器

  302. else
  303. down();
  304. }
  305. }



  306. void (unsigned char DataToSend)  //串口中斷服務(wù)程序
  307. {   
  308. //   USART_SendData(USART1, (unsigned char) DataToSend);
  309. //   a= ;//讀取單片機(jī)串口接受的藍(lán)牙模塊發(fā)送的數(shù)據(jù)
  310.    a = DataToSend;
  311. }




  312. /*

  313. 硬件鏈接:
  314. 左電機(jī)控制端口:PA3、PA4
  315. 右電機(jī)控制端口:PA1、PA2            
  316. */

  317. #include "stm32f10x.h"//聲明頭文件
  318. #include "stm32f10x_exti.h"
  319. #include "stm32f10x_gpio.h"
  320. #include "stm32f10x_rcc.h"
  321. #include "stm32f10x_usart.h"


  322. #define uchar unsigned char//宏定義
  323. #define uint unsigned int//宏定義
  324. #define AA 35//左輪速度調(diào)節(jié)值
  325. #define BB 35//右輪速度調(diào)節(jié)值

  326. uchar a=0;//定義一個變量a,用來讀取串口的數(shù)據(jù)

  327. /*有參數(shù)延時函數(shù)*/
  328. void delay(__IO uint32_t nCount)
  329. {
  330.   for (; nCount != 0; nCount--);
  331. }


  332. unsigned int temp=0;
  333. unsigned char rebuf[5];
  334. unsigned int start=0;

  335. void GPIO_DengConfiguration()
  336. {
  337.     GPIO_InitTypeDef  GPIO_InitStructure;

  338.     /* 初始化LED的GPIO管腳,配置為推挽輸出 */         //設(shè)置端口
  339.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;         //車燈GPIO_Pin12,13,14端口 15蜂鳴器端口
  340. //設(shè)置對端口的模式
  341.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;         //設(shè)置為 推挽(Push-Pull)輸出
  342. //
  343.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         //最大輸出速度為50MHz

  344.     GPIO_Init(GPIOB, &GPIO_InitStructure);
  345. }




  346. //前進(jìn)子程序
  347. void go1()         
  348.   {
  349.     GPIO_SetBits(GPIOA,GPIO_Pin_3);
  350. GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
  351. delay(AA);

  352. GPIO_SetBits(GPIOA,GPIO_Pin_4);  //關(guān)閉左邊輪子

  353. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  354. GPIO_SetBits(GPIOA,GPIO_Pin_2);        //右邊輪子正轉(zhuǎn)
  355. delay(BB);

  356. GPIO_SetBits(GPIOA,GPIO_Pin_2);  //關(guān)閉右邊輪子

  357. delay(500000);
  358. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  359. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  360.   }

  361.   
  362. //前進(jìn)子程序
  363. void go2()
  364.   {
  365.     GPIO_SetBits(GPIOA,GPIO_Pin_3);
  366. GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
  367. delay(AA);

  368. GPIO_SetBits(GPIOA,GPIO_Pin_4);  //關(guān)閉左邊輪子

  369. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  370. GPIO_SetBits(GPIOA,GPIO_Pin_2);        //右邊輪子正轉(zhuǎn)
  371. delay(BB);

  372. GPIO_SetBits(GPIOA,GPIO_Pin_2);  //關(guān)閉右邊輪子

  373. delay(400000);
  374. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  375. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  376.   }

  377. //前進(jìn)子程序
  378. void go3()
  379.   {
  380.     GPIO_SetBits(GPIOA,GPIO_Pin_3);
  381. GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
  382. delay(AA);

  383. GPIO_SetBits(GPIOA,GPIO_Pin_4);  //關(guān)閉左邊輪子

  384. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  385. GPIO_SetBits(GPIOA,GPIO_Pin_2);        //右邊輪子正轉(zhuǎn)
  386. delay(BB);

  387. GPIO_SetBits(GPIOA,GPIO_Pin_2);  //關(guān)閉右邊輪子

  388. delay(300000);
  389. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  390. GPIO_SetBits(GPIOB,GPIO_Pin_14);         //關(guān)閉轉(zhuǎn)向燈

  391.   }

  392. //前進(jìn)子程序
  393. void go4()
  394.   {
  395.     GPIO_SetBits(GPIOA,GPIO_Pin_3);
  396. GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
  397. delay(AA);

  398. GPIO_SetBits(GPIOA,GPIO_Pin_4);  //關(guān)閉左邊輪子

  399. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  400. GPIO_SetBits(GPIOA,GPIO_Pin_2);        //右邊輪子正轉(zhuǎn)
  401. delay(BB);

  402. GPIO_SetBits(GPIOA,GPIO_Pin_2);  //關(guān)閉右邊輪子

  403. delay(200000);
  404. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  405. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  406.   }

  407. //前進(jìn)子程序
  408. void go5()
  409.   {
  410.     GPIO_SetBits(GPIOA,GPIO_Pin_3);
  411. GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
  412. delay(AA);

  413. GPIO_SetBits(GPIOA,GPIO_Pin_4);  //關(guān)閉左邊輪子

  414. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  415. GPIO_SetBits(GPIOA,GPIO_Pin_2);        //右邊輪子正轉(zhuǎn)
  416. delay(BB);

  417. GPIO_SetBits(GPIOA,GPIO_Pin_2);  //關(guān)閉右邊輪子

  418. delay(100000);
  419. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  420. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  421.   }


  422. //前進(jìn)子程序
  423. void go6()
  424.   {
  425.     GPIO_SetBits(GPIOA,GPIO_Pin_3);
  426. GPIO_ResetBits(GPIOA,GPIO_Pin_4); //左邊輪子正轉(zhuǎn)
  427. delay(AA);

  428. GPIO_SetBits(GPIOA,GPIO_Pin_4);  //關(guān)閉左邊輪子

  429. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  430. GPIO_SetBits(GPIOA,GPIO_Pin_2);        //右邊輪子正轉(zhuǎn)
  431. delay(BB);

  432. GPIO_SetBits(GPIOA,GPIO_Pin_2);  //關(guān)閉右邊輪子

  433. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  434. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  435.   }

  436. //小車后退的子程序
  437. void hui1()
  438.    {
  439. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左邊輪子倒轉(zhuǎn)
  440. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  441. delay(AA);

  442. GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子

  443.    GPIO_SetBits(GPIOA,GPIO_Pin_2);         //右邊輪子倒轉(zhuǎn)
  444. GPIO_ResetBits(GPIOA,GPIO_Pin_1);         
  445. delay(BB);

  446.    GPIO_SetBits(GPIOA,GPIO_Pin_1);  //關(guān)閉右邊輪子
  447.    delay(500000);

  448.            GPIO_SetBits(GPIOB,GPIO_Pin_13);
  449. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  450.    }

  451. //小車后退的子程序
  452. void hui2()
  453.    {
  454. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左邊輪子倒轉(zhuǎn)
  455. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  456. delay(AA);

  457. GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子

  458.    GPIO_SetBits(GPIOA,GPIO_Pin_2);         //右邊輪子倒轉(zhuǎn)
  459. GPIO_ResetBits(GPIOA,GPIO_Pin_1);         
  460. delay(BB);

  461.    GPIO_SetBits(GPIOA,GPIO_Pin_1);  //關(guān)閉右邊輪子
  462.    delay(400000);

  463.            GPIO_SetBits(GPIOB,GPIO_Pin_13);
  464. GPIO_SetBits(GPIOB,GPIO_Pin_14);   //關(guān)閉轉(zhuǎn)向燈

  465.    }
  466.    
  467. //小車后退的子程序
  468. void hui3()
  469.    {
  470. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左邊輪子倒轉(zhuǎn)
  471. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  472. delay(AA);

  473. GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子

  474.    GPIO_SetBits(GPIOA,GPIO_Pin_2);         //右邊輪子倒轉(zhuǎn)
  475. GPIO_ResetBits(GPIOA,GPIO_Pin_1);         
  476. delay(BB);

  477.    GPIO_SetBits(GPIOA,GPIO_Pin_1);  //關(guān)閉右邊輪子
  478.    delay(300000);

  479.            GPIO_SetBits(GPIOB,GPIO_Pin_13);
  480. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  481.    }  
  482.          
  483.   //小車后退的子程序
  484. void hui4()
  485.    {
  486. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左邊輪子倒轉(zhuǎn)
  487. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  488. delay(AA);

  489.     GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子

  490.    GPIO_SetBits(GPIOA,GPIO_Pin_2);         //右邊輪子倒轉(zhuǎn)
  491. GPIO_ResetBits(GPIOA,GPIO_Pin_1);         
  492. delay(BB);

  493.    GPIO_SetBits(GPIOA,GPIO_Pin_1);  //關(guān)閉右邊輪子
  494.    delay(200000);

  495.            GPIO_SetBits(GPIOB,GPIO_Pin_13);
  496. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  497.    }
  498.    
  499.    //小車后退的子程序
  500. void hui5()
  501.    {
  502. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左邊輪子倒轉(zhuǎn)
  503. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  504. delay(AA);

  505. GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子

  506.    GPIO_SetBits(GPIOA,GPIO_Pin_2);         //右邊輪子倒轉(zhuǎn)
  507. GPIO_ResetBits(GPIOA,GPIO_Pin_1);         
  508. delay(BB);

  509.    GPIO_SetBits(GPIOA,GPIO_Pin_1);  //關(guān)閉右邊輪子
  510.    delay(100000);

  511.            GPIO_SetBits(GPIOB,GPIO_Pin_13);
  512. GPIO_SetBits(GPIOB,GPIO_Pin_14);   //關(guān)閉轉(zhuǎn)向燈

  513.    }
  514.    
  515.    //小車后退的子程序
  516. void hui6()
  517.    {
  518. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左邊輪子倒轉(zhuǎn)
  519. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  520. delay(AA);

  521. GPIO_SetBits(GPIOA,GPIO_Pin_3); //關(guān)閉左邊輪子

  522.    GPIO_SetBits(GPIOA,GPIO_Pin_2);         //右邊輪子倒轉(zhuǎn)
  523. GPIO_ResetBits(GPIOA,GPIO_Pin_1);         
  524. delay(BB);

  525.    GPIO_SetBits(GPIOA,GPIO_Pin_1);  //關(guān)閉右邊輪子
  526.   

  527.            GPIO_SetBits(GPIOB,GPIO_Pin_13);
  528. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈

  529.    }  


  530. //小車左轉(zhuǎn)彎子程序   
  531. void turnleft()
  532.      {
  533. GPIO_ResetBits(GPIOB,GPIO_Pin_13);//轉(zhuǎn)向燈打開

  534. GPIO_SetBits(GPIOA,GPIO_Pin_3);
  535. GPIO_ResetBits(GPIOA,GPIO_Pin_4);        //左邊輪子正轉(zhuǎn)
  536.   
  537.   GPIO_SetBits(GPIOA,GPIO_Pin_1);
  538.   GPIO_SetBits(GPIOA,GPIO_Pin_2);        //右邊輪子停止
  539. delay(AA);

  540. GPIO_SetBits(GPIOA,GPIO_Pin_4);  //左邊輪子停止
  541. delay(250000);

  542. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  543. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈  

  544. }


  545. //小車右轉(zhuǎn)彎子程序
  546. void turnright()
  547. {
  548. GPIO_ResetBits(GPIOB,GPIO_Pin_14);//轉(zhuǎn)向燈打開
  549.   
  550. GPIO_SetBits(GPIOA,GPIO_Pin_3);
  551. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左邊輪子停止
  552.   
  553.   GPIO_SetBits(GPIOA,GPIO_Pin_1);
  554.   GPIO_ResetBits(GPIOA,GPIO_Pin_2);        //右邊輪子正轉(zhuǎn)
  555. delay(BB);

  556. GPIO_SetBits(GPIOA,GPIO_Pin_2);  //右邊輪子停止
  557. delay(250000);

  558. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  559. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈  

  560. }


  561. //停止子程序
  562. void down()
  563.   {
  564. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  565. GPIO_SetBits(GPIOA,GPIO_Pin_2);
  566. GPIO_SetBits(GPIOA,GPIO_Pin_3);
  567. GPIO_SetBits(GPIOA,GPIO_Pin_4);        //左右輪全部停止


  568. GPIO_SetBits(GPIOB,GPIO_Pin_13);
  569. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈
  570.   }

  571. int main()//主程序
  572. {
  573. while(1)//死循環(huán)
  574. {
  575.    if(a==0x14||a==0x15||a==0x54||a==0x55||a==0x64||a==0x65)//如果是就前進(jìn)
  576. go1();
  577. if(a==0x16||a==0x17||a==0x56||a==0x57||a==0x66||a==0x67)//如果是就前進(jìn)
  578. go2();
  579. if(a==0x18||a==0x19||a==0x58||a==0x59||a==0x68||a==0x69)//如果是就前進(jìn)
  580. go3();
  581. if(a==0x1a||a==0x1b||a==0x5a||a==0x5b||a==0x6a||a==0x6b)//如果是就前進(jìn)
  582. go4();
  583. if(a==0x1c||a==0x1d||a==0x5c||a==0x5d||a==0x6c||a==0x6d)//如果是就前進(jìn)
  584. go5();
  585. if(a==0x1e||a==0x1f||a==0x5e||a==0x5f||a==0x6e||a==0x6f)//如果是就前進(jìn)
  586. go6();

  587.    if(a==0x24||a==0x25||a==0x74||a==0x75||a==0x84||a==0x85)//如果是就后退
  588. hui1();
  589. if(a==0x26||a==0x27||a==0x76||a==0x77||a==0x86||a==0x87)//如果是就后退
  590. hui2();
  591. if(a==0x28||a==0x29||a==0x78||a==0x79||a==0x88||a==0x89)//如果是就后退
  592. hui3();
  593. if(a==0x2a||a==0x2b||a==0x7a||a==0x7b||a==0x8a||a==0x8b)//如果是就后退
  594. hui4();
  595. if(a==0x2c||a==0x2d||a==0x7c||a==0x7d||a==0x8c||a==0x8d)//如果是就后退
  596. hui5();
  597. if(a==0x2e||a==0x2f||a==0x7e||a==0x7d||a==0x8e||a==0x8f)//如果是就后退
  598. hui6();

  599. if(a==0x3f)//如果是0x3f就左轉(zhuǎn)
  600. turnleft();
  601. if(a==0x4f)//如果是0x4f就右轉(zhuǎn)
  602. turnright();
  603. if(a==0x00)//如果是0x00就停止
  604. down();
  605. if(a==0xa0)//如果是0xa0車燈打開
  606. GPIO_ResetBits(GPIOB,GPIO_Pin_12);        //打開轉(zhuǎn)向燈
  607. if(a==0xb0)//如果是0xb0車燈關(guān)閉
  608. GPIO_SetBits(GPIOB,GPIO_Pin_14);        //關(guān)閉轉(zhuǎn)向燈
  609. if(a==0xc0)//如果是0xc0蜂鳴器鳴響
  610. GPIO_ResetBits(GPIOB,GPIO_Pin_15);        //打開蜂鳴器
  611. if(a==0xd0)//如果是0xd0蜂鳴器關(guān)
  612.    GPIO_SetBits(GPIOB,GPIO_Pin_15);         //關(guān)閉蜂鳴器

  613. else
  614. down();
  615. }
  616. }



  617. void (unsigned char DataToSend)  //串口中斷服務(wù)程序
  618. {   
  619. //   USART_SendData(USART1, (unsigned char) DataToSend);
  620. //   a= ;//讀取單片機(jī)串口接受的藍(lán)牙模塊發(fā)送的數(shù)據(jù)
  621.    a = DataToSend;
  622. }


復(fù)制代碼







歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 日韩不卡一区二区三区 | 中文一区| 91视频免费在观看 | 亚洲精品一区中文字幕乱码 | 国产精品99视频 | 日韩三级精品 | 中文字幕欧美一区二区 | 久久精品视频9 | 日韩影院在线 | 久久成人国产精品 | 亚洲久久一区 | 久久久久国产一区二区三区 | aa级毛片毛片免费观看久 | 成人在线观看免费视频 | 亚洲成人精品久久 | 日韩av在线中文字幕 | 一区观看 | 每日更新av | 日韩无 | 国产精品久久久久久久久免费樱桃 | 夜夜操av| 国产高清一区二区三区 | 免费在线h视频 | 久久成人国产精品 | 美日韩免费| 亚洲午夜精品在线观看 | 亚洲欧美在线观看 | 日韩欧美视频 | 欧美中文在线 | 国产福利在线视频 | 一区二区免费在线观看 | 天天干天天操天天爽 | 天堂av在线影院 | 欧美日韩成人在线 | 91亚洲国产成人精品一区二三 | 国产欧美精品在线观看 | 7799精品视频天天看 | 国产精品视频网 | 精品美女 | 美国十次成人欧美色导视频 | 国产在线资源 |