pic12C508超声波测距仪程序
扫描二维码
随时随地手机看文章
;超声波测距仪
;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