Assembly Coding of 8051
Assembly Coding of 8051
DISCUSSION:
In this lab we learn about the 8051 microcontroller which is a 40 pin IC and its internal
architecture. And how to do coding on KEIL software by interfacing it with the PROTEUS
software.
Ram/Rom:
• 8051 microcontroller has 4K Bytes internal ROM.
• 8051 microcontroller has 256 Bytes internal RAM.
I/O Ports:
8051 microcontroller has four I/O ports(P0-P3) and all of the four ports are of 8-bits which means
each port can handle the data of 8-bits. Port 1 is only for I/O purpose and the remaining ports have
multipurpose. All the ports have internal pull-up resistor except the port 0. In port 0 we don’t have
internal pull-up resistor and we have to connect it externally. And there are some others pins in
8051 microcontroller for different purposes.
Registers:
There are different types of Registers inside 8051 microcontroller like General purpose registers
which includes A,B,R0,R1,R2,R3,R4,R5,R6,R7 and there are some Special function registers
which are called SFRs. The General purpose registers and SFRs are of 8-bits. Some registers are
of 16-bits which include PC(program counter) and DPTR(data pointer).
Other Features:
• 6-interrupts sources.
• Two 16-bit timers
• 1-serial port
LAB TASKS
Task#01
Write a code to blink even and odd LEDs one after the other.
Program Code
org 00h
mov A,#10101010b // binary data to register A
mov B,#01010101b // binary data to register B
here: //label
mov p2,A //on even LEDs
call delay //calling delay
mov p2,B // on odd LEDs
call delay //calling delay
jmp here //repeating process
delay: //delay function
mov r6,#250
label2:
mov r7,#250
label1:
djnz r7,label1
djnz r6,label2
ret
end
Calculation:
Proteus circuit
Task#02
Write a code to blink 8 LEDs in sequence one after the other using setb and
clr instruction.
Program Code
org 00h
mov p2,#00h //making p2 an output port
here: //label
setb p2.0 // on LED
lcall delay //calling delay
clr p2.0 // off LED
lcall delay
setb p2.1
lcall delay
clr p2.1
lcall delay
setb p2.2
lcall delay
clr p2.2
lcall delay
setb p2.3
lcall delay
clr p2.3
lcall delay
setb p2.4
lcall delay
clr p2.4
lcall delay
setb p2.5
lcall delay
clr p2.5
lcall delay
setb p2.6
lcall delay
clr p2.6
lcall delay
setb p2.7
lcall delay
clr p2.7
lcall delay
jmp here //repeating process
delay: //delay function
mov r6,#230
label2:
mov r7,#250
label1:
djnz r7,label1
djnz r6,label2
ret
end
Proteus circuit
Task#03
Write a code to blink LED with 5 seconds delay. (Code shouldn’t exceed 50
lines)
T on =5 seconds
T off =5 seconds
Program Code
org 00h
mov p2,#00h //making p2 an output port
here: //label
mov A,#00000001b //moving binary data to register A
mov p2,A //turning on LED
call delay //calling delay
mov A,#00000000b //moving binary data to register A
mov p2,A //turning off LED
call delay
jmp here //repeat process
delay: //delay function
mov r6,#50
label2:
mov r7,#60
label1:
mov r5,#60
label3:
mov r4,#9
label4:
djnz r4,label4
djnz r5,label3
djnz r7,label1
djnz r6,label2
ret
end
Calculation:
Proteous circuit
Task#04
Generate the following sequences on LEDs
1. Blinking LEDs towards right
2. Blinking LEDs towards left
Program Code
org 00h
mov p2,#00h //making p2 an output port
here: //label
mov A,#10000000b //moving binary data to register A
mov r5,#8 //moving decimal data to register r5
label3:
mov p2,A //turning on LED
call delay //calling delay
RR A //rotate the bit towards right
djnz r5,label3 //repeating process up to 8 times
mov A,#10000000b
mov r4,#8
label4:
mov p2,A
call delay
RL A //rotate the bit towards left
djnz r4,label4
jmp here //repeating process
delay: //delay function
mov r6,#230
label2:
mov r7,#250
label1:
djnz r7,label1
djnz r6,label2
ret
end
Proteous circuit
Learning Outcomes
In this lab we found out about the 8051 microcontroller which is a 40 pin IC and its interior
engineering. We see the working of various pins of 8051 microcontroller. We found out about how
to utilize the ports and the pins of microcontroller as a yield and how to send information to them.
We additionally figured out how to utilize KEIL programming and how to do coding in it and
afterward how to interface it with the PROTEUS in the wake of making the .hex record of our
venture. We additionally figured out how to compute the delay time by doing counts.