[51] Ultra sonic distance measurement another code error in measurement (ANOTHER CODE)

Status
Not open for further replies.

kirtan.gopal

Newbie level 4
Joined
Mar 26, 2014
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
34
Code:
ORG 30H
RAM_ADDR        EQU 20H 
hundreds        equ 20h
tens            equ 21h
ones            equ 22h
MOV P1,#00000000B ; sets P1 as output port
MOV P0,#00000000B ; sets P0 as output port
CLR P3.0 ; sets P3.0 as output for sending trigger
SETB P3.1 ; sets P3.1 as input for receiving echo
MOV TMOD,#00100000B ; // sets timer1 as mode 2 auto reload timer
MAIN: 

MOV TL1,#247D  ;// loads the initial value to start counting from
MOV TH1,#247D  ;// loads the reload value
MOV A,#00000000B ;// clears accumulator
SETB P3.0 ;// starts the trigger pulse
ACALL DELAY1 ;// gives 10uS width for the trigger pulse
CLR P3.0 ;// ends the trigger pulse
HERE: JNB P3.1,HERE ;// loops here until echo is received
BACK: SETB TR1 ;// starts the timer1
HERE1: JNB TF1,HERE1 ;// loops here until timer overflows (ie;48 count)
CLR TR1 ;// stops the timer
CLR TF1 ;// clears timer flag 1
INC A ;// increments A for every timer1 overflow
JB P3.1,BACK ;// jumps to BACK if echo is still available
MOV R4,A ;// saves the value of A to R4
ACALL Bin2Dec ;// calls the display loop
ACALL   DATA1
ACALL ONETIME_LCDINIT
ACALL DEC_ASCI_CONVRT
ACALL   DELAY

SJMP MAIN ;// jumps to MAIN loop

Bin2Dec:
       MOV A,R4 
       mov b,#100d
       div ab
       mov hundreds,a
       mov a,b
       mov b,#10d
       div ab
       mov tens,a
       mov ones,b
       RET  
DEC_ASCI_CONVRT: 
        MOV R0,#20h       
        MOV R2,#03H      
BACKk:  MOV A,@R0       
        ORL A,#30H      
        ACALL   DATA_DISPLAY
        INC R0          
        DJNZ R2,BACKk 
      
      ACALL DELAY
      ACALL DELAY
        		
        RET
DATA1:
  ACALL ONETIME_LCDINIT
  MOV A,#'R'
  ACALL DATA_DISPLAY
  MOV A,#'E'
  ACALL DATA_DISPLAY
  MOV A,#'A'
  ACALL DATA_DISPLAY
  MOV A,#'D'
  ACALL DATA_DISPLAY
  MOV A,#'I'
  ACALL DATA_DISPLAY
  MOV A,#'N'
  ACALL DATA_DISPLAY
  MOV A,#'G'
  ACALL DATA_DISPLAY
  MOV A,#'.'
  ACALL DATA_DISPLAY
  MOV A,#'.'
  ACALL DATA_DISPLAY
  MOV A,#'.'
  ACALL DATA_DISPLAY
  ACALL   DELAY_200M
  ACALL   DELAY_200M
   RET
ONETIME_LCDINIT:
        MOV     A,#38H          
        ACALL   COMMAND         
        MOV     A,#0FH          
        ACALL   COMMAND         
        MOV     A,#01H          
        ACALL   COMMAND         
        MOV     A,#06H          
        ACALL   COMMAND         
        MOV     A,#82H          
        ACALL   COMMAND 
        MOV     A,#3CH 
        ACALL   COMMAND
        RET

COMMAND:
        ACALL   READY           
        MOV     P1,A            
        CLR     P2.0            
        CLR     P2.1            
        SETB    P2.2            
        CLR     P2.2            
        RET

DATA_DISPLAY:
        ACALL   READY           
        MOV     P1,A            
        SETB    P2.0            
        CLR     P2.1            
        SETB    P2.2            
        ACALL   DELAY           
        CLR     P2.2            
        RET
READY:  SETB    P1.7                    
        CLR     P2.0            
        SETB    P2.1            
BACK1:   CLR     P2.2                    
        ACALL   DELAY           
        SETB    P2.2            
        JB      P1.7,BACK1       
        RET
DELAY_200M:
DELAY:  MOV     R3,#50H
HERE3:  MOV     R4,#255 
HERE2:  DJNZ    R4,HERE2
        DJNZ    R3,HERE3
        RET

DELAY1: MOV R6,#2D ;// 10uS delay
LABEL1: DJNZ R6,LABEL1
RET
END
-------------------------------------------------------------------------
HERE THE CODE GIVE ERROR VALUE . INTE IMAGE I HAVE USE A OR GATE ONLY TO CHECK DISPLAY IS COMMING OR NOT OR NOTHING I HAVE REAL HCSR04 HARWARE WHICH I HAVE IMPLEMENTED THIS CODE
 

Attachments

  • Untitled page-page-001.jpg
    74 KB · Views: 51
Last edited by a moderator:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…