EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / plz help me to finished this simple project

plz help me to finished this simple project

|

Microcontroller › 8051 › Interfacing AT89S51 with ultrasonic sensor and LCD › plz help me to finished this simple project

May 16, 2015 at 9:07 am #12890
nitesh sinha
Participant

i am doing distance measurement using at89c51 and ultrasonic sensor but i m not getting anything on the seven-segment display ,i am using three seven-segment display ,the code is given below

ORG 00H
MOV DPTR,#SSDisplay // moves the address of LUT to DPTR
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,#210D // loads the initial value to start counting from
      MOV TH1,#210D // 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 DLOOP // calls the display loop
      SJMP MAIN // jumps to MAIN loop
 
DELAY1: MOV R6,#2D // 10uS delay
LOOP1: DJNZ R6,LOOP1
RET     
 
DLOOP: MOV R5,#50D // loads R5 with 100D
BACK1: MOV A,R4 // loads the value in R4 to A
       MOV B,#100D // loads B with 100D
       DIV AB   // isolates the first digit
       SETB P1.0 // activates LED display unit D1
       ACALL DISPLAY // calls DISPLAY subroutine
       MOV P0,A // moves digit drive pattern for 1st digit to P0
       ACALL DELAY   // 1mS delay
       ACALL DELAY
       MOV A,B // moves the remainder of 1st division to A
       MOV B,#10D // loads B with 10D
       DIV AB   // isolates the second digit
       CLR P1.0 // deactivates LED display unit D1
       SETB P1.1 // activates LED display unit D2
       ACALL DISPLAY
       MOV P0,A // moves digit drive pattern for 2nd digit to P0
       ACALL DELAY
       ACALL DELAY
       MOV A,B // moves the remainder of 2nd division to A
       CLR P1.1 // deactivates LED display unit D2
       SETB P1.2 // activates LED display unit D3
       ACALL DISPLAY
       MOV P0,A // moves the digit drive pattern for 3rd digit to P0
       ACALL DELAY
       ACALL DELAY
       CLR P1.2 // deactivates LED display unit D3
       DJNZ R5,BACK1 // repeats the display loop 100 times
       RET
 
DELAY: MOV R7,#250D   // 1mS delay
LABEL2: DJNZ R7,LABEL2
        RET
 
DISPLAY: MOVC A,@A+DPTR // gets the digit drive pattern for the content in A
         RET
 
SSDisplay: DB 0C0H // Hex code to display DISPLAY 0
DB 0F9H // DISPLAY 1
DB 0A2H // DISPLAY 2
DB 0B0H // DISPLAY 3
DB 99H // DISPLAY 4
DB 94H // DISPLAY 5
DB 84H // DISPLAY 6
DB 0F8H // DISPLAY 7
DB 80H // DISPLAY 8
DB 90H // DISPLAY 9
 
END
 
 

RSS Recent Posts

  • Raise your hand if your car had one of these: July 8, 2025
  • Tektronix 2235 channel 1 trace unstable July 8, 2025
  • How to make string LEDs? July 8, 2025
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz July 8, 2025
  • The Analog Gods Hate Me July 8, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise