使用PIC16F877A的超声波测量距离 [英] Ultrasonic measure distance using PIC16F877A

查看:117
本文介绍了使用PIC16F877A的超声波测量距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好;

我完成了超声波测距的完整电路..

然后我开始编写PWM代码,并从RC2产生10个脉冲,这就是正常工作,
但是
1.我想生成另一个高电平信号,它在脉冲开始和停止的同时启动,用于检测到的信号吗?..
2.当我写代码来启动计数器吗?
你能帮助我吗???

Hi everybody;

I was finish build the complete circuit for Ultrasonic measure distance..

and I start to write the PWM code and generate 10 pulse from RC2 thats is working,
but
1.I want to generate another High signal it will be start when pulse start and stop at same time this one for detected signal?..
2. when I write the code to start counter?
can you help me???

LIST P=16F877A
#INCLUDE P16F877A.INC
cblock 0x20 ;start of general purpose registers
PULSE_COUNT 
count ;used in delay routine
count1 ;used in delay routine
temp ;temp storage
TIMEL
TIMEH
LOW_COUNT
HIGH_COUNT
LOOP_COUNT
endc
ORG 0x0000
GOTO START
ORG 0x0010
INIT_RC
CLRF PORTC
BSF STATUS,RP0
MOVLW B''00000001''
MOVWF TRISC
BCF STATUS,RP0
RETURN 
SEND
MOVLW D''10''
MOVWF PULSE_COUNT
CALL PWM
RETURN
START 
CALL INIT_RC
CALL INIT_PWM
CALL SEND

INIT_PWM
CLRF TIMEL
CLRF TIMEH
CLRF CCP1CON
CLRF TMR2
MOVLW D''12''
MOVWF CCPR1L
CLRF INTCON
BSF STATUS,RP0
MOVLW D''24''
MOVWF PR2
BCF TRISC,2
BCF STATUS,RP0
CLRF PIR1
MOVLW 0X0C
MOVWF CCP1CON
BSF T2CON,TMR2ON
BCF PORTC,1 
RETURN
PWM
BTFSS PIR1,TMR2IF
GOTO PWM
BTFSC PORTC,2
BSF PORTC,1
BCF PIR1,TMR2IF
DECFSZ PULSE_COUNT
GOTO PWM
BCF PORTC,1
CLRF CCPR1L
CALL Delay500
MOVLW D''10''
MOVWF PULSE_COUNT
RETURN

Delay500
movlw d''3'' ;delay for500us
movwf count1
Delay1 call Delay250
decfsz count1
goto Delay1
return
Delay250 
movlw d''125'' ;delay for250us
movwf count
goto Delay
Delay ;delay for2us
nop
nop
decfsz count, f
goto Delay
return

END

推荐答案

您好,

如果您在任何与PIC相关的论坛(如
)中尝试查询,则可能会得到更快的答复.
Microchip论坛 [论坛2 [ ^ ]


论坛3 [
Hello,

You might get a more quicker reply if you try your queries in any of the PIC related forums like

Microchip Forum [^]

Forum 2[^]


Forum 3[^]


About your Question :

1. Are you talking about Generating a Square wave that has the time period of the PWM wave front ?

2. What counter are you talking about ?

BR//
Harsha


是的,我生成了250us的40KHz方波..

我是指数时间来测量距离.

你能帮我吗?????
yes I Generating a Square wave 40KHz for 250us..

I mean count time for measure the distance..

can you help me?????


这篇关于使用PIC16F877A的超声波测量距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆