• 易迪拓培训,专注于微波、射频、天线设计工程师的培养
首页 > 测试测量 > 技术文章 > 基于单片机的超声波测距仪LED显示电路的设计

基于单片机的超声波测距仪LED显示电路的设计

录入:edatop.com    点击:

附录二:程序调试

VOUT EQU P1.0

ORG  0000H

LJMP START

ORG  0003H

LJMP PINT0

ORG  000BH

LJMP INTT0

ORG  0013H

RETI

ORG  001BH

LJMP INTT1

ORG  0023H

RETI

ORG  002BH

RETI

;***********主程序**************

START: MOV  SP,#4FH

MOV  R0,#40H

MOV  R7,#0BH

CLEARDISP:MOV  @R0, #00H

INC  R0

DJNZ R7,CLEARDISP

MOV  20H, #00H

MOV  TMOD,21H

MOV  TH0, #00H

MOV  TL0,00H

MOV  TH1,0F2H

MOV  TL1,0F2H

MOV  P0, 0FFH

MOV  P1, 0FFH

MOV  P2, 0FFH

MOV  P3, 0FFH

MOV  R4, 04H

SETB PX0

SETB ET0 

SETB EA 

SETB TR0

START1:   LCALL DISPLAY

JNB   00H,START1

CLR EA

LCALL WORK

SETB  EA

CLR 00H

SETB  TR0

MOV  R2,#64H

LOOP:     LCALL DISPLAY

DJNZ R2,LOOP

SJMP START1

INTT0: CLR  EA

CLR  TR0

MOV  TH0,#00H

MOV  TL0,#00H

SETB ET1

SETB EA

SETB TR0

SETB TR1

OUT :   RET

;T1中断,发超声波用:

INTT1 : CPL  VOUT

DJNZ R4,RETIOUT

CLR  TR1

CLR  ET1

MOV  R4,#04H

SETB EX0

RETIOUT:RETI

;外中断0,收到回波时进入

PINT0: CLR TR0

CLR TR1

CLR ET1

CLR  EA

CLR  EX0

MOV  44H,TL0

MOV  45H,TH0

SETB 00H

RETI

;*****显示程序:**********

DISPLAY:MOV R1, #40H;G

MOV R5,#0F7H;G

PLAY:   MOV A,R5

MOV P0,#0FFH

MOV P2,A

MOV A,@R1

MOV DPTR,#TAB

MOVC A,@A+DPTR

MOV P0,A

LCALL DL1MS

INC R1

MOV A,R5

JNB ACC.0,ENDOUT;G

RR A

MOV R5,A

AJMP PLAY

ENDOUT:        MOV R2,#0FFH

MOV P0,#0FFH

RET

TAB:           DB   0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0FFH,88H,0BFH

; 共阳段码管        "0","1","2","3","4","5","6","7","8","9","不亮","A","-"

;延时程序:

DL1MS:        MOV  R6,#14H

DL1:          MOV  R7,#19H

DL2:           DJNZ R7,DL2

DJNZ R6,DL1

RET

;*** ****距离计算程序**********

WORK: PUSH    ACC

PUSH    PSW

PUSH    B

MOV     PSW,#18H

MOV   R3,45H

MOV   R2,44H

MOV   R1,00D

MOV   R0,17D

LCALL MUL2BY2

MOV   R3,#03H

MOV   R2,0E8H

LCALL DIV4BY2

LCALL DIV4BY2

MOV   40H,R4

MOV   A,40H

JNZ   JJ0

MOV   40H,#0AH

JJ0: MOV   A, R0

MOV   R4,  A

MOV   A,   R1

MOV   R5,  A

MOV   R3,  00D

MOV   R2, #100D

LCALL DIV4BY2

MOV   41H,R4

MOV   A,41H

JNZ   JJ1

MOV   A,40H

SUBB  A,#0AH

JNZ   JJ1

MOV 41H,#0AH

JJ1:  MOV A,R0

MOV R4,A

MOV A,R1

MOV R5,A

MOV R3,#00D

MOV R2,10D

LCALL DIV4BY2

MOV 42H,R4

JNZ JJ2

MOV A,41H

SUBB A,#0AH

JNZ JJ2

MOV 42H,#0AH

JJ2:  MOV 43H,R0

POP B

POP PSW

POP ACC

RET

MUL2BY2:CLR  A

MOV  R7,A

MOV  R6,A

MOV  R5,A

MOV  R4,A

MOV  46H,#10H

MULLOOP1:CLR C

MOV A,R4

RLC A

MOV R4,A

MOV A,R5

RLC A

MOV R5,A

MOV A,R6

RLC A

MOV R6,A

MOV A,R7

RLC A

MOV R7,A

MOV A,R0

RLC A

MOV R0,A

MOV A,R1

RLC A

MOV R1,A

JNC MULLOOP2

MOV A,R4

ADD A,R2

MOV R4,A

MOV A,R5

ADDC A,R3

MOV R5,A

MOV A,R6

ADDC A,#00H

MOV R6,A

MOV A,R7

ADDC A,#00H

MOV R7,A

MULLOOP2:DJNZ 46H,MULLOOP1

RET

DIV4BY2:MOV 46H,#20H

MOV R0,#00H

MOV R1,#00H

DIVLOOP1:MOV A,R4

RLC A

MOV R4,A

MOV A,R5

RLC A

MOV R5,A

MOV A,R6

RLC A

MOV R6,A

MOV A,R7

RLC A

MOV R7,A

MOV A,R0

RLC A

MOV R0,A

MOV A,R1

RLC A

MOV R1,A

CLR C

MOV A,R0

SUBB A,R3

JC DIVLOOP2

MOV R0,B

MOV R1,A

DIVLOOP2:CPL C

DJNZ 46H,DIVLOOP1

MOV A,R4

RLC A

MOV R4,A

MOV A,R5

RLC A

MOV R5,A

MOV A,R6

RLC A

MOV R6,A

MOV A,R7

RLC A

MOV R7,A

RET

END       <PIXTEL_MMI_EBOOK_2005>9                                                           </PIXTEL_MMI_EBOOK_2005>

来源:网易

点击浏览:矢量网络分析仪、频谱仪、示波器,使用操作培训教程

上一篇:基于单片机的超声波测距仪的主要硬件电路
下一篇:CMOS探测器在射线检测中的设计应用

微波射频测量操作培训课程详情>>
射频和天线工程师培训课程详情>>

  网站地图