English
Language : 

AN597 Datasheet, PDF (7/8 Pages) Microchip Technology – Implementing Ultrasonic Ranging
AN597
0014 018E 0069 clrf TMR1L
; Clear TMR1L
0015 018F 0070 clrf TMR1H
; Clear TMR1H
0016 0195 0071 clrf CCPR1L
; Clear CCPR1L
0017 0196 0072 clrf CCPR1H
; Clear CCPR1H
0018 1409 0073 bsf
PORT_E,0
; Set INIT High on Ranging Module
0019 1410 0074 bsf
T1CON,0
; Enable TMR1
001A 21F3 0075 call DEL_9
; Delay 0.9 msec for transducer to stabilize
001B 1489 0076 bsf
PORT_E,1
; Enable Transducer to Receive (BINH)
001C
0077 chk_t1
001C 190C 0078 btfsc PIR1,2
; Check for Capture
001D 2822 0079 goto chk_done
; Jump if Capture
001E 1C0C 0080 btfss PIR1,0
; Check for TMR1 Overflow
001F 281C 0081 goto chk_t1
; Loop if nothing happened
0020 1010 0082 bcf
T1CON,0
; Turn off TMR1
0021 2833 0083 goto ovr_flo
; Capture event did not occur
0022
0084 chk_done
0085 ;
0086 ; Calculate distance to 0.5 inch resolution
0087 ;
0022 1010 0088 bcf
T1CON,0
; Turn off TMR1
0023 0815 0089 movf CCPR1L,W
; Move LSB into W
0024 00A2 0090 movwf ACCbLO
; Move LSB into ACCbLO
0025 0816 0091 movf CCPR1H,W
; Move MSB into W
0026 00A3 0092 movwf ACCbHI
; Move MSB into ACCbHI
0027 304A 0093 movlw 0x4A
; Move 75usec/0.50in into W
0028 00A0 0094 movwf ACCaLO
; Move LSB into ACCaLO
0029 01A1 0095 clrf ACCaHI
; Clear MSB (ACCaHI)
002A 208F 0096 call D_divF
; Call 16-bit/8-bit routine
0097
; which is described in
0098
; Application Note 544
002B 3025 0099 movlw 0x25
; Check remainder to see if
002C 0224 0100 subwf ACCcLO,W
; we should round up...
002D 1803 0101 btfsc STATUS,CARRY
; If Remainder < (0.5 * Divisor), skip
002E 0AA2 0102 incf ACCbLO,F
; Round up
002F 1903 0103 btfsc STATUS,Z
; Check low byte for wrap around
0030 0AA3 0104 incf ACCbHI,F
; If LSB wrapped, increment high byte
0031 1D03 0105 btfss STATUS,Z
; Check high byte for wrap around
0032 2835 0106 goto done
; High byte didn't wrap
0033
0107 ovr_flo
0033 01A2 0108 clrf ACCbLO
0034 01A3 0109 clrf ACCbHI
0035
0110 done
0035 21FD 0111 call DEL_100
; Wait 100 msec before clearing HW.
0036 1009 0112 bcf
PORT_E,0
; Disable INIT
0037 1089 0113 bcf
PORT_E,1
; Disable BINH
0038 21FD 0114 call DEL_100
; Wait 100 msec before enabling HW.
0039 2812 0115 goto Xdcr
0116
0120
0149
0150 end
0151
MEMORY USAGE MAP ('X' = Used, '-' = Unused)
0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXX------
0040 : ---------------- ---------------- ---------------- ----------------
All other memory blocks unused.
Errors : 0
Warnings : 0
Messages : 0
© 1995 Microchip Technology Inc.
DS00597A-page 7