**51单片机智能小车(舵机云台超声波避障+循迹+蓝牙+红外跟随+遥控+TFT液晶显示屏)
本人由于使用的液晶显示屏,程序大于8K,所以更换为STC12C5A60S2芯片,与51芯片兼容。
功能比较多:
1舵机云台超声波避障
2.循迹
3.蓝牙
4.红外跟随
5.遥控
按键切换模式和蓝牙切换模式可以会和使用。
布线比较乱,如果学习了PCB制版 可以很整洁。
超声波避障部分程序
{
if(S>300)
{
zhixing();
}
if(S<=300)
{
Stoping();
DJrighting(); //舵机云台you转30度
delayms1(2500);
ceju();
delayms1(200);
S1=S; //测距保存数据S1
LCD_Show2Num(35,50,S1,4);
delay(3000);
DJlefting(); //舵机zuo转30度
delayms1(2500);
ceju();
delayms1(200);
S2=S; //测距保存数据S2
LCD_Show2Num(35,75,S2,4);
delay(4000);
if(S1>S2) //比较两侧前方距离
{
BZ_flag=1; //左转前行标志
}
if(S1<=S2) //S1
{
BZ_flag=2; //右转前行标志
}
switch(BZ_flag)
{
case(1):
Righting();
FWing();
delayms1(2500);
zhixing();
break;
case(2):
Lefting();
FWing();
delayms1(2500);
zhixing();
break;
}
}
}
主函数
void main()
{
LCD_LED=1;
UartInit(); //蓝牙定时计2初始化程序
InitTime(); //电机定时器0初始化
Lcd_Init(); //tft初始化
LCD_Clear(WHITE); //清屏
BACK_COLOR=WHITE;;POINT_COLOR=RED;
xianshihanzi();
while(1)
{
Measure();
if(S4==0) //按键切换模式
{
delay(5);
if(S4==0)
{
while(!S4);
flag++; //更换模式
switch(flag)
{
case(1):
XJ_flag=1;T2CON=0;Stoping();
UartInit(); //蓝牙定时计2初始化程序
showhanzi(40,25,7); //循迹
showhanzi(55,25,8);
LCD_ShowString(70,25," ");
led1=0;led2=1;led3=1;led4=1;led5=1;break;
}
}
}
while(XJ_flag) //循迹模式
{
XunJi();
if(S4==0) //按键切换模式
{
delay(5);
if(S4==0)
{
while(!S4);
flag++; //更换模式
switch(flag)
{
case(2):
XJ_flag=0;HWBZ_flag=1;CSB_flag=0;HWYK_flag=0;Stoping();
UartInit(); //蓝牙定时计2初始化程序
showhanzi(40,25,9); //跟随
showhanzi(55,25,10);
LCD_ShowString(70,25," ");
led1=1;led2=0;led3=1;led4=1;led5=1;break;
}
}
}
}
**51单片机智能小车(舵机云台超声波避障+循迹+蓝牙+红外跟随+遥控+TFT液晶显示屏)
本人由于使用的液晶显示屏,程序大于8K,所以更换为STC12C5A60S2芯片,与51芯片兼容。
功能比较多:
1舵机云台超声波避障
2.循迹
3.蓝牙
4.红外跟随
5.遥控
按键切换模式和蓝牙切换模式可以会和使用。
布线比较乱,如果学习了PCB制版 可以很整洁。
超声波避障部分程序
{
if(S>300)
{
zhixing();
}
if(S<=300)
{
Stoping();
DJrighting(); //舵机云台you转30度
delayms1(2500);
ceju();
delayms1(200);
S1=S; //测距保存数据S1
LCD_Show2Num(35,50,S1,4);
delay(3000);
DJlefting(); //舵机zuo转30度
delayms1(2500);
ceju();
delayms1(200);
S2=S; //测距保存数据S2
LCD_Show2Num(35,75,S2,4);
delay(4000);
if(S1>S2) //比较两侧前方距离
{
BZ_flag=1; //左转前行标志
}
if(S1<=S2) //S1
{
BZ_flag=2; //右转前行标志
}
switch(BZ_flag)
{
case(1):
Righting();
FWing();
delayms1(2500);
zhixing();
break;
case(2):
Lefting();
FWing();
delayms1(2500);
zhixing();
break;
}
}
}
主函数
void main()
{
LCD_LED=1;
UartInit(); //蓝牙定时计2初始化程序
InitTime(); //电机定时器0初始化
Lcd_Init(); //tft初始化
LCD_Clear(WHITE); //清屏
BACK_COLOR=WHITE;;POINT_COLOR=RED;
xianshihanzi();
while(1)
{
Measure();
if(S4==0) //按键切换模式
{
delay(5);
if(S4==0)
{
while(!S4);
flag++; //更换模式
switch(flag)
{
case(1):
XJ_flag=1;T2CON=0;Stoping();
UartInit(); //蓝牙定时计2初始化程序
showhanzi(40,25,7); //循迹
showhanzi(55,25,8);
LCD_ShowString(70,25," ");
led1=0;led2=1;led3=1;led4=1;led5=1;break;
}
}
}
while(XJ_flag) //循迹模式
{
XunJi();
if(S4==0) //按键切换模式
{
delay(5);
if(S4==0)
{
while(!S4);
flag++; //更换模式
switch(flag)
{
case(2):
XJ_flag=0;HWBZ_flag=1;CSB_flag=0;HWYK_flag=0;Stoping();
UartInit(); //蓝牙定时计2初始化程序
showhanzi(40,25,9); //跟随
showhanzi(55,25,10);
LCD_ShowString(70,25," ");
led1=1;led2=0;led3=1;led4=1;led5=1;break;
}
}
}
}
举报