Saturday, 8 October 2016

To perform MESSAGE PASSING in 8051 Programming

MOV TMOD,#20H
MOV TH1,#0faH
MOV SCON,#050H
SETB TR1
START: MOV A,#'M'
ACALL F1
MOV A,#'e'
ACALL F1
MOV A,#'s'
ACALL F1
MOV A,#'s'
ACALL F1
MOV A,#'a'
ACALL F1
MOV A,#'g'
ACALL F1
MOV A,#'e' 
ACALL F1
SJMP START

F1: MOV SBUF,A
HERE:JNB TI,HERE
CLR TI
RET

Check if 5AH is located is located in any one of the locations.If yes load acc. by 5AH.

START: MOV R0,#5FH
 MOV R7,#10H
 COMPIT: CJNE @R0,#5AH,NEXT
 MOV A,#5AH
 SJMP FOUND
NEXT: DEC R0
DJNZ R7,COMPIT
NOMATCH : MOV A,#00H
FOUND : SJMP FOUND

Copy a block of 20bytes of data from 60h to 73h to the location starting from 40h.

START: MOV R0,#60H
 MOV R1,#40H
 MOV R7,#14H
COPYIT: MOV A,@R0
 MOV @R1,A
 INC R0
 INC R1
 DJNZ R7,COPYIT
 OVER: SJMP OVER

Program to shift a block of 8 bytes data,from 50h to 57h,1 byte up data is available from 51H to 58H

START: MOV R0,#57H
 MOV R1,#58H
 MOV R7,#08H
 SHIFT: MOV A,@R0
 MOV @R1,A
 DEC R0
 DEC R1
 DJNZ R7,SHIFT
 OVER :SJMP OVER

Friday, 16 September 2016

Program to display the message in 8051

ORG 0000
MOV DPTR,#MY_DATA
MOV R0,#50H
MOV R2,#5H
REPEAT : CLR A
MOVC A,@A+DPTR
MOV @R0,A
INC DPTR
INC R0 
DJNZ R2,REPEAT
HERE :SJMP HERE
ORG 240H
 MY_DATA : DB " HELLO"
END

Program to perform factorial of a number (8051)

MOV DPTR,#1000H
MOVX A,@DPTR
MOV R1,A
MOV A,#01H
LOOP: MOV B,R1
MUL AB
INC DPTR
DJNZ R1,LOOP
END

Program to perform 16 bit BCD addition in 8051

MOV DPTR,#2080H
MOV A,#20H
MOV B ,#10H
ADDC A,DPL
DA A  
MOV A,B
DA A
ADDC A,DPH
MOV B,A
DA A
MOV A,DPL
END

Program to transfer n numbers from port 1 to port 2 in 8051

MOV A,#0FFH
MOV P0,A
MOV A,P0
MOV B,#10
DIV AB
MOV R7,B
MOV B,#10
DIV AB
MOV R6,B
MOV R5,A
END

Program for block transfer from one address to other (8051)

MOV R0,#30H
MOV R1,#50H
MOV R3,#8
RETURN : MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R3, RETURN
END

Program to find the sum of 10 numbers stored in the array (8051)

MOV R0,#50H
MOV R2,#6
CLR A
MOV R7,A
XYZ: ADD A,@R0
JNC NEXT
INC R7
NEXT: INC R0
DJNZ R2 , XYZ  
END

How to sort n numbers(Bubble sort ) in 8051

MOV R0,#09H
AGAIN:MOV DPTR,#1000H
MOV R1,#09H
BACK:MOV R2,DPL
MOVX A,@DPTR
MOV B,A
INC DPTR
MOVX A,@DPTR
CJNE A,B ,NEXT
AJMP SKIP
NEXT:JNC SKIP
MOV DPL,R2
MOVX @DPTR,A
INC DPTR
MOV A,B
MOVX @DPTR,A
SKIP:DJNZ R1,BACK
DJNZ R0,AGAIN
END

How to write a Program to perform Fibonacci series (8051)

ORG 0H
MOV R0,#30H
MOV @R0,#00H
MOV R1,#31H
MOV @R1,#01H
MOV R2,#09H
MOV A,#01H
BACK:ADD A,@R0
INC R0
INC R1
MOV @R1,A
DJNZ R2,BACK
HERE:SJMP HERE
MOV @R0,#00H
END 

Program to perform maximum of two numbers (8051)

MOV DPTR,#1000H 
MOV R1,#5H
MOV B ,#00H
AGAIN: MOVX A,@DPTR
CJNE A,B ,L1
SJMP L2
L1: JC L2
MOV B,A
INC DPTR
L2: DJNZ R1,AGAIN
END

How to write a Program to swap two variables in 8051 microcontroller.

MOV R0,#00H
MOV A,#01H
MOV B,#05H
MOV R0,B
MOV B,A
MOV A,R0
END 

How to Write a Program to perform 8-bit addition,subtraction,multiplication,division (8051)

MOV  R0,#02H 
MOV  R1,#03H
MOV  R2,#04H
MOV  R3,#05H
MOV  A,R0
ADD  A,R1
MOV  R0,A
MOV A,R2
SUBB  A,R1
MOV  R1,A
MOV  A,R1
MOV  B,R2
MUL  AB
MOV  R2,A
MOV  A,R3
MOV  B,R0
DIV  AB
MOV  R3,A
END