標(biāo)題: 智能小車紅外避障程序 [打印本頁(yè)]
作者: a23806112 時(shí)間: 2017-2-7 22:35
標(biāo)題: 智能小車紅外避障程序
#include <AT89X52.H>
#include <STRING.H>
#include <REG52.H>
#define FLeftMotor P1_0 = 1 ; P1_1 = 0
#define BLeftMotor P1_0 = 0 ; P1_1 = 1
#define FRightMotor P1_2 = 1 ; P1_3 = 0
#define BRightMotor P1_2 = 0 ; P1_3 = 1
#define LeftStop P1_0 = 1 ; P1_1 = 1
#define RightStop P1_2 = 1 ; P1_3 = 1
#define CarStop P1_0 = 1; P1_1 = 1 ; P1_2 = 1 ; P1_3 = 1
Senser=P3^2//延時(shí)//
Void delay1(unsigned int i)
{
While(--i)
}
//********************************************************
// 左轉(zhuǎn)
//********************************************************
void TurnLeft_1()
{
LeftStop ;
FRightMotor ;
}
//********************************************************
// 壁障程序
//********************************************************
void Obstacle_Avoid(void)
{
if(!Senser)
{
Fleftmotor;
Frightmotor;
}
if((RightSenser) {
Turnright();
delay1(300);
Fleftmotor;Frightmotor;
Delay1(300);
Turnleft();
delay1(300);
Fleftmotor;Frightmotor;
}
//右轉(zhuǎn)//
void Turnright()
{
Rightstop;
Fleftmotor;
}
void Turnleft()
{
Leftstop;
Frightmotor;
}
中斷方式:
#include <AT89X52.H>
#include <REG52.H>
# include <string.h>
#define qianjin P1=0x0A; //前進(jìn)//
#define zuozhuan P1=0x02; //左轉(zhuǎn)//
#define youzhuan P1=0x08; //右轉(zhuǎn)//
#define houtui P1=0x05; //后退//
#define shatin P1=0x0f; //剎停//
IE=0x05;
SETB EXO;SETB EX1;
Void bizhang (void) interrupt 0;
Void delay (unsigned char i);
Void main (void)
{ while(1){
qianjin; }
}
Void bizhang ( ) interrupt 0 //壁障函數(shù)//
{ EA=0;
zuozhuan;
delay(500);
shatin;
if(!(EX0||EX1))
{ zuozhuan;
delay(500);
shatin;
}
qianjin;
delay(30000);
zuozhuan;
delay(500);
EA=1;
}
Void delay (unsigned char i) //延時(shí)函數(shù)//
{ while(--i);
}
歡迎光臨 (http://www.torrancerestoration.com/bbs/) |
Powered by Discuz! X3.1 |