Microcontroller › 8051 › Assemby level code to C code conversion help
- This topic has 0 replies, 1 voice, and was last updated 10 years, 8 months ago by Nishanth.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
March 22, 2014 at 1:13 pm #2969NishanthParticipant
Someone please help me convert this assembly code to c code.
ORG 00H // origin
MOV DPTR,#LUT // moves the address of LUT to DPTRMOV P1,#00000000B // sets P1 as output portMOV P0,#00000000B // sets P0 as output portCLR P3.0 // sets P3.0 as output for sending triggerSETB P3.1 // sets P3.1 as input for receiving echoMOV TMOD,#00100000B // sets timer1 as mode 2 auto reload timerMAIN: MOV TL1,#207D // loads the initial value to start counting fromMOV TH1,#207D // loads the reload valueMOV A,#00000000B // clears accumulatorSETB P3.0 // starts the trigger pulseACALL DELAY1 // gives 10uS width for the trigger pulseCLR P3.0 // ends the trigger pulseHERE: JNB P3.1,HERE // loops here until echo is receivedBACK: SETB TR1 // starts the timer1HERE1: JNB TF1,HERE1 // loops here until timer overflows (ie;48 count)CLR TR1 // stops the timerCLR TF1 // clears timer flag 1INC A // increments A for every timer1 overflowJB P3.1,BACK // jumps to BACK if echo is still availableMOV R4,A // saves the value of A to R4ACALL DLOOP // calls the display loopSJMP MAIN // jumps to MAIN loopDELAY1: MOV R6,#2D // 10uS delayLABEL1: DJNZ R6,LABEL1RETDLOOP: MOV R5,#100D // loads R5 with 100DBACK1: MOV A,R4 // loads the value in R4 to AMOV B,#100D // loads B with 100DDIV AB // isolates the first digitSETB P1.0 // activates LED display unit D1ACALL DISPLAY // calls DISPLAY subroutineMOV P0,A // moves digit drive pattern for 1st digit to P0ACALL DELAY // 1mS delayACALL DELAYMOV A,B // moves the remainder of 1st division to AMOV B,#10D // loads B with 10DDIV AB // isolates the second digitCLR P1.0 // deactivates LED display unit D1SETB P1.1 // activates LED display unit D2ACALL DISPLAYMOV P0,A // moves digit drive pattern for 2nd digit to P0ACALL DELAYACALL DELAYMOV A,B // moves the remainder of 2nd division to ACLR P1.1 // deactivates LED display unit D2SETB P1.2 // activates LED display unit D3ACALL DISPLAYMOV P0,A // moves the digit drive pattern for 3rd digit to P0ACALL DELAYACALL DELAYCLR P1.2 // deactivates LED display unit D3DJNZ R5,BACK1 // repeats the display loop 100 timesRETDELAY: MOV R7,#250D // 1mS delayLABEL2: DJNZ R7,LABEL2RETDISPLAY: MOVC A,@A+DPTR // gets the digit drive pattern for the content in ACPL A // complements the digit drive pattern (see Note 1)RETLUT: DB 3FH // look up table (LUT) starts hereDB 06HDB 5BHDB 4FHDB 66HDB 6DHDB 7DHDB 07HDB 7FHDB 6FHEND -
AuthorPosts
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.