当前位置:首页 > 西北农林科技大学智能小车实习总结(完整版) - 图文
} }
2.3.3直流电机小车测速任务实现 ①直流电机小车测速任务实现程序:
void timer0()interrupt 1
using 2
{
2.3.4直流电机小车四路寻迹任务实现 ①直流电机小车四路寻迹任务实现程序 #include
disbuff[1]=V00/100;
disbuff[2]=V000/10;
disbuff[3]=V000;
} void
}
TH0=(65536-2000)/256; TL0=(65536-2000)%6; time++; Display_SMG(); if(time>=250) {
time=0; V=count1*2; count1=0;
disbuff[0]=V/1000;
intersvr1(void)interrupt 0 using 1000
{ }
count1++
{P1_4=0,P1_5=0,P1_6=0,P1_7=0;}
void delay(unsigned int k) { }
//全速前进 void run(void) { }
//全速后退
void backrun(void) {
- 18 -
unsigned int x,y; for(x=0;x for(y=0;y<125;y++); Left_moto_go Left_moto_back Left_moto_Stop Right_moto_go Right_moto_back Right_moto_Stop {P1_0=1,P1_1=0,P1_2=1,P1_3=0;} {P1_0=0,P1_1=0,P1_2=0,P1_3=1;} {P1_0=0,P1_1=0,P1_2=0,P1_3=0;} {P1_4=1,P1_5=0,P1_6=1,P1_7=0;} {P1_4=0,P1_5=1,P1_6=0,P1_7=1;} Left_moto_go; Right_moto_go; } Left_moto_back Right_moto_back } /*--主函数--*/ void main(void) { 动状态 } } delay(100); run(); while(1) { run();//将run()改成 //左转 void leftrun(void) { } //右转 void rightrun(void) { Left_moto_go; Right_moto_back; Left_moto_back; Right_moto_go; 其他三种运动状态即可实现其他三种运 2.3.5直流电机小车避障任务实现 ①直流电机小车避障任务实现程序: #include Left_moto_go Left_moto_back Left_moto_Stop Right_moto_go Right_moto_back Right_moto_Stop {P1_0=1,P1_1=0,P1_2=1,P1_3=0;} {P1_0=0,P1_1=0,P1_2=0,P1_3=1;} {P1_0=0,P1_1=0,P1_2=0,P1_3=0;} {P1_4=1,P1_5=0,P1_6=1,P1_7=0;} {P1_4=0,P1_5=1,P1_6=0,P1_7=1;} {P1_4=0,P1_5=0,P1_6=0,P1_7=0;} void delay(unsigned int k) { - 19 - } unsigned int x,y; for(x=0;x for(y=0;y<125;y++); //全速前进 void run(void) { } //全速后退 void backrun(void) { } //左转 void leftrun(void) { Left_moto_back Right_moto_back Left_moto_go; Right_moto_go; } Left_moto_back; Right_moto_go; { 2_led==1) 1) } } { backrun(); rightrun(); } else { } else { } backrun(); backrun(); leftrun(); } if(Left_1_led==0&&Right_2_led== { } else { run(); if(Left_1_led==1&&Right_ //右转 void rightrun(void) { } /*--主函数--*/ void main(void) { 动状态 } void main(void) { while(1) 2.3.6直流电机小车红外遥控任务实现 ①直流电机小车红外遥控任务实现程序: #include - 20 - Left_moto_go; Right_moto_back; delay(100); run(); while(1) { run();//将run()改成if(Right_2_led==0&&Left_1_led==1) 其他三种运动状态即可实现其他三种运 } if(Left_1_led==0&&Right_2_led==0) delay(100); { } run(); #define Right_2_led P3_7 #define #define Left_moto_go Left_moto_back {P1_0=1,P1_1=0,P1_2=1,P1_3=0;} {P1_0=0,P1_1=0,P1_2=0,P1_3=1;} #define #define #define #define {P1_0=0,P1_1=0,P1_2=0,P1_3=0;} Right_moto_go Right_moto_back Right_moto_Stop {P1_4=1,P1_5=0,P1_6=1,P1_7=0;} {P1_4=0,P1_5=1,P1_6=0,P1_7=1;} {P1_4=0,P1_5=0,P1_6=0,P1_7=0;} #define Imax 14000 #define Imin 8000 #define Inum1 1450 #define Inum2 700 #define Inum3 3000 unsigned char f=0; unsigned Im[4]={0x00,0x00,0x00,0x00}; unsigned char show [2] = {0,0}; unsigned long m,Tc; unsigned char IrOK; //延时 void delay(unsigned int k) { } //外部中断解码程序 void intersvr1(void)interrupt 2 using 1 { TL0=0; if(Tc>Imin)&&(Tc m=0; f=1; return; Left_moto_Stop //定时中断重新置零 } if(f==1) { //找到起始码 if(Tc>Inum1&&Tc } m++; { char Im[m/8]=Im[m/8]>>1|0x80; if(Tc>Inum2&&Tc } if(m==32) { m=0; f=0; if(Im[2]==~Im[3]) { } { Im[m/8]=Im[m/8]>>1; m++; unsigned int x,y; for(x=0;x for(y=0;y<125;y++); //取码 Tc=TH0*256+TL0TH0=0; ; IrOK = 1; - 21 - //提取中断时间间隔时长 else IrOK = 0;
共分享92篇相关文档