【正文】
tran1(){ uchar i。 TH0=0。 TL0=0。 TR0=1。 for(i=8。i0。i) { csb=!csb。 nop。 nop。 nop。 nop。 nop。 nop。 nop。 nop。 nop。 } csb=1。 delay_ms(2)。 EX1=1。 delay_ms(30)。 if(flag==1) { distance=Distance_count()。 dis=(unsigned long)distance。 flag=0。 } else dis=0。}void tran2(){ uchar i。 TH0=0。 TL0=0。 TR0=1。 for(i=16。i0。i) { csb=!csb。 nop。 nop。 nop。 nop。 nop。 nop。 nop。 nop。 nop。 } csb=1。 delay_ms(2)。 EX1=1。 delay_ms(40)。 if(flag==1) { distance=Distance_count()。 dis=(unsigned long)distance。 flag=0。 } else dis=0。}/***************************************函數(shù)名:void dis_all(ulong dis_s)功能:控制LED指示燈****************************************/void dis_all(ulong dis_s){ show(dis_s)。 if(dis_s2000) { show_one(DIS4,2)。 green=0。red=1。yellow=1。 if(flag_2!=1) { send_(16)。//send_(16)。 delay_nms(50)。 while(!busy)。 } flag_2=1。 } else { if((dis_s500)amp。(dis_s1000)) { show_one(DIS5,2)。 green=1。red=1。yellow=0。 if(flag_2!=2) { send_(18)。 delay_nms(50)。 while(!busy)。 } flag_2=2。 } else { if((dis_s100)amp。(dis_s500)) { show_one(DIS6,2)。 green=1。red=0。yellow=1。 if(flag_2!=3) { send_(19)。 delay_nms(50)。 while(!busy)。 send_(17)。 delay_nms(50)。 while(!busy)。 } flag_2=3。 } else { show_one(DIS8,2)。 yellow=1。 if(dis_s100) { red=!red。green=1。} else {green=!green。red=1。} } } }}/***************************************函數(shù)名:void fit_1(void)功能:取最大值****************************************/void fit_1(void){ dis=dis_4[2]。 if(dis_4[0]dis) dis=dis_4[0]。 if(dis_4[1]dis) dis=dis_4[1]。}/***************************************函數(shù)名:void main(void)功能:主函數(shù)****************************************/ void main(void){ data ulong time。 uchar i,j。 P0 = 0xff。 P1 = 0xff。 P2 = 0xff。 TMOD=0x01。 TH0=0。 TL0=0。 EA=1。 IE=0x80。 displayall()。 while(1) { for(i=0。i3。i++) { tran()。 if(dis==0) { tran1()。 if(dis==0) {tran2()。} } dis=do_s(dis)。 dis_4[i]=dis。 } fit_1()。 if(distime) { if((timedis)4000) time=time1000。 else { if((timedis)2500) time=dis。 else time=time100。 } } else time=dis。 dis_all(time)。 if(tc_say==4) { soundplay(time)。 tc_say=0。 temp_all()。 } tc_say++。 lcd_pos(1,6)。 for(j=0。j4。j++) write(1,space4[j])。 lcd_pos(1,6)。 for(j=0。j4。j++) { write(1,point4[j])。 delay(100)。 } }}/***************************************函數(shù)名:void TT() interrupt 2功能:中斷,產(chǎn)生脈沖****************************************/void TT() interrupt 2{ uint temp。 TR0=0。 ET1=0。 flag=1。 temp=TH0*256+TL0。 if((temp0)amp。amp。(temp30000)) { high_time=TH0。 low_time=TL0。 } else { high_time=0。 low_time=0。 } }The Research about Fuzzy Collision Avoidance in Ultrasonic Ranging Robots Electronic and Information Engineering *******Tutor *****Abstract: When mobile robots working, it interfere inevitably by obstructions, obstacles will affect seriously in the efficiency of the robot, serious collide may make the robots breakage, so it is very important to achieve the robot avoided obstacle automatic. This paper based on the mon use of sensors , analyzes the intelligent mobile robot how to obstacle avoidance, based on ultrasonic sensor, proposed a system about the fuzzy distance of the mobile robot obstacle avoidance, and write up in details about the principles and characteristics of ultrasonic sensors, the core used is AT89C52 MCU and let ultrasonic range finder to detect obstacles, through the signal processing on MCU, motordriven steering the azimuth, make it turn left ,right ,go and back, so as to achieve the function about the automatic obstacle avoidance .Study through the practice is easy to accept and understand of fuzzy control mechanism and strategy for obstacle avoidance, it will more convenient for application and development, fuzzy obstacle avoidance algorithm has great adaptability to the environment, the robot can be achieved the obstacle avoidance under different environmental conditions. Key words: AT89C52 microcontroller。 mobile robot。 ultrasonic sensors。 Ultrasonic Ranging 33