;超聲波測距儀
;InternalOsc,WDTEnabLED
include
loopequ10h
dlyCTRequ11h
tone_cntequ12h;反射周期計數(shù)
periodequ13h;tmr0溢出時間
org0
MOVwfOSCCAL
MOVlwb’10001001’
option;1:2WDTON
MOVlwb’00001101’
trisGPIO
MOVwf0
bcfGPIO,1;輸出脈沖
;===================================
mainclrwdt
btfssGPIO,0;等待觸發(fā)信號
gotomain
m2clrwdt
btfscGPIO,0
gotom2
callburst;發(fā)送超聲波
bsfGPIO,1;開始輸出定時脈沖
m1btfscGPIO,2
gotom1
bcfGPIO,1;結(jié)束輸出定時脈沖
gotomain
;===================================
burstclrfloop
MOVlw8
MOVwfloop
burst1MOVlwb’00010000’
MOVwfGPIO
MOVlw3
MOVwfdlyctr
burst2decfszdlyctr,f
gotoburst2;12uS
MOVlwb’00010100’
MOVwfGPIO
MOVlw2;(2*3inst*1uS)-1uS=5uS
MOVwfdlyctr;5uS+(8*1uS)=13uS
burst3decfszdlyctr,f
gotoburst3
nop
decfszloop,f
gotoburst1
MOVlw0x00
MOVwfGPIO
retlw0
;================================
toneclrfTMR0
t1btfscGPIO,2
gotot1
MOVfwTMR0
clrfTMR0
MOVwfperiod
MOVlw21;if(period>22&&period<30)
subwfperiod,w
btfssSTATUS,C
gotot2
MOVlw30
subwfperiod,f
btfscSTATUS,C
gotot2
decfsztone_cnt,f;25uSperiodOK,so
gotot1;ifnotyet3ofthem,keeplooking
retlw0;else-success-return
t2MOVlw3
MOVwftone_cnt
gotot1
;=====================================
end