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