当前位置:首页 > 单片机 > 单片机
[导读] ;超声波测距仪;InternalOsc,WDTEnabLEDincludeloopequ10h dlyCTRequ11htone_cntequ12h;反射周期计数periodequ13h;tmr0溢出时间org0MOVwfOSCCALMOVlwb’10001001’option;1:2WDTONMOVlwb’00001101’tr

;超声波测距仪
;InternalOsc,WDTEnabLED

include

loopequ10h

dlyCTRequ11h
tone_cntequ12h;反射周期计数
periodequ13h;tmr0溢出时间


org0
MOVwfOSCCAL
MOVlwb’10001001’
option;1:2WDTON
MOVlwb’00001101’
trisGPIO
MOVwf0
bcfGPIO,1;输出脉冲

;===================================
mainclrwdt
btfssGPIO,0;等待触发信号
gotomain
m2clrwdt
btfscGPIO,0
gotom2

callburst;发送超声波
bsfGPIO,1;开始输出定时脉冲
m1btfscGPIO,2
gotom1
bcfGPIO,1;结束输出定时脉冲
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


本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭