建网站价格网,wordpress手机单页面模板,做网站域名重要吗,miya1173跳转接口目录
循迹小车
1. 循迹模块使用
2. 循迹小车原理
3. 循迹小车开发和调试代码 循迹小车
1. 循迹模块使用
TCRT5000传感器的红外发射二极管不断发射红外线当发射出的红外线没有被反射回来或被反射回来但强度不够大时红外接收管一直处于关断状态#xff0c;此时模块的输出… 目录
循迹小车
1. 循迹模块使用
2. 循迹小车原理
3. 循迹小车开发和调试代码 循迹小车
1. 循迹模块使用
TCRT5000传感器的红外发射二极管不断发射红外线当发射出的红外线没有被反射回来或被反射回来但强度不够大时红外接收管一直处于关断状态此时模块的输出端为高电平指示二极管一直处于熄灭状态被检测物体出现在检测范围内时红外线被反射回来且强度足够大红外接收管饱和此时模块的输出端为低电平指示二极管被点亮总结就是一句话没反射回来D0输出高电平灭灯 接线方式
VCC:接电源正极3-5VGND:接电源负极 DO:TTL开关信号输出0、1AO:模拟信号输出(不同距离输出不同的电压此脚一般可以不接
2. 循迹小车原理
由于黑色具有较强的吸收能力当循迹模块发射的红外线照射到黑线时红外线将会被黑线吸收导致 循迹模块上光敏三极管处于关闭状态此时模块上一个LED熄灭。在没有检测到黑线时模块上两个LED常亮
总结就是一句话有感应到黑线D0输出高电平 灭灯 3. 循迹小车开发和调试代码
//main.c
#include motor.h
#include delay.h
#include uart.h
#include time.h
#include reg52.h
extern char speedLeft;
extern char speedRight;sbit leftSensor P2^7;
sbit rightSensor P2^6;void main()
{Time0Init();Time1Init();//UartInit();while(1){if(leftSensor 0 rightSensor 0){speedLeft 32;speedRight 40;}if(leftSensor 1 rightSensor 0){speedLeft 12;//10份单位时间全速运行30份停止所以慢20ms是40份的500usspeedRight 40;}if(leftSensor 0 rightSensor 1){speedLeft 32;speedRight 20;}if(leftSensor 1 rightSensor 1){//停speedLeft 0;speedRight 0;}}
}//motor.c
#include reg52.hsbit RightCon1A P3^2;
sbit RightCon1B P3^3;sbit LeftCon1A P3^4;
sbit LeftCon1B P3^5;void goForwardLeft()
{LeftCon1A 0;LeftCon1B 1;
}void stopLeft()
{LeftCon1A 0;LeftCon1B 0;
}void goForwardRight()
{RightCon1A 0;RightCon1B 1;
}
void stopRight()
{RightCon1A 0;RightCon1B 0;
}void goForward()
{LeftCon1A 0;LeftCon1B 1;RightCon1A 0;RightCon1B 1;
}void goRight()
{LeftCon1A 0;LeftCon1B 1;RightCon1A 0;RightCon1B 0;
}void goLeft()
{LeftCon1A 0;LeftCon1B 0;RightCon1A 0;RightCon1B 1;
}void goBack()
{LeftCon1A 1;LeftCon1B 0;RightCon1A 1;RightCon1B 0;
}void stop()
{LeftCon1A 0;LeftCon1B 0;RightCon1A 0;RightCon1B 0;
}//delay.c
#include intrins.hvoid Delay1000ms() //11.0592MHz
{unsigned char i, j, k;_nop_();i 8;j 1;k 243;do{do{while (--k);} while (--j);} while (--i);
}//time.c
#include motor.h
#include reg52.hchar speedLeft;
char cntLeft 0;char speedRight;
char cntRight 0;void Time1Init()
{//1. 配置定时器1工作模式位16位计时TMOD 0x0F;TMOD | 0x1 4;//2. 给初值定一个0.5出来TL10x33;TH10xFE;//3. 开始计时TR1 1;TF1 0;//4. 打开定时器1中断ET1 1;//5. 打开总中断EAEA 1;
}void Time0Init()
{//1. 配置定时器0工作模式位16位计时TMOD 0x01;//2. 给初值定一个0.5出来TL00x33;TH00xFE;//3. 开始计时TR0 1;TF0 0;//4. 打开定时器0中断ET0 1;//5. 打开总中断EAEA 1;
}void Time1Handler() interrupt 3
{cntRight; //统计爆表的次数. cnt1的时候报表了1//重新给初值TL10x33;TH10xFE;//控制PWM波if(cntRight speedRight){//右前进goForwardRight();}else{//停止stopRight();}if(cntRight 40){//爆表40次经过了20mscntRight 0; //当100次表示1s重新让cnt从0开始计算下一次的1s}}void Time0Handler() interrupt 1
{cntLeft; //统计爆表的次数. cnt1的时候报表了1//重新给初值TL00x33;TH00xFE;//控制PWM波if(cntLeft speedLeft){//左前进goForwardLeft();}else{//停止stopLeft();}if(cntLeft 40){//爆表40次经过了20mscntLeft 0; //当100次表示1s重新让cnt从0开始计算下一次的1s}}