Help Assembly code PIC16F877A ultrasonic project

Status
Not open for further replies.

jian999

Newbie level 3
Joined
Apr 11, 2014
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
45
Read distance in the 16x2 LCD using hc-sr04 ultrasonic and pic16f877a........I found lots of information but not used because all are in c language..................pls someone can give me assembly code for this project (I stuck in calculation and display )
 

How abut showing what you have done so far as a start?

John
 

HTML:
LIST P=16F877A
#INCLUDE <P16F877A.INC>
__CONFIG   0X3F32

;===========================================================================================
; MACRO
;===========================================================================================
BANK0        MACRO                    ;CHANGE TO BANK 0
            BCF        STATUS,RP0                    
            BCF        STATUS,RP1
            ENDM
            
BANK1        MACRO                    ;CHANGE TO BANK 1
            BSF        STATUS,RP0
            BCF        STATUS,RP1
            ENDM

CLOCK_E        MACRO                    ;'E' RISE UP N FALL DOWN
            BSF        PORTB,7
            CALL    DELAY1
            BCF        PORTB,7
            CALL    DELAY1
            ENDM            
;=========================================================================================
; RESET VECTOR
;=========================================================================================
            ORG        00h

RESET        GOTO    INIT


;=========================================================================================
;INTERRUPT VECTOR 
;=========================================================================================
            ORG        04h
            RETFIE

;=========================================================================================
; INITIALIAZATION OF I/O
;=========================================================================================
            ORG        05h
                        
INIT    BANK1
        CLRF    TRISC
        MOVLW    B'00001110'
        MOVWF    TRISB
        MOVLW    B'00000001'
        MOVWF    TRISD
        
        BANK0
        CLRF    PORTC
        CLRF    PORTD
        CLRF    PORTB

;=======================================================================================        
;DELAY SUBROUTINE 
;=======================================================================================

DELAY1        MOVLW    FFh
            MOVWF    20h
            MOVLW    FFh
            MOVWF    21h
DELAYLOOP    DECFSZ    20h
            GOTO    DELAYLOOP
            DECFSZ    21h
            GOTO    DELAYLOOP
            RETURN    

;============================================================================================== 
;MAIN PROGRAM START HERE
;==============================================================================================

;LCD INITIALIZED
            
            CALL    DELAY1
            CALL    DELAY1

            BCF        PORTB,6                ; R/S SET TO '0'as a command        
            MOVLW    B'00110000'            
            MOVWF    PORTC                ; FUNCTION SET: 8 BIT INTERFACE
            CLOCK_E                        ; E CLOCK MACRO
            MOVLW    B'00001101'            
            MOVWF    PORTC                ; DISPALY & CURSOR: SET TO DISPLAY ON; CURSOR UNDERLINE OFF; CURSOR BLINK ON
            CLOCK_E                        ; E CLOCK MACRO
            MOVLW    B'00111000'        
            MOVWF    PORTC                ; FUNCTION SET: 8 BIT; 2 LINE MODE; 5X7 DOT FORMAT
            CLOCK_E                        ; E CLOCK MACRO
            MOVLW    B'00000001'            
            MOVWF    PORTC                ; CLEAR DISPLAY
            CLOCK_E                        ; E CLOCK MACRO                                    
            MOVLW    B'00000110'
            MOVWF    PORTC                ; CHARACTER ENTRY MODE: INCREMENT; DISPLAY SHIFT ON
            CLOCK_E                        ; E CLOCK MACRO

;WRITE YOUR CHARACTER HERE

            BSF        PORTB,6        ;R/S SET TO '1' to write character
            MOVLW    B'01010110'        ;'V'in ASCII mode
            MOVWF    PORTC            ;Display 'V'
            CLOCK_E                    
            MOVLW    B'01001111'        ;'O' in ASCII mode
            MOVWF    PORTC            ;Display 'O'
            CLOCK_E                    
            MOVLW    B'01001100'        ;'L' in ASCII mode
            MOVWF    PORTC            ;Diplay 'L'
            CLOCK_E                    
            MOVLW    B'01010101'        ;'U' in ASCII mode
            MOVWF    PORTC            ;Display 'U'
            CLOCK_E
            MOVLW    B'01001101'        ;'M' in ASCII mode
            MOVWF    PORTC            ;Display 'M'
            CLOCK_E
            MOVLW    B'01000101'        ;'E' in ASCII mode
            MOVWF    PORTC            ;Display 'E'
            CLOCK_E
            MOVLW    B'00111010'        ;':' in ASCII mode
            MOVWF    PORTC            ;Display ':'
            CLOCK_E    
            MOVLW    ' '                ;' ' in ASCII mode
            MOVWF    PORTC            ;Display ' '
            CLOCK_E

I dun know how to declare and activate ultrasonic sensor part using Timer1,CCP1,the division formula, and to display the answer in lcd


- - - Updated - - -

I found an example from internet,but I dun understand the coding.......hope this useful, thx for help
 

Attachments

  • try.txt
    6.7 KB · Views: 108

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…