1、智能循迹避障小车完整程序亲测好使/ VXyx Tx 7 |/利用51定时器产生PWM波来调节电机速度/速度变化范围从0-100可调/使用三路做寻迹使用,哪一路检测在黑线哪一路为/高电平没检测到黑线表示有反射对应输出低电平信号K fT 7#include#define uint unsigned int#define uchar unsigned char/*电机四个接口定义*/sbit ini二P00;sbit in2二P(T1;sbit in3二P02;sbit in4二P03;/*计时器*/uchar j, k, i, a, Al, A2, second, minge, minshi ;s
2、bit dula=P26;sbit wela=P27;uchar code table = 0x3f, 0x06, 0x5b, 0x4f,0x66, 0x6d, 0x7d, 0x07,0x7f, 0x6f, 0x77, 0x7c,0x39, 0x5e, 0x79, 0x71;uchar code table2 = 0xbf, 0x86, Oxdb, Oxcf,0xe6, Oxed, Oxfd, 0x87,Oxff, Oxef, 0xf7, Oxfc,0xb9, Oxde, 0xf9, Oxfl;void delay (uchar i)for(j=i; j0; j)for(k=110;k0;k)
3、;void display(uchar sh_c, uchar g_c, uchar min_ge, uchar min_shi) dula=l;Portablesh_c;dula=0;PO二Oxff;wela=l;PO二Oxfb;wela=0;delay(5);dula=l;Portableg_c;dula=O;PO二Oxff;wela=l;PO二Oxf7;wela=0;delay (5);dula=l;Portablemin_shi;dula=0;PO二Oxff;wela=l;P0=0xfe;wela=0;delay (5);dula=l;P0=table2min_ge;dula=0;PO
4、二Oxff;wela=l;PO二Oxfd;wela=0;delay (5);/*左、中、右三路循迹传感器接口定义*/ sbit zuo二P1O;sbit zhong二Pl1;sbit you二Pl2;/*避障接口定义*/sbit bz_zuo二P3/3;sbit bz_zhong二P3/4;sbit bz_you二P3/5;uchar count 二 0;/*利用定时器0定时中断,产生PWM波*/void Init_timer()THO = (65535-10)/256;TLO = (65535-10)%256;TMOD = 0x01;TRO 二 1;ETO 二 1;EA = 1;/*左轮速度调节程序*/void zuolun(uchar speed)辻(count = speed) /count 计数变量ini = 1;in2 = 0;elseini = 0;in2 = 1;/同上void youlun(uchar speed)if (count0;a-)display (Al, A2, minge, minshi);;void TimerO_int () interrupt 1 定时器中断计数THO = (65535-10)/256;TLO = (65535-10)%256;count +;if(count = 100)count = 0