找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 7683|回复: 8
打印 上一主题 下一主题
收起左侧

51单片机WiFi遥控小车及APP

  [复制链接]
跳转到指定楼层
楼主
    51单片机WiFi遥控小车是利用手机作为控制端,通过WIFI模块与单片机串口通信,实现小车的前进、后退、左拐、右拐停止等功能。

下载:
51单片机WiFi遥控小车及APP.rar (180.02 KB, 下载次数: 173)










单片机源码:
  1. #include <REGX51.H>
  2. #define uint unsigned int
  3. #define uchar unsigned char


  4. uchar Receive,i,qj,yz,zz,ht;
  5. uint n;
  6. uchar Recive_table[40];



  7. void ms_delay(uint t)
  8. {
  9. uint i,j;
  10. for(i=t;i>0;i--)
  11. for(j=110;j>0;j--);
  12. }


  13. void us_delay(uchar t)
  14. {
  15. while(t--);
  16. }


  17. void Uart_Init() //使用定时器1作为波特率发生器(STC89C52、STC89C51、AT89C51等均可)
  18. {
  19. TMOD = 0x20;
  20. SCON = 0x50;
  21. TH1 = 0xFD;
  22. TL1 = TH1;
  23. PCON = 0x00;
  24. EA = 1; //总中断打开
  25. ES = 1; //开串口中断
  26. TR1 = 1; //启动定时器1
  27. }




  28. void Send_Uart(uchar value)
  29. {
  30. ES=0; //关闭串口中断
  31. TI=0; //清发送完毕中断请求标志位
  32. SBUF=value; //发送
  33. while(TI==0); //等待发送完毕
  34. TI=0; //清发送完毕中断请求标志位
  35. ES=1; //允许串口中断
  36. }






  37. void ESP8266_Set(uchar *puf) // 数组指针*puf指向字符串数组
  38. {
  39. while(*puf!='\0') //遇到空格跳出循环
  40. {
  41. Send_Uart(*puf);
  42. us_delay(5);
  43. puf++;
  44. }
  45. us_delay(5);
  46. Send_Uart('\r');
  47. us_delay(5);
  48. Send_Uart('\n');
  49. }





  50. void main()
  51. {
  52. Uart_Init();
  53. ms_delay(2000);
  54. ESP8266_Set("AT+CWMODE=2");
  55. ms_delay(2000);
  56. // ESP8266_Set("AT+RST");
  57. // ms_delay(2000);
  58. ESP8266_Set("AT+CWSAP=\"wifi\",\"123456789\",11,4"); //AT+CWSAP="wifi","123456789",11,4
  59. ms_delay(2000);
  60. ESP8266_Set("AT+CIPMUX=1");
  61. ms_delay(2000);
  62. ESP8266_Set("AT+CIPSERVER=1,5000");
  63. ms_delay(2000);
  64. ESP8266_Set("AT+CIPSTO=0");
  65. ES=1;
  66. qj=1;
  67. zz=1;
  68. yz=1;
  69. ht=1;
  70. while(1)
  71. {
  72. if((Recive_table[0]=='+')&&(Recive_table[1]=='I')&&(Recive_table[2]=='P'))
  73. {
  74. if((Recive_table[9]=='G')&&(Recive_table[10]=='P'))
  75. {
  76. if(Recive_table[15]=='0')
  77. {
  78. qj=0; //前进
  79. zz=1;
  80. yz=1;
  81. ht=1;
  82. }
  83. else
  84. if (Recive_table[15]=='1')
  85. {
  86. qj=1;
  87. zz=1;
  88. yz=1;
  89. ht=0; // 后退
  90. }
  91. else
  92. if (Recive_table[15]=='2')
  93. {
  94. // qj=1; //
  95. zz=1;
  96. yz=0; //右转
  97. // ht=1;
  98. }
  99. else
  100. if (Recive_table[15]=='3')
  101. {
  102. // qj=1; //
  103. zz=0; //左转
  104. yz=1;
  105. // ht=1;
  106. }
  107. else
  108. if (Recive_table[15]=='4')
  109. {
  110. qj=1; //
  111. zz=1;
  112. yz=1;
  113. ht=1;
  114. }
  115. }
  116. }
  117. if(qj==0)
  118. {
  119. if((zz==0)|(yz==0))
  120. {
  121. ;
  122. }
  123. else
  124. {
  125. P2=0x11;
  126. ms_delay(10);
  127. P2=0x22;
  128. ms_delay(10);
  129. P2=0x44;
  130. ms_delay(10);
  131. P2=0x88;
  132. ms_delay(10);
  133. }
  134. }
  135. if(ht==0)
  136. {
  137. if((zz==0)|(yz==0))
  138. {
  139. ;
  140. }
  141. else
  142. {
  143. P2=0x88;
  144. ms_delay(10);
  145. P2=0x44;
  146. ms_delay(10);
  147. P2=0x22;
  148. ms_delay(10);
  149. P2=0x11;
  150. ms_delay(10);
  151. }
  152. }
  153. if(zz==0)
  154. {
  155. if(ht==1)
  156. {
  157. P2=0x01;
  158. ms_delay(10);
  159. P2=0x02;
  160. ms_delay(10);
  161. P2=0x04;
  162. ms_delay(10);
  163. P2=0x08;
  164. ms_delay(10);
  165. }
  166. else
  167. {
  168. P2=0x08;
  169. ms_delay(10);
  170. P2=0x04;
  171. ms_delay(10);
  172. P2=0x02;
  173. ms_delay(10);
  174. P2=0x01;
  175. ms_delay(10);
  176. }
  177. }
  178. if(yz==0)
  179. {
  180. if(ht==1)
  181. {
  182. P2=0x10;
  183. ms_delay(10);
  184. P2=0x20;
  185. ms_delay(10);
  186. P2=0x40;
  187. ms_delay(10);
  188. P2=0x80;
  189. ms_delay(10);
  190. }
  191. else
  192. {
  193. P2=0x80;
  194. ms_delay(10);
  195. P2=0x40;
  196. ms_delay(10);
  197. P2=0x20;
  198. ms_delay(10);
  199. P2=0x10;
  200. ms_delay(10);
  201. }
  202. }
  203. }
  204. }






  205. void Uart_Interrupt() interrupt 4
  206. {
  207. static uchar i=0;
  208. if(RI==1)
  209. {
  210. RI=0;
  211. Receive=SBUF;
  212. Recive_table[ i]=Receive; if((Recive_table[ i]=='\n')){ i=0;} else i++; } else TI=0; }
复制代码


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏11 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:130231 发表于 2018-6-13 15:53 | 只看该作者
APP可以有重力感应控制吗
回复

使用道具 举报

板凳
ID:34643 发表于 2018-6-13 21:01 | 只看该作者
zqy181818 发表于 2018-6-13 15:53
APP可以有重力感应控制吗

APP没有重力感应控制
回复

使用道具 举报

地板
ID:34643 发表于 2018-6-16 06:14 | 只看该作者
电机使用的是步进电机。
回复

使用道具 举报

5#
ID:130231 发表于 2018-6-16 22:23 | 只看该作者
51mcu 发表于 2018-6-13 21:01
APP没有重力感应控制

我看到过,用的是加速传感器做的,不过的是我不会做。
回复

使用道具 举报

6#
ID:436502 发表于 2018-11-30 13:57 | 只看该作者
感谢楼主无私奉献
回复

使用道具 举报

7#
ID:74784 发表于 2021-3-22 18:51 | 只看该作者
下了2遍都说数据坏掉了!

评分

参与人数 1黑币 +15 收起 理由
51hei团团 + 15

查看全部评分

回复

使用道具 举报

8#
ID:328014 发表于 2021-3-23 00:24 | 只看该作者
lxa0 发表于 2021-3-22 18:51
下了2遍都说数据坏掉了!

我刚测试了,没有问题 要用最新版的winrar解压才行,用其他的会失败
回复

使用道具 举报

9#
ID:895316 发表于 2021-3-23 08:12 | 只看该作者
大佬可以加摄像头吗,DIY小玩意要做智能搜救小车想加个摄像头和超声波避障
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表