You are on page 1of 11

Experiment 1: Program to add to values using register address

mode and 1 value using immediate mode store final result in


accumulator.
Solution:
ORG 0H
MOV R5, #25H
MOV R7, #34H
MOV A, #0
ADD A, R5
ADD A, R7
ADD A, #12H
HERE: SJMP HERE
END

Experiment 2: Write a program to push 3 values in stack using


PUSH instruction and pop 3 values accordingly using POP
instruction.
Hint: use 6h,1h,4h for PUSH and 3h,5h,2h for POP.
ORG 0000H
MOV R6, #25H
MOV R1, #12H
MOV R4, #0F3H
PUSH 6
PUSH 1
PUSH 4
END
ORG 0000H
MOV R6, #25H
MOV R1, #12H
MOV R4, #0F3H
PUSH 6
PUSH 1

PUSH 4
POP 3
POP 5
POP 2
END

Experiment 3: Write a program to Add decimal number 03d, 10


time using DJNZ loop and store the result in R5.
ORG 0000H
MOV A,#0
MOV R2,#10
AGAIN: ADD A,#03
DJNZ R2,AGAIN
MOV R5,A
END

Experiment 4: Write a program to toggle pins of port 1 of 8051


700 times without any delay.
ORG 0000H
MOV A,#55H
MOV R3,#10
NEXT: MOV R2,#70
AGAIN: CPL A
MOV P1,A
DJNZ R2,AGAIN
DJNZ R3,NEXT
END

Experiment 5: Write a program to add 3 hexadecimal numbers


listed below keep track of carry in R5 and store result in R0
79H, 0F5H , E2H
ORG 0000H
MOV A,#0
MOV R5,A
ADD A,#79H
N_1: ADD A,#0F5H
JNC N_2
INC R5
N_2: ADD A,#0E2H
JNC OVER
INC R5
OVER: MOV R0,A
END

Experiment 6: Memory location 40 41 42 43 44 containing values


given as 7DH 0EBH 0C5H 5BH 30H 40H Add these values using
register indirect addressing mode store result in accumulator.
ORG 0000H
mov 40H,#7DH
mov 41H,#0EBH
mov 42H,#0C5H
mov 43H,#5BH
mov 44H,#30H
MOV R0,#40H
MOV R5,#5
mov R7,#0
CLR A
AGAIN:ADD A,@R0
JNC NEXT

INC R7
NEXT:INC R0
DJNZ R5,AGAIN
END

Experiment 7: Write a program to transfer message YES


serially at baud rate of 9600, 8 bit data and 1 stop bit Do this
continuously.
org 0000h
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON,#50H
SETB TR1
AGAIN: MOV A,#'Y'
ACALL TRANS
MOV A,#'E'
ACALL TRANS
MOV A,#'S'
ACALL TRANS
SJMP AGAIN
TRANS: MOV SBUF,A
CLR TI
RET
End

Experiment 8: Write an 8051 program to (a) send to PC the message

We Are Ready, (b) receive any data send by PC and put it on LEDs
connected to P1, and (c) get data on switches connected to P2 and send it
to PC serially. The program should perform part (a) once, but parts (b) and
(c) continuously, use 4800 baud rate.

org 0000h
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON,#50H
SETB TR1
AGAIN: MOV A,#'Y'
ACALL TRANS
MOV A,#'E'
ACALL TRANS
MOV A,#'S'
ACALL TRANS
SJMP AGAIN
TRANS: MOV SBUF,A
CLR TI
RET
End

Experiment 9: Write a program in assembly language to convert


a series of packed BCD numbers to equivalent ASCII code
Org 300h
MYDATA: DB 76h,87h,98h,43h
Place ASCII numbers in RAM location 40 onwards.
org 0h
mov a,#0
mov dptr,#mydata

mov r0,#40H
mov r5,#4H
again:clr a
movc a,@a+dptr
mov r6,a
swap a
anl a,#0fh
add a,#30h
mov @r0,a
inc r0
mov a,r6
anl a,#0fH
add a,#30H
mov @r0,a
inc r0
inc dptr
djnz r5,again
org 300H
mydata: db 76H,87H,98H,43H
end

Experiment 10: Write a program in assembly language to


convert a series of ASCII characters to packed BCD numbers.
Org 300h
MYDATA: DB 87675649
Place BCD data at RAM locations 60H
org 0h
mov a,#0
mov dptr,#mydata
mov r0,#60H
mov r5,#4H
again:clr a
movc a,@a+dptr
anl a,#0fh
swap a
mov r7,a
inc dptr
clr a
movc a,@a+dptr
anl a,#0fh
orl a,r7
mov @r0,a
inc r0
inc dptr
djnz r5,again
org 300H

mydata: db "87675649"
end
Experiment 11: Write an 8051 C program to toggle all the bits of P1

continuously.
#include<reg51.h>
void main(void)
{
for(;;)
{
P1=0x55;
P1=0xAA;
}
}

Experiment 12: Write an 8051 C program to send values of 4 to +4 to

port P1.
#include<reg51.h>
void main(void)
{
char mynum[] = {1,-1,2,-2,3,-3,4,-4};
unsigned char z;
for(z=0;z<=8;z++)
P1=mynum[z];
}

Experiment 13: Write an 8051 C program to toggle bit D0 of the port

P1 (P1.0) 50,000 times.

#include<reg51.h>
sbit mybit=P1^0;
void main(void)
{

unsigned int z;
for(z=0;z<=50000;z++)
{
mybit=0;
mybit=1;
}
}

Experiment 14: Assume that 5 BCD data items are stored in RAM

locations starting at 40H, as shown below. Write a program to find the sum
of all the numbers. The result must be in BCD.
40=(71) 41=(11) 42=(65) 43=(59) 44=(37)
Write program in c.
#include<reg51.h>
void main(void)
{
unsigned char myarray []={71,11,65,59,37};
unsigned z=0;
unsigned s;
for(z=0;z<5;z++)
{
s=s+myarray[z];
}
P1=s;
}

Experiment 15: write a program in c to add a value 700 in


variable a using for loop.
Hint: Use a as unsigned character
#include<reg51.h>
void main(void)
{
unsigned char x,y;
unsigned char a=5;
for(x=0;x<=70;x++)
for(y=0;y<=10;y++)
{
a=-a+1;
P1=a;
}
}

Experiment 16: Write a program in c to monitor a value


continuously stored as unsigned character send it to P1 if number
is even otherwise send it to P2.
#include<reg51.h>
void main(void)
{
unsigned char x=0,y=0;
unsigned char a=5;
for(;;)
{
x=a+y;
if(x%2==0)
P1=x;
else

P2=x;
y++;
}
}

You might also like