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

QQ登錄

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

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

超聲波避障小車(chē)源程序

[復(fù)制鏈接]
ID:219419 發(fā)表于 2017-7-13 15:44 | 顯示全部樓層 |閱讀模式
超聲波避障  程序

單片機(jī)源程序如下:
  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. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼

所有資料51hei提供下載:
超聲波避障小車(chē)源程序.zip (16.96 KB, 下載次數(shù): 21)


回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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