1、sbit O3=P32; /投球sbit O4=P33;sbit O5=P34;sbit O6=P35;sbit O7=P36;sbit O8=P37;bit W_0; /传感器低8位bit W_1;bit W_2;bit W_3;bit W_4;bit W_5;bit W_6;bit W_7;sbit P0_0=P00; /红蓝sbit P0_1=P01;sbit P0_2=P02;sbit P0_3=P03;sbit P0_4=P04; /左限位sbit P0_5=P05; /右限位sbit P0_6=P06;sbit P0_7=P07; /接近开关unsigned char num,c=
2、0,jp=0,j,co,ball=0,sener;unsigned char mode;#define l 1 /左电机#define r 2 /右电机#define rl 3 /#define S_B 70 /基准占空比设置#define f f /代表电机正转#define forward #define b b /代表电机反转#define backward /*=【函数原形】:void pwm0_1() 【功能说明】:PCA时钟源 控制寄存器 计数初值 设置2011年1月20日=*/void pwm0_1() CCON=0x00; CH=0; CL=0; CMOD=0x00;void
3、PWM0(unsigned char Fosc_1) 【参数说明】:Fosc_0 Fosc_0为占空比设置形参void PWM0(unsigned int Fosc_0) /Fosc_0为占空比设置形参 CCAP0H=CCAP0L=(Fosc_0)*25)/10; CCAPM0=0X42; /8位PWM输出,无中断 PCA_PWM0=0x00;void PWM1(unsigned char Fosc_1) Fosc_1 Fosc_1为占空比设置形参void PWM1(unsigned int Fosc_1) CCAP1H=CCAP1L=(Fosc_1)*25)/10; CCAPM1=0X42;
4、 PCA_PWM1=0x00;void delay_ms(unsigned int T)T 延时时间设定【函数功能】:ms级延时函数 unsigned int CON; unsigned int i; for(i=0;iT;i+) for(CON=0;CON8) for(co=0;co=60)&(S_B80) /基准速度大于80时的巡线程序 if(W_7& motor(r,f,S_B); motor(l,f,S_B); n=0; else if(W_7) motor(r,f,S_B-10); motor(l,f,S_B+10); else if(WP_8) motor(r,f,S_B+10);
5、 motor(l,f,S_B-10); else if(W_6) motor(r,f,S_B-20); n-; else if(WP_9) motor(l,f,S_B-20); n+; else if(W_5) motor(r,f,S_B-50); else if(WP_10) motor(l,f,S_B-50); else if(W_4) motor(r,f,S_B-60); else if(WP_11) motor(l,f,S_B-60); else if(W_3) n-; else if(WP_12) n+; else if(W_2) motor(r,f,S_B-70); else if
6、(WP_13) motor(l,f,S_B-70); else if(W_1) motor(r,f,S_B-80); else if(WP_14) else if(W_0) else if(WP_15) motor(l,f,S_B-80); else if(!(W_0&W_1&W_2&W_3&W_4&W_5&W_6&W_7&WP_8&WP_9&WP_10&WP_11&WP_12&WP_13&WP_14&WP_15)&n DIR_0=1; DIR_1=0; motor(r,f,60); motor(l,b,60); if(WP_8)(WP_8); void TURN_90()控制左右转向 201
7、1年2月17日void TURN_90(unsigned char e) delay_ms(150); PWM0(0); PWM1(0); delay_ms(10); if(e=r) /右转控制选择语句/右/左 motor(r,b,75); motor(l,f,65); delay_ms(1000); if(W_5|W_4|W_3)(W_5|W_4|W_3); if(e=l) /左转控制选择语句 motor(l,b,80); if(WP_10|WP_11|WP_12)(WP_10|WP_11|WP_12); delay_ms(20); /延时等待继电器动作 void TURN_90l()void TURN_901(unsigned char h) if(h=r) /右转控制选择语句 motor(r,b,6
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2