超声波测距仪超声波测距仪1任务说明2任务分析3流程图4程序超声波测距仪任务说明利用超声波探头测距离,显示计数值(时间)超声波测距仪任务分析(1)通过T1定时,产生T探头的激励信号(40KHZ)(2)通过T0记录发射接收间的时间差(计数值),T0方式1定时值000H(3)外部中断0:关闭T0、T1,读时间TH0、TL0超声波测距仪任务分析(4)显示:4位显示,显示单元由TH0、TL0刷新T0:定时方式1T1:定时方式2(8位自动重装初值)外部中断:每次中断翻转P1.0状态,且要连续中断4次(2个脉冲)CycleDiagram流程图主程序流程图INT0流程图T0中断流程图超声波测距仪30H、31H、70H~73H清零定时器初始化中断初始化启动T0调用DIS00H?调用拆字刷新显示CLR00H启动T0调用100次动态显示开始超声波测距仪开始CLRTR0重装初值启动T1开T1中断启动T0RET超声波测距仪进入CLRTR0CLRET0关中断TH031HTL030H00H返回•INT00003H•T0000BH•T1001BH中断入口程序CPLP1.0DJNZR5,OUTCLRTR1CLRET1SETBEX0MOVR5,#4中断程序DiagramORG0000HLJMPSTORG0003HLJMPIN_0ORG000BHLJMPT_0ORG001BHLJMPT_1ORG0100HST:MOV30H,#0MOV31H,#0MOV70H,#0MOV71H,#0MOV72H,#0MOV73H,#0MOV20H,#00HMOVR4,#4MOVTMOD,#21HMOVTH0,#00HMOVTL0,#00HMOVTH1,#0F3HMOVTL1,#0F3HSETBEASETBET0SETBTR0SETBEX0L1:LCALLDISJNB00H,L1LCALLCOVCLR00HSETBTR0MOVR2,#250LOOP:LCALLDISDJNZR2,LOOP超声波测距仪SJMPL1;;;;;;;;;;;;;;;;;;;;;;;;;;;T_0:CLRTR0CLREAMOVTH0,#00HMOVTL0,#00HSETBET1SETBEASETBTR0SETBTR1RETIT_1:CLRP1.0DJNZR4,OUTCLRTR1CLRET1SETBEX0MOVR4,#4OUT:RETIIN_0:CLRTR0CLRET0CLREACLREX0MOV30H,TH0MOV31H,TH0SETB00HRETIDIS:MOVP2,#0FEHMOVA,70HMOVDPTR,#TABMOVCA,@A+DPTRMOVP0,AMOVR6,#100DJNZR6,$MOVP2,#0FDHMOVA,71HMOVCA,@A+DPTRMOVP0,ADiagramMOVR6,#100DJNZR6,$MOVP2,#0FBHMOVA,72HMOVDPTR,#TABMOVCA,@A+DPTRMOVP0,AMOVR6,#100DJNZR6,$MOVP2,#0F7HMOVA,73HMOVDPTR,#TABMOVCA,@A+DPTRMOVP0,AMOVR6,#100DJNZR6,$RETTAB:DB0C0H,0F9H,0A4H,0DBB0H,DB99H,92H,82H,0F8H,DB80H,90HDB88H,83H,0C6H,0A1H,DB86H,8EHCOV:MOVA,30HANLA,#0FHMOV70H,AMOVA,30HSWAPAANLA,#0FHMOV71H,AMOVA,31HANLA,#0FHMOV72H,AMOVA,31HSWAPAANLA,#0FHMOV73H,ARETEND