#include<uart.h>
#define LeftIR P1_2
#define RightIR P3_5
#define LeftLaunch P1_3
#define RightLaunch P3_6
void delay_nus(unsigned int i)
{
i=i*10/12;
while(--i);
}
void Hardware_delay_1ms(void)
{
TMOD &=0xF0;
TMOD |=0x01;
TH0 = 0xFC;
TL0 =0x18;
TF0=0;
TR0=1;
while(TF0==0);
TR0=0;
}
void delay_nms(int n)
{
int j;
for(j=n;j>0;j--)
Hardware_delay_1ms();
}
void IRLaunch(unsigned char IR)
{
int counter;
if(IR==‘L’)
for(counter=0;counter<38;counter++)
{
LeftLaunch=1;
delay_nus(13);
LeftLaunch=0;
delay_nus(13);
}
if(IR=='R')
for(counter=0;counter<38;counter++)
{
RightLaunch=1;
delay_nus(13);
RightLaunch=0;
delay_nus(13);
}
}
void Forward(void)
{
P1_1=1;
delay_nus(1700);
P1_1=0;
P1_0=1;
delay_nus(1300);
P1_0=0;
delay_nms(20);
}
void Left_Turn(void)
{
int i;
for( i=1;i<=23;i++)
{
P1_1=1;
delay_nus(1300);
P1_1=0;
P1_0=1;
delay_nus(1300);
P1_0=0;
delay_nms(20);
}
}
void Right_Turn(void)
{
int i;
for( i=1;i<=23;i++)
{
P1_1=1;
delay_nus(1700);
P1_1=0;
P1_0=1;
delay_nus(1700);
P1_0=0;
delay_nms(20);
}
}
void Backward(void)
{
int i;
for( i=1;i<=65;i++)
{
P1_1=1;
delay_nus(1300);
P1_1=0;
P1_0=1;
delay_nus(1700);
P1_0=0;
delay_nms(20);
}
链接:https://pan.baidu.com/s/1q9B6j0FAXSllHjbO2om_KA 提取码:0nks
|