找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 9416|回復(fù): 2
收起左側(cè)

51單片機(jī)藍(lán)牙控制小車 源程序+APP

[復(fù)制鏈接]
ID:150303 發(fā)表于 2018-8-3 16:06 | 顯示全部樓層 |閱讀模式
智藍(lán)牙遙機(jī)器人
IMG_20180604_144316.jpg
藍(lán)牙模塊出廠默認(rèn)參數(shù):
從機(jī),波特率:9600,N,8,1。配對(duì)密碼:1234//注意程序只做參考之用,要達(dá)到最理想的效果,還需要同學(xué)們細(xì)心調(diào)試。        
        //注意藍(lán)牙模塊接線,急性之人經(jīng)常接錯(cuò)線,燒壞模塊,請(qǐng)一定要核對(duì)好再通電試驗(yàn),模塊接錯(cuò)線燒壞不保修,不換貨的。
        /****************************************************************************
         硬件連接
         藍(lán)牙有4條線定義:
          VCC
          GND
          TDX
          RXD
        
**********************************************************/
藍(lán)牙圖.png
  1. #include<AT89x51.H>

  2.         //HL-1小車驅(qū)動(dòng)接線定義
  3.     #define Left_moto_go      {P0_0=1,P0_1=0;}    //左邊電機(jī)向前走
  4.         #define Left_moto_back    {P0_0=0,P0_1=1;}    //左邊電機(jī)向后轉(zhuǎn)
  5.         #define Left_moto_Stop    {P0_0=0,P0_1=0;}    //左邊電機(jī)停轉(zhuǎn)                     
  6.         #define Right_moto_go     {P0_2=1,P0_3=0;}        //右邊電機(jī)向前走
  7.         #define Right_moto_back   {P0_2=0,P0_3=1;}        //右邊電機(jī)向后走
  8.         #define Right_moto_Stop   {P0_2=0,P0_3=0;}        //右邊電機(jī)停轉(zhuǎn)   

  9.         #define left     'C'
  10.        #define right    'D'
  11.         #define up       'A'
  12.        #define down     'B'
  13.         #define stop     'F'

  14.         #define uint    unsigned int                          //重定義無(wú)符號(hào)整數(shù)類型
  15.     #define uchar   unsigned char                         //重定義無(wú)符號(hào)字符類型

  16.         char code str[] =  "收到指令,向前!\n";
  17.         char code str1[] = "收到指令,向后!\n";
  18.         char code str2[] = "收到指令,向左!\n";
  19.         char code str3[] = "收到指令,向右!\n";
  20.         char code str4[] = "收到指令,停止!\n";

  21.         bit  flag_REC=0;
  22.         bit  flag    =0;  
  23.         

  24.         unsigned char  i=0;
  25.         unsigned char  dat=0;
  26.     unsigned char  buff[5]=0; //接收緩沖字節(jié)
  27.         uchar code  LedShowData[]={0x03,0x9F,0x25,0x0D,0x99,  //定義數(shù)碼管顯示數(shù)據(jù)
  28.                             0x49,0x41,0x1F,0x01,0x19};//0,1,2,3,4,5,6,7,8,9

  29.         #define ShowPort P2                                   //定義數(shù)碼管顯示端口

  30. /************************************************************************/        
  31. //延時(shí)函數(shù)        
  32.    void delay(unsigned int k)
  33. {   
  34.      unsigned int x,y;
  35.          for(x=0;x<k;x++)
  36.            for(y=0;y<2000;y++);
  37. }

  38. /************************************************************************/
  39. //字符串發(fā)送函數(shù)
  40.           void send_str( )
  41.                    // 傳送字串
  42.     {
  43.             unsigned char i = 0;
  44.             while(str[i] != '\0')
  45.            {
  46.                 SBUF = str[i];
  47.                 while(!TI);                                // 等特?cái)?shù)據(jù)傳送
  48.                 TI = 0;                                        // 清除數(shù)據(jù)傳送標(biāo)志
  49.                 i++;                                        // 下一個(gè)字符
  50.            }        
  51.     }
  52.         
  53.                   void send_str1( )
  54.                    // 傳送字串
  55.     {
  56.             unsigned char i = 0;
  57.             while(str1[i] != '\0')
  58.            {
  59.                 SBUF = str1[i];
  60.                 while(!TI);                                // 等特?cái)?shù)據(jù)傳送
  61.                 TI = 0;                                        // 清除數(shù)據(jù)傳送標(biāo)志
  62.                 i++;                                        // 下一個(gè)字符
  63.            }        
  64.     }        

  65.                           void send_str2( )
  66.                    // 傳送字串
  67.     {
  68.             unsigned char i = 0;
  69.             while(str2[i] != '\0')
  70.            {
  71.                 SBUF = str2[i];
  72.                 while(!TI);                                // 等特?cái)?shù)據(jù)傳送
  73.                 TI = 0;                                        // 清除數(shù)據(jù)傳送標(biāo)志
  74.                 i++;                                        // 下一個(gè)字符
  75.            }        
  76.     }        
  77.                     
  78.                           void send_str3()
  79.                    // 傳送字串
  80.     {
  81.             unsigned char i = 0;
  82.             while(str3[i] != '\0')
  83.            {
  84.                 SBUF = str3[i];
  85.                 while(!TI);                                // 等特?cái)?shù)據(jù)傳送
  86.                 TI = 0;                                        // 清除數(shù)據(jù)傳送標(biāo)志
  87.                 i++;                                        // 下一個(gè)字符
  88.            }        
  89.     }        

  90.               void send_str4()
  91.                    // 傳送字串
  92.     {
  93.             unsigned char i = 0;
  94.             while(str4[i] != '\0')
  95.            {
  96.                 SBUF = str4[i];
  97.                 while(!TI);                                // 等特?cái)?shù)據(jù)傳送
  98.                 TI = 0;                                        // 清除數(shù)據(jù)傳送標(biāo)志
  99.                 i++;                                        // 下一個(gè)字符
  100.            }        
  101.     }        
  102.                     
  103.                     
  104. /************************************************************************/
  105. //前速前進(jìn)
  106.      void  run(void)
  107. {

  108.          Left_moto_go ;   //左電機(jī)往前走
  109.          Right_moto_go ;  //右電機(jī)往前走
  110. }

  111. //前速后退
  112.      void  backrun(void)
  113. {

  114.          Left_moto_back ;   //左電機(jī)往后走
  115.          Right_moto_back ;  //右電機(jī)往后走
  116. }

  117. //左轉(zhuǎn)
  118.      void  leftrun(void)
  119. {


  120.           Left_moto_go ;   //左電機(jī)往前走
  121.          Right_moto_back ;  //右電機(jī)往后走
  122. }

  123. //右轉(zhuǎn)
  124.      void  rightrun(void)
  125. {

  126.          
  127.          Left_moto_back ;   //左電機(jī)往前走
  128.          Right_moto_go ;  //右電機(jī)往前走
  129. }
  130. //STOP
  131.      void  stoprun(void)
  132. {

  133.          Left_moto_Stop ;   //左電機(jī)往前走
  134.          Right_moto_Stop ;  //右電機(jī)往前走
  135. }
  136. /************************************************************************/
  137. void sint() interrupt 4          //中斷接收3個(gè)字節(jié)
  138. {

  139.     if(RI)                         //是否接收中斷
  140.     {
  141.        RI=0;
  142.        dat=SBUF;
  143.        if(dat=='O'&&(i==0)) //接收數(shù)據(jù)第一幀
  144.          {
  145.             buff[i]=dat;
  146.             flag=1;        //開(kāi)始接收數(shù)據(jù)
  147.          }
  148.    else
  149.      if(flag==1)
  150.      {
  151.       i++;
  152.       buff[i]=dat;
  153.       if(i>=2)
  154.       {i=0;flag=0;flag_REC=1 ;}  // 停止接收
  155.      }
  156.          }
  157. }
  158. /*********************************************************************/   
復(fù)制代碼
            
由于篇幅問(wèn)題,剩余程序和app都在壓縮包里
QQ截圖20180803160325.jpg

全部資料51hei下載地址:
藍(lán)牙遙控程序操作程序.zip (1.4 MB, 下載次數(shù): 124)


評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

ID:383544 發(fā)表于 2018-9-7 19:18 | 顯示全部樓層
為哈沒(méi)有APK的源程序呢?
回復(fù)

使用道具 舉報(bào)

ID:395308 發(fā)表于 2018-9-12 11:00 | 顯示全部樓層
看來(lái)不錯(cuò),學(xué)習(xí)一下謝謝了
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表