#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar temp,signal,tt1;
void delay_1ms(uint d)
{
uint i;
while(d--)
for(i=0;i<75;i++);
}
void motor_run() //?????
{
P1=0x35;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
/* ENA=1;
OUT1=0;
OUT2=1;
delay_1ms(800);
OUT2=0;
delay_1ms(200);
ENB=1;
OUT4=0;
OUT3=1;
delay_1ms(800);
OUT3=0;
delay_1ms(200);
*/
}
void motor_left() //???
{
P1=0x30;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_right() //???
{
P1=0x05;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_big_right() //?????
{
P1=0x55;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_big_left()
{
P1=0x33;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_stop() //?????
{
P1=0x00;
}
void motor_back()
{
P1=0x53;
}
void main()
{
tt1=0;
EA=1;
ET1=1;
TR1=1;
TMOD=0x01;
TH1=-(1000/256);
TL1=-(1000%256);
while(1)
{
temp=P2;
signal=temp&0xff; //????????????
switch(signal)
{
case 0xff: //?????
motor_run();
break;
case 0xfd: //1?????
motor_left();
break;
case 0xef: //4?????
motor_right();
break;
case 0xfb: //2?????????
case 0xf9: //1??2?????
motor_big_left();
// delay_1ms(10);
break;
case 0xdf: //5???????
case 0xcf: //4??5?????
motor_big_right();
// delay_1ms(10);
break;
case 0xfe: //0?????????
case 0xfa:
motor_big_left();
// delay_1ms(10);
break;
case 0xbf: //6?????????
case 0x9f:
motor_big_right();
// delay_1ms(10);
break;
case 0xeb: //?????????????????
case 0xdb: //??????????????????
case 0xbe: //?м?????????????????
case 0xac: //????????????????
case 0x9a: //?????????????????
motor_back();
delay_1ms(200);
motor_stop();
// delay_1ms(1000);
default:
break;
}
}
}
void time1() interrupt 3
{
TH1=-(1000/256);
TL1=-(1000%256);
tt1++;
if(tt1==300)
{
motor_back();
// delay_1ms(1);
tt1=0;
}
}
|