智能超声波测距仪项目设计学士学位论文(编辑修改稿)内容摘要:

程图 软件流程图 如 图 41 所示: 图 41 软件流程图 程序源代码 程序源代码如下 : /*************************************** 函数名: float Distance_count() 功能:距离计算函数 ****************************************/ float Distance_count() { float temp。 temp=high_time*256+low_time。 temp=(temp*10/9216)/2。 牡丹江师范学院学士学位论文(设计) 9 temp*=speed。 return temp。 } /*************************************** 函数名: void tran(), void tran1(), void tran2() 功能:超声波的发射 ****************************************/ void tran() { uchar i。 TH0=0。 TL0=0。 TR0=1。 for(i=4。 i0。 i) { csb=!csb。 nop。 nop。 nop。 nop。 nop。 nop。 nop。 nop。 牡丹江师范学院学士学位论文(设计) 10 nop。 } csb=1。 delay_ms(2)。 EX1=1。 delay_ms(30)。 if(flag==1) { distance=Distance_count()。 dis=(ulong)distance。 flag=0。 } else dis=0。 } void tran1() { uchar i。 TH0=0。 TL0=0。 TR0=1。 for(i=8。 i0。 i) { csb=!csb。 nop。 牡丹江师范学院学士学位论文(设计) 11 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。 牡丹江师范学院学士学位论文(设计) 12 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。 牡丹江师范学院学士学位论文(设计) 13 flag=0。 } else dis=0。 } /*************************************** 函数名: void dis_all(ulong dis_s) 功能:控制 LED 指示灯和语音播报 ****************************************/ void dis_all(ulong dis_s) { show(dis_s)。 if(dis_s2020) { show_one(DIS4,2)。 if(flag_2!=1) { send_oneline(12)。 //安全距离 delay_nms(50)。 while(!busy)。 } flag_2=1。 } else { 牡丹江师范学院学士学位论文(设计) 14 if((dis_s500)amp。 (dis_s1000)) { show_one(DIS5,2)。 if(flag_2!=2) { send_oneline(14)。 //保持距离 delay_nms(50)。 while(!busy)。 } flag_2=2。 } else { if((dis_s100)amp。 (dis_s500)) { show_one(DIS6,2)。 if(flag_2!=3) { send_oneline(15)。 //请注意 delay_nms(50)。 while(!busy)。 send_oneline(13)。 //危险距离 delay_nms(50)。 while(!busy)。 牡丹江师范学院学士学位论文(设计) 15 } flag_2=3。 } else { show_one(DIS8,2)。 } } } } /*************************************** 函数名: void main(void) 功能:主函数 ****************************************/ void main(void) { ulong data time。 uchar i,j。 P1 = 0xff。 P2 = 0xff。 TMOD=0x01。 TH0=0。 TL0=0。 EA=1。 牡丹江师范学院学士学位论文(设计) 16 IE=0x80。 displayall()。 while(1) { lcd_pos(4,0)。 //设置显示位置为第三行 for(i=0。 i16。 i++)。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。