ultrasonic sensor interfecaing pic16f877a asm code

Submitted by moz on

hello

well i'm a beginner in asm coding ..and i have this project to set a code for ultrasonic sensor with pic16f877a using assembly langauge ( which i don't know very well)  to display a distance in 7seg_ .. ..i started with this little code but can't understand how to go further plz help me 

                                                               

TRIG   equ  0x0c
count  equ  0x0c
count1 equ  0x0c
count2 equ  0x0c
;*****************************************
ORG 0x00
GOTO START ; reset vector
ORG 0x04
GOTO INTERRUPT ; interruption vector
 
;;*************INITIALISATION*********
 
 
START clrf    PIE1
bsf status,5
bcf status,6  ; bank1
movlw 0x07
movwf adcon1
CLRF TRISD
CLRF TRISC
clrf TRISB
bcf TRISA,0
bsf TRISA,1     ; RA0 is TRIG  RA1 is ECHO
bsf option_reg,6
bsf PIE1,TMR1IE
 
bcf status,5
movlw   0x29
        movwf   T1CON    ;Prescaller 1:4
        bsF     INTCON,PEIE
bcf INTCON,GIE
clrf    TMR1L
CLRF TMR1H
goto ULTRA
 
 
;**************************************
 
ULTRA bsf PORTA,0
movlw 0x02
movwf TRIG
TRIGG decfsz TRIG,1   ; 10us
GOTO TRIGG
nop
bcf PORTB,2
ECHO
HIGH btfss   PORTA,1  ; test if echo high
goto    HIGH
bsf     INTCON,7
 
LOW         btfsc PORTA,1  ; test echo if low
goto LOW
bcf INTCON,GIE
CLRF COUNT
CLRF COUNT1
CLRF COUNT2
goto    ULTRA

  

Have any questions?
m

marcelo

  Joined June 09, 2023      1

Friday at 08:07 AM

Hi, did you manage to finish it?

D

Daniel Ruth

  Joined February 01, 2024      1

Thursday at 05:19 PM

TRIG   equ  0x0c
count  equ  0x0c
count1 equ  0x0c
count2 equ  0x0c

It seems like these equates are unused in your code. You can safely remove them.
 

It is crucial to have a clear understanding of how the ultrasonic sensor works and how to use it to measure distance based on the time taken for the ultrasonic pulse to return. To achieve this, you may need to create a logic that calculates the distance by taking into account the time difference between triggering the pulse and receiving the echo. 

Moreover, it is important to handle the Timer1 interrupt (INTERRUPT label) in order to measure the time accurately.

Here are some suggestions to help you advance your project: 

1. Implement the Timer1 interrupt service routine to measure the time accurately between triggering the pulse and receiving the echo.
2. Calculate the distance based on the measured time.
3. Update your code to display the calculated distance on the 7-segment display.

Make sure to refer to the PIC16F877A datasheet for understanding the configurations and functions of the registers.

Add a comment

No account needed. Your comment appears once a moderator has reviewed it.

Never shown publicly.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.