9:39 AM
8051 Assembly language programming using Keil compiler

Aim: 8051 Assembly language programming using Keil compiler.
a. Find the sum of the values 79H, F5H, E2H. Put the sum in register R0 (low byte) and R5 (high byte).
b. Write a program to copy the values 55H into RAM memory locations 40H to 45H using
i) Direct addressing mode
ii) Register indirect addressing mode without using loop
iii) With a loop
c. Write a program to toggle all the bits of P1 after some delay
d. Write a program to generate square wave of 50% duty cycle on bit 0 of port 1
e. Write a program to
i) Make P1 as input port.
ii) To get hex data from P1 and convert it into decimal and save the digits in R7, R6, R5.
f. Write a program to add two 16 – bit numbers 3CE7H and 3B8DH. Place the sum in R7 and R6 (Lower Byte).
g. A switch is connected to P1.7. Write a program to check the status of SW and perform the following:
i) If SW=0, send letter „N. to P2.
ii) If SW=1, send letter „Y. to P2.
h. Write a program for Hex to ASCII conversion
i. Write a program to generate square wave using timer
Requirements: Keil software
Learning Objectives: Use of Keil software to perform basic assembly programs
Outline of the Procedure:
1. Open Keil software on your laptop.
2. Write the given code.
3. Save the file.
4. Assemble the code and check error, if error remove it and again assemble it.
5. Execute the code and verify the results.


Program (a):
Org 0000h
mov a,#79h
mov r5,#00h
add a,#0f5h
jnc here
inc r5
here: add a,#0e2h
jnc go
inc r5
go: mov r0,a
end


Program (b):
i) Direct addressing mode
MOV A,#55
MOV 40H,A
MOV 41H,A
MOV 42H,A
MOV 43H,A
MOV 44H,A
MOV 45H,A
ii) Register indirect addressing mode without using loop
MOV R0,#40H
MOV A,#55H
MOV @R0,A //copy a to ram location r0 points to
INC R0
MOV @R0,A
INC R0
MOV @R0,A
INC R0
MOV @R0,A
INC R0
MOV @R0,A
INC R0
END


iii) With a loop.
MOV R0,#40H
MOV A,#55H
GO:MOV @R0,A
INC R0
CJNE R0,#46H, GO
END
Program (c):
org 0000h
again:
mov p1,#55h
acall delay
mov p1,#0aah
acall delay
sjmp again
delay:mov r0,#04h
go3:mov r1,#0ffh
go2:mov r2,#0ffh
go1:djnz r2,go1
djnz r1,go2
djnz r0,go3
ret
end


Program (d):


org 0000h
again:cpl p1.0
sjmp again
end
Program (e):
Org 0000h
mov a,#0ffh
mov p1,a
mov a,p1
mov b,#10
div ab
mov r7,b
mov b,#10
div ab
mov r6,b
mov r5,a
end


Program (f):


org 0000h
mov r5,#00h
mov a,#0e7h
add a,#8dh
mov r6,a
mov a,#3ch
addc a,#3bh
jnc go
inc r5
go: mov r7,a
end


Program (g):


org 0000h
setb p1.7
again:mov c,p1.7
jnc go
mov p2,#'Y'
go:mov p2,#'N'
sjmp again
end


Program (h):
org 0000h
mov a,#2dh
mov r1,a
anl a,#0fh
acall char
mov r2,a
mov a,r1
swap a
anl a,#0fh //mov the lower nibble to r2
acall char
mov r3,a
here:sjmp here
char:
cjne a,#0ah,out1
mov a,#41h //to get 41
sjmp go
out1:cjne a,#0bh,out2
mov a,#42h //to get 42
sjmp go
out2:cjne a,#0ch,out3
mov a,#43h //to get 43
sjmp go
sjmp code1
code1:
out3:cjne a,#0dh,out4
mov a,#44h //to get 44
sjmp go
out4:cjne a,#0eh,out5
mov a,#45h //to get 45
sjmp go
out5:cjne a,#0fh,out
mov a,#46h //to get 46
sjmp go
out:
orl a,#30h
go:
ret
end


Program (i):
org 0000h
again:mov tmod,#01h
mov th0,#01h
mov tl0,#00h
cpl p1.1
setb tr0
here: jnb tf0,here
clr tr0
clr tf0
sjmp again
end
Learning outcomes: to be written by the students in 50-70 words.

 

Views: 102 | Added by: vijoriya | Tags: Compiler, 8051, Keil, programming, Assembly language | Rating: 0.0/0
Total comments: 0
avatar