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 / Topics / Assemby level code to C code conversion help

Assemby level code to C code conversion help

|

Microcontroller › 8051 › Assemby level code to C code conversion help

  • This topic has 6 replies, 3 voices, and was last updated 11 years, 2 months ago by Ashutosh Bhatt.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • March 22, 2014 at 1:14 pm #2970
    Nishanth
    Participant

    Someone please help me convert this to c code.

    ORG 00H // origin

    MOV DPTR,#LUT // 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,#207D // loads the initial value to start counting from

    MOV TH1,#207D // 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

    LABEL1: DJNZ R6,LABEL1

    RET

    DLOOP: MOV R5,#100D // 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

    CPL A // complements the digit drive pattern (see Note 1)

    RET

    LUT: DB 3FH // look up table (LUT) starts here

    DB 06H

    DB 5BH

    DB 4FH

    DB 66H

    DB 6DH

    DB 7DH

    DB 07H

    DB 7FH

    DB 6FH

    END

    March 23, 2014 at 5:20 pm #11357
    Ashutosh Bhatt
    Participant

    why do u want to convert it in to C?

    what do u want to do?

    March 28, 2014 at 4:02 am #11408
    SHAH DISHANT H.
    Participant

    What this code is doing ? If you can tell purpose of code then its easy to do it instead of going into depth of code..

    April 3, 2014 at 3:43 pm #11456
    Nishanth
    Participant

    I want the C code for distance claculation using HC SR04 Sensor.Above is aseembly level code for the same

    April 3, 2014 at 4:48 pm #11457
    Ashutosh Bhatt
    Participant

    my question is still same?

    why u want to convert it into C?

     

    u have already written code in assembly. now just test it, debug it, run it

    why to switch over C language?

    April 5, 2014 at 2:45 pm #11473
    Nishanth
    Participant

    We were asked to do mini project using 8051, I learnt the aseembly code and wrote a program,but they want C Code in our project report so.Pls help

    April 15, 2014 at 3:55 pm #11558
    Ashutosh Bhatt
    Participant

    in that case you have to learn  embedded C programming for 8051.

    it is easy. you can learn for the tutorials given on this site also.

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Curved lines in PCB design June 15, 2025
  • using a RTC in SF basic June 15, 2025
  • Parts required for a personal project June 15, 2025
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz June 15, 2025
  • PIC KIT 3 not able to program dsPIC June 15, 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