📄 trace.c
字号:
#include <at89X52.h> //left--P32, right ---P33, middle---P36
//#include <moto.h>
#define pulse 3
#define period 8
int count1=period;
int count2=pulse;
int leftdetect=0;
int rightdetect=0;
void delay(int degree)
{
unsigned int m=0;
while(m<(degree*100)) m++;
}
void go(int degree)
{
int grade1=degree;
ET0=1;
P1=0x0a;
delay(grade1);
P1=0;
}
void right(int degree)
{
int i;
int grade3=degree;
ET0=0;
for(i=0;i<grade3;i++)
{
P1=0x39;
delay(10);
P1=0x36;
delay(1);
P1=0;
}
P1=0;
ET0=1;
}
void left(int degree)
{
int i;
int grade4=degree;
ET0=0;
for(i=0;i<grade4;i++)
{
P1=0x36;
delay(10);
P1=0x39;
delay(1);
P1=0;
}
P1=0;
ET0=1;
}
main()
{
IT0=1;
EX0=1;
IT1=1;
EX1=1;
TMOD=0X01;
TH0=0XEE;
TL0=0X58;
ET0=1;
EA=1;
TR0=1;
while(1)
{
if(rightdetect==1)
{
right(3);
rightdetect=0;
}
if(leftdetect==1)
{
left(3);
leftdetect=0;
}
go(50);
}
}
void int0(void) interrupt 0
{
ET0=0;
leftdetect=1;
}
void int1(void) interrupt 2
{
ET0=0;
rightdetect=1;
}
void timer0(void) interrupt 1
{
TH0=0XEE;
TL0=0X58;
count1--;
if(count1==0)
{
count1=period;
count2=pulse;
P1_4=1;
P1_5=1;
}
count2--;
if(count2==0) {P1_4=0;P1_5=0;count2++;}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -