标题:
超声波避障部分程序源代码
[打印本页]
作者:
1329866424
时间:
2017-4-27 15:39
标题:
超声波避障部分程序源代码
#include <REGX51.H>
#include <stdio.h>
#define uint unsigned int
uint i,j,k;
void delay(i);
void main()
{
P0=0xFF;
while(1)
{
if(P1_0==0)
{
P2=0x11;
delay(1500);
P2=0x22;
delay(1500);
P2=0x44;
delay(1500);
P2=0x88;
delay(1500);
}
if(P1_0!=0)
{
j=0;
for (j=0;j<13;j++)
{
P2=0x18;
delay(1500);
P2=0x24;
delay(1500);
P2=0x42;
delay(1500);
P2=0x81;
delay(1500);
}
if(P1_0!=0)
{
j=0;
for (j=0;j<23;j++)
{
P2=0x81;
delay(1500);
P2=0x42;
delay(1500);
P2=0x24;
delay(1500);
P2=0x18;
delay(1500);
}
}
if(P1_0!=0)
{
j=0;
for (j=0;j<36;j++)
{
P2=0x18;
delay(1500);
P2=0x24;
delay(1500);
P2=0x42;
delay(1500);
P2=0x81;
delay(1500);
}
}
}
if(P1_0!=0)
{
j=0;
for (j=0;j<52;j++)
{
P2=0x81;
delay(1500);
P2=0x42;
delay(1500);
P2=0x24;
delay(1500);
P2=0x18;
delay(1500);
}
if(P1_0!=0)
{
j=0;
for (j=0;j<65;j++)
{
P2=0x18;
delay(1500);
P2=0x24;
delay(1500);
P2=0x42;
delay(1500);
P2=0x81;
delay(1500);
}
}
if(P1_0!=0)
{
j=0;
for (j=0;j<80;j++)
{
P2=0x81;
delay(1500);
P2=0x42;
delay(1500);
P2=0x24;
delay(1500);
P2=0x18;
delay(1500);
}
}
}
}
}
/* us级延时函数,参数i为延时时间 */
void delay(i) //延时子程序
{
while(--i);
}
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1