|
#include <REGX52.H> //°üo¬51μ¥Ƭ»úÏà1ØμÄí·Îļt
sbit LeftLed=P2^0;
sbit RightLed=P0^7;
sbit FontLled=P1^0;
sbit LeftIR=P3^5;
sbit RightIR=P3^6;
sbit FontIR=P3^7;
sbit M1A=P0^0;
sbit M1B=P0^1;
sbit M2A=P0^2;
sbit M2B=P0^3;
sbit B1=P0^4;
sbit SB1=P0^6;
void tingzhi()
{
M1A=0;
M1B=0;
M2A=0;
M2B=0;
}
void qianjin()
{
M1A=1;
M1B=0;
M2A=1;
M2B=0;
}
void houtui()
{
M1A=0;
M1B=1;
M2A=0;
M2B=1;
}
void zuozhuan()
{
M1A=0;
M1B=1;
M2A=1;
M2B=0;
}
void youzhuan()
{
M1A=1;
M1B=0;
M2A=0;
M2B=1;
}
void delay_nus(unsigned int i)
{
i=i/10;
while(--i);
}
void delay_nms(unsigned int n)
{
n=n+1;
while(--n)
delay_nus(900);
}
void ControlCar(unsigned char ConType)
{
tingzhi();
switch(ConType)
{
case 1: //ǰ½ø
{
qianjin();
break;
}
case 2: //oóíË
{
houtui();
break;
}
case 3: //×ó×a
{
zuozhuan();
break;
}
case 4: //óò×a
{
youzhuan();
break;
}
case 8: //í£Ö1
{
tingzhi();
break;
}
}
}
void main()
{
bit RunFlag=0;
//RunShow=0;
ControlCar(8);
while(1)
{
Start:
LeftLed=LeftIR;
RightLed=RightIR;
FontLled= FontIR;
SB1=LeftIR;
if(LeftIR == 0 && RightIR == 0)
{
ControlCar(1);
delay_nms (10);
goto NextRun;
}
if(LeftIR == 0 && RightIR == 1)
{
ControlCar(3);
delay_nms (10);
goto NextRun;
}
if(LeftIR == 1 && RightIR == 0)
{
ControlCar(4);
delay_nms (10);
goto NextRun;
}
goto Start;
NextRun:
ControlCar(8);
}
}
|
評分
-
查看全部評分
|