📄 text1.c
字号:
#include <at89x51.H>
#include <stdio.h>
sbit P01=P0^1; //接左1红外发射接收对管
sbit P02=P0^2; //接右1红外发射接收对管
sbit P10=P1^0;//此引脚接L298N上的IN1口,控制前电机的转向
sbit P11=P1^1;//此引脚接L298N上的IN2口,控制前电机的占空比
sbit P12=P1^2;//此引脚接L298N上的IN3口,控制后电机的转向
sbit P13=P1^3;//此引脚接L298N上的IN4口,控制后电机的占空比
sbit P14=P1^4;//此引脚接接L298N上的使能端E1,控制前电机
sbit P15=P1^5;//此引脚接接L298N上的使能端E2,控制后电机
int r;
void Delay_1()//延时子程序1
{
unsigned int r;
for(r=0;r<500;r++)
{;}
}
void Delay_2()//延时子程序2
{
for(r=0;r<2500;r++)
{;}
}
void OutputPWM1()
{
P13=!P13;
Delay_2();
P13=!P13;
Delay_1();
}
void pwm_moto2_go(void)
{
OutputPWM1();
P15=1;
P12=1; //此引脚接后电机
}
void direction_moto1(void)
{
if(P01==0) //接左1红外发射接收对管 (左1 左2 中心轴线 右2 右1)
{P14=0;P10=1;P11=0;} //左转,P1^4接L298N的EN1 ,P1^0接L298N的IN0
if(P02==0) //接右1红外发射接收对管
{P14=0;P10=0;P11=1;} //右转,P1^4接L298N的EN1 ,P1^0接L298N的IN0
if( P01==1&&P02==1)
P10=0;P11=0;
} //寻迹程序
void main(void)
{
while(1)
{
pwm_moto2_go();
direction_moto1();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -