#Microcontrollers Sample Assembly Programs for 8051


// Assembly code for memory transfer

 

ORG 00H

 MOV R1,#05  ;Counter

 MOV R0,#40H  ;Source

 MOV DPTR,#6000H ;Destination


move:

 MOV A,@R0

 MOVX @DPTR,A ;A->ext destn

 INC R0   ;Source increment

 INC DPTR  ;destination increment

 DJNZ R1,move

here:

 sjmp here

 END 


//==========================


WAP to toggle the PORT1 LEDs

 

ORG 0000H
TOGLE: MOV P1, #01    //move 00000001 to the p1 register//
CALL DELAY    //execute the delay//
MOV A, P1        //move 
p1 value to the accumulator//
CPL A        //complement A value //
MOV P1, A        //move 11111110 to the port1 register//
CALL DELAY    //execute the delay//
SJMP TOGLE
DELAY: MOV R5, #10H    //load register R5 with 10//
TWO:        MOV R6, #200    //load register R6 with 200//
ONE:       MOV R7, #200    //load register R7 with 200//
DJNZ R7, $    //decrement R7 till it is zero//
DJNZ R6, ONE    //decrement R7 till it is zero//
DJNZ R5, TWO    //decrement R7 till it is zero//
RET            //go back to the main program //
END

// ===================================================

 

WAP to calculate the 500us time delay.

MOV TMOD, #10H        //select the timer mode by the registers//
MOV TH1, #0FEH        // store the delay time in higher bit//
MOV TL1, #32H        // store the delay time in low bit//
SETB TR1

JNB TF1, $            //decrement the value of the timer till it is zero//
CLR TF1            //clear the timer flag 
bit//
CLR TR1            //OFF the timer//

 // ===================================================

 

WAP to toggle the LEDs withthe 5 sec time delay

ORG 0000H
RETURN: MOV PO, #00H
ACALL DELAY
MOV P0, #0FFH
ACALL DELAY
SJUMP RETURN
DELAY:   MOV R5, #50H      //load register R5 with 50//
DELAY1: MOV R6, #200    //load register R6 with 200//
DELAY2: MOV R7, #229    //load register R7 with 200//
DJNZ R7, $    //decrement R7 till it is zero//
DJNZ R6, DELAY2//decrement R6 till it is zero//
DJNZ R5, DELAY1//decrement R5 till it is zero//
RET            //go back to the main program //
END

 // ===================================================

 

ORG 0000H
MOV TMOD, #50H        //select the counter//
MOV TH0, #15        //move the counting pulses higher bit//
MOV TH1, #9FH        //move the counting pulses, lower bit//
SET TR0            //ON the timer//
JNB  $            //decrement the count value till zero//
CLR TF0            //clear the counter, flag bit//
CLR TR0            //stop the timer//
END

 // ===================================================

 

WAP to transmit the characters to the Hyper Terminal

MOV SCON, #50H        //set the serial communication//
MOV TMOD, #20H        //select the timer mode//
MOV TH1, #-3        //set the baud rate//
SET TR1            //ON the timer//
MOV SBUF, #’S’        //transmit S to the serial window //
JNB TI, $            //decrement value of the timer till it is zero//
CLR TI            // clear transmit interrupt //
CLR TR1            //clear timer//

// =================================================== 

WAP to transmit the Receive the character by the Hyper Terminal

MOV SCON, #50H        //set the serial communication//
MOV TMOD, #20H        //select the timer mode//
MOV TH1, #-6        //set the baud rate//
SET TR1            //on the timer//
MOV SBUF, #’S’        //transmit S to the serial window //
JNB RI, $            //decrement value of timer till it is zero//
CLR RI            // clear receive interrupt //
MOV P0, SBUF         //send the SBUF register value to the port0//
CLR TR1            //clear timer//

 

Comments