📄 yydcld.asm
字号:
#include<P16C712.inc>
ORG 0x0000
CALL Label_0001 ;初始化
MOVLW 0x04
CALL delay500ms ;delay 500ms
GOTO start
;========================================================
;
;========================================================
MOVWF 0x20
SWAPF STATUS , W
CLRF STATUS
MOVWF 0x21
MOVF PCLATH , W
MOVWF 0x23
CLRWDT
BCF 0x0C , 01
MOVF 0x23 , W
MOVWF PCLATH
SWAPF 0x21 , W
MOVWF STATUS
SWAPF 0x20 , f
SWAPF 0x20 , W
RETFIE
;=======================================================
;
;=======================================================
ADDWF PCL , f
RETLW 0xFF
RETLW 0xFE
RETLW 0xFE
RETLW 0xFC
RETLW 0xFC
RETLW 0xF8
RETLW 0xF8
RETLW 0xF0
RETLW 0xF0
RETLW 0xE0
RETLW 0xE0
RETLW 0xC0
RETLW 0xC0
RETLW 0x00
RETLW 0x00
RETLW 0x00
RETLW 0x00
RETLW 0x00
start CALL detect_sensor
CALL speak_indication
MOVLW 0x06
MOVWF 0x6F
start1 CALL measure1
CALL measure2
CALL measure3
CALL measure4
DECFSZ 0x6F , f
GOTO start1
main CALL measure1
CALL measure2
CALL speak_off
CALL measure3
CALL measure4
CALL assort
CALL speak_on
GOTO main
;================================================================
;发送并接收探头1
;=================================================================
measure1 CLRF 0x0E ;tmr1l tmr1h
CLRF 0x0F
BTFSC 0x25 , 00
GOTO is_error1 ;如果故障,则直接赋一个大值
CALL measure_distance
Label_001F CALL move_ram1
CALL copy1
CALL sort
CALL average
MOVF 0x7C , W
MOVWF 0x3C
MOVF 0x7D , W
MOVWF 0x3D
GOTO wait32ms
;===================================================================
;连续5次超过0.43m的最近距离,才恢复实际距离,0x24 标志 0x3e记数
;===================================================================
measure_distance
CALL send_no1_ultra
MOVLW 0x0E
CALL delay100nus
BTFSC PORTB , 04
GOTO Label_0018
Label_001A BTFSC PORTB , 04
GOTO Label_0019 ;1.5m 内收到回波
MOVLW 0x23
SUBWF 0x0F , W
BTFSS STATUS , C
GOTO Label_001A ;继续检测
MOVLW 0x55
SUBWF 0x0E , W
BTFSS STATUS , C
GOTO Label_001A ;继续检测 0x2355us(1.5m)内测试返回脉冲
BTFSS 0x24 , 00
GOTO Label_001B ;大于1.53m
DECFSZ 0x3E , f
GOTO Label_001C
BCF 0x24 , 00
Label_001B MOVLW 0x23 ;大于1.5m
MOVWF 0x7E
MOVLW 0x5B
MOVWF 0x7F
RETURN
Label_0018 BSF 0x24 , 00 ;小于0.43米直接置数0x055c(0.23m)
MOVLW 0x05
MOVWF 0x3E
Label_001C MOVLW 0x05
MOVWF 0x7E
MOVLW 0x5C
MOVWF 0x7F
RETURN
Label_0019 MOVF 0x0F , W
MOVWF 0x7E
MOVF 0x0E , W
MOVWF 0x7F ;读取回波时间防在7e,7f中
CALL delay50us
BTFSS PORTB , 04 ;回波脉冲小于50us 干扰
GOTO Label_001A
MOVLW 0x0A
SUBWF 0x7E , W
BTFSC STATUS , C
GOTO Label_001E ;大于等于0x0a00,大于4.3公分
MOVLW 0x00
SUBWF 0x7F , W
BTFSS STATUS , C
GOTO Label_0018 ;小于0x0a00 ,与0相减肯定执行这一行
Label_001E BTFSS 0x24 , 00
RETURN
DECFSZ 0x3E , f
GOTO Label_001C
BCF 0x24 , 00
RETURN
;=================================================================
is_error1 MOVLW 0x25
MOVWF 0x7E
CLRF 0x7F
GOTO Label_001F
;==================================================================
;发送并接收探头2
;=================================================================
measure2 CLRF 0x0E
CLRF 0x0F
BTFSC 0x25 , 01
GOTO Label_0020
CALL Label_0021
Label_002B CALL move_ram2
CALL copy2
CALL sort
CALL average
MOVF 0x7C , W
MOVWF 0x4C
MOVF 0x7D , W
MOVWF 0x4D
GOTO wait32ms
Label_0021 CALL send_no2_ultra
MOVLW 0x0E
CALL delay100nus
BTFSC PORTB , 05
GOTO Label_0025
Label_0027 BTFSC PORTB , 05
GOTO Label_0026
MOVLW 0x23
SUBWF 0x0F , W
BTFSS STATUS , C
GOTO Label_0027
MOVLW 0x55
SUBWF 0x0E , W
BTFSS STATUS , C
GOTO Label_0027
BTFSS 0x24 , 01
GOTO Label_0028
DECFSZ 0x3F , f
GOTO Label_0029
BCF 0x24 , 01
Label_0028 MOVLW 0x23
MOVWF 0x7E
MOVLW 0x5B
MOVWF 0x7F
RETURN
Label_0025 BSF 0x24 , 01
MOVLW 0x05
MOVWF 0x3F
Label_0029 MOVLW 0x05
MOVWF 0x7E
MOVLW 0x5C
MOVWF 0x7F
RETURN
Label_0026 MOVF 0x0F , W
MOVWF 0x7E
MOVF 0x0E , W
MOVWF 0x7F
CALL delay50us
BTFSS PORTB , 05
GOTO Label_0027
MOVLW 0x0A
SUBWF 0x7E , W
BTFSC STATUS , C
GOTO Label_002A
MOVLW 0x00
SUBWF 0x7F , W
BTFSS STATUS , C
GOTO Label_0025
Label_002A BTFSS 0x24 , 01
RETURN
DECFSZ 0x3F , f
GOTO Label_0029
BCF 0x24 , 01
RETURN
Label_0020 MOVLW 0x25
MOVWF 0x7E
CLRF 0x7F
GOTO Label_002B
;===============================================================================================
;发送并接收探头3
;==============================================================================================
measure3 CLRF 0x0E
CLRF 0x0F
BTFSC 0x25 , 02
GOTO Label_002C
CALL Label_002D
Label_0037 CALL move_ram3
CALL copy3
CALL sort
CALL average
MOVF 0x7C , W
MOVWF 0x5C
MOVF 0x7D , W
MOVWF 0x5D
GOTO wait32ms
Label_002D CALL send_no3_ultra
MOVLW 0x0E
CALL delay100nus
BTFSC PORTB , 06
GOTO Label_0031
Label_0033 BTFSC PORTB , 06
GOTO Label_0032
MOVLW 0x23
SUBWF 0x0F , W
BTFSS STATUS , C
GOTO Label_0033
MOVLW 0x55
SUBWF 0x0E , W
BTFSS STATUS , C
GOTO Label_0033
BTFSS 0x24 , 02
GOTO Label_0034
DECFSZ 0x4E , f
GOTO Label_0035
BCF 0x24 , 02
Label_0034 MOVLW 0x23
MOVWF 0x7E
MOVLW 0x5B
MOVWF 0x7F
RETURN
Label_0031 BSF 0x24 , 02
MOVLW 0x05
MOVWF 0x4E
Label_0035 MOVLW 0x05
MOVWF 0x7E
MOVLW 0x5C
MOVWF 0x7F
RETURN
Label_0032 MOVF 0x0F , W
MOVWF 0x7E
MOVF 0x0E , W
MOVWF 0x7F
CALL delay50us
BTFSS PORTB , 06
GOTO Label_0033
MOVLW 0x0A
SUBWF 0x7E , W
BTFSC STATUS , C
GOTO Label_0036
MOVLW 0x00
SUBWF 0x7F , W
BTFSS STATUS , C
GOTO Label_0031
Label_0036 BTFSS 0x24 , 02
RETURN
DECFSZ 0x4E , f
GOTO Label_0035
BCF 0x24 , 02
RETURN
Label_002C MOVLW 0x25
MOVWF 0x7E
CLRF 0x7F
GOTO Label_0037
;===============================================================================================
;发送并接收探头4
;==============================================================================================
measure4 CLRF 0x0E
CLRF 0x0F
BTFSC 0x25 , 03
GOTO Label_0038
CALL Label_0039
Label_0043 CALL move_ram4
CALL copy4
CALL sort
CALL average
MOVF 0x7C , W
MOVWF 0x6C
MOVF 0x7D , W
MOVWF 0x6D
GOTO wait32ms
Label_0039 CALL send_no4_ultra
MOVLW 0x0E
CALL delay100nus
BTFSC PORTB , 07
GOTO Label_003D
Label_003F BTFSC PORTB , 07
GOTO Label_003E
MOVLW 0x23
SUBWF 0x0F , W
BTFSS STATUS , C
GOTO Label_003F
MOVLW 0x55
SUBWF 0x0E , W
BTFSS STATUS , C
GOTO Label_003F
BTFSS 0x24 , 03
GOTO Label_0040
DECFSZ 0x4F , f
GOTO Label_0041
BCF 0x24 , 03
Label_0040 MOVLW 0x23
MOVWF 0x7E
MOVLW 0x5B
MOVWF 0x7F
RETURN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -