找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2103|回复: 0
收起左侧

超声波避障小车源程序

[复制链接]
ID:219419 发表于 2017-7-13 15:44 | 显示全部楼层 |阅读模式
超声波避障  程序

单片机源程序如下:
  1. #include <REGX51.H>
  2. #include <stdio.h>
  3. #define uint  unsigned int

  4. uint i,j,k;
  5. void delay(i);
  6. void main()
  7. {
  8.         P0=0xFF;
  9.            while(1)
  10.            {
  11.                  if(P1_0==0)
  12.                   {
  13.                     P2=0x11;
  14.                 delay(1500);
  15.                     P2=0x22;
  16.                 delay(1500);
  17.                     P2=0x44;
  18.                 delay(1500);
  19.                     P2=0x88;
  20.                 delay(1500);
  21.                   }
  22.               if(P1_0!=0)
  23.                   {
  24.                       j=0;
  25.                       for (j=0;j<13;j++)
  26.                       {
  27.                             P2=0x18;
  28.                     delay(1500);
  29.                         P2=0x24;
  30.                     delay(1500);
  31.                         P2=0x42;
  32.                     delay(1500);
  33.                         P2=0x81;
  34.                     delay(1500);
  35.                           }
  36.                   if(P1_0!=0)
  37.                       {
  38.                               j=0;
  39.                               for (j=0;j<23;j++)
  40.                               {
  41.                                       P2=0x81;
  42.                               delay(1500);
  43.                                   P2=0x42;
  44.                               delay(1500);
  45.                                   P2=0x24;
  46.                               delay(1500);
  47.                                   P2=0x18;
  48.                               delay(1500);
  49.                             }
  50.                   }
  51.                   if(P1_0!=0)
  52.                       {       
  53.                         j=0;
  54.                         for (j=0;j<36;j++)
  55.                         {
  56.                                       P2=0x18;
  57.                               delay(1500);
  58.                                   P2=0x24;
  59.                               delay(1500);
  60.                                   P2=0x42;
  61.                               delay(1500);
  62.                                   P2=0x81;
  63.                               delay(1500);
  64.                             }
  65.                   }
  66.             }
  67.         if(P1_0!=0)
  68.             {
  69.                       j=0;
  70.                       for (j=0;j<52;j++)
  71.                       {
  72.                              P2=0x81;
  73.                      delay(1500);
  74.                          P2=0x42;
  75.                      delay(1500);
  76.                          P2=0x24;
  77.                      delay(1500);
  78.                          P2=0x18;
  79.                      delay(1500);
  80.                           }
  81.                           if(P1_0!=0)
  82.                       {
  83.                                j=0;
  84.                                for (j=0;j<65;j++)
  85.                                 {
  86.                                       P2=0x18;
  87.                               delay(1500);
  88.                                   P2=0x24;
  89.                               delay(1500);
  90.                                   P2=0x42;
  91.                               delay(1500);
  92.                                   P2=0x81;
  93.                               delay(1500);
  94.                                    }
  95.                           }
  96.                   if(P1_0!=0)
  97.                      {
  98.                                j=0;
  99.                                for (j=0;j<80;j++)
  100.                                {
  101.                                       P2=0x81;
  102.                               delay(1500);
  103.                                   P2=0x42;
  104.                               delay(1500);
  105.                                   P2=0x24;
  106.                               delay(1500);
  107. ……………………

  108. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
超声波避障小车源程序.zip (16.96 KB, 下载次数: 21)
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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