Microcontroler Labmanual
Microcontroler Labmanual
Microcontroler Labmanual
LAB MANUAL
Microcontroller &
Embedded
(2019‐2020)
Authorized by
HOD
CHOUKSEY ENGG. COLLEGE, BILASPUR (C.G.)
10
11
STUDY OF 8051
A brief history of the 8051:
In 1981, Intel Corporation introduced an 8-bit micro – controller called the
8051. This micro controller had 128bytes of RAM, 4k bytes of on-clip ROM, tow
timers, one serial port and four ports all on a single chip. At that time it was also
referred to as a system on a chip. The 8051 is an 8-bit processor, meaning that the
CPU can work on only 8-bit of date at a time. Data larger than 8-bit has to be taken
into 8-bit pieces to be processed by the CPU. The 8051 has a total of four I/O
ports, each 8-bit wide.
FEATURES QUANTITY
ROM 4k bytes
RAM 128 bytes
TIMER 2
I/O Pins 32
SERIAL 1
PORT
Interrupt 6
service
8- bit with data type, any data layer larger then 8-bits must be broken into 8-bit
frame before it is processed on address [pointing to the data to be fetched.
The most widely used registers at the 8051 are A, B, R0, R1, R2, R3, R4, R5, R6,R7,
R8, DPTR (data pointer) and PC (Program Counter). All of the above system
registers and 8-digit except DPTR and the program counter. The accumulator A, is
used for an arithmetic and logic instructions. To, understand the use of these
registers, we will use them in various simple instructions.
Examination figure, we note that of the 40pins, a total of 32 pins are set aside for
the four ports. P0, P1, P2 and P3 where each port takes 8 pins. The rest of the pins
are designated as CLC, GND, XTAL1, XTAL2, RST, EA, P SEN , of these 8 pins.
Six of them are used by all members of the 8051 and 8031 Family.
The 16-bit register of timer 0 is accused as low byte and high byte.
The low byte register called TL0 and the high byte register is as TH0
b. Timer 1 registers:
Timer 1 is also 16 bits and its 16bit register in split into 2 bytes
referred to as TL1 and TH1, these register are accessible in the same way as the
register of timer 0.
ARITHMETIC OPERATION
AIM:
ALGORITHM:
PC = A= B=
R0= R1= R2= R7=
2. For Question 1, indicate the largest value (in decimal) that each register can
contain.
PC = A= B=
R0= R1= R2= R7=
Program
1. For Question 1, indicate the largest value (in hex) that each register can
contain.
PC = A= B=
R0= R1= R2= R7=
2. Who generates each of the following files and what is the use of each.
.asm
.lst
.obj
.abs
.hex
Result:
Thus the above programs are executed and run with the help of
89C51microcontroller.
LOGICAL OPERATION
AIM:
To write the logical operation like ANL, ORI and XRL for the input using
89c51 controller.
ALGORITHM:
MOV A,#45H
RR A
RR A
RR A
A= in hex
MOV A,#45H
RL A
RL A
RL A
A= in hex
3. In the absence of the "SWAP A" instruction, how would you perform the
operation?
PROGRAM:
CLR A
XRL A, #0FFH
A= in hex
CLR A
CPL A
XRL A, #0FFH
Result:
Thus the above programs are executed and run with the help of
89C51microcontroller.
SQUARE WAVE
AIM:
ALGORITHM:
• Start the window.
• Load TMOD
• Load FF2H into THO and TLO
• Delay sub route using timer is called.
• In the ‘DELAY’ sub-routes, time 0 is started by the SETB TRO,
instructions.
• Timer 0 is stopped by the instruction ‘CLR TRO’, the delay sub routine ends
and the process is repeated.
Pre Lab Questions:
1. What is the maximum frequency that can be generated using Mode 1 if the
crystal frequency is 11.0592 MHz? Show your calculation.
2. What is the maximum frequency that can be generated using Mode 2 if the
crystal frequency is 11.0592 MHz? Show your calculation.
3. What is the lowest frequency that can be generated using Mode 1 if the
crystal frequency is 11.0592 MHz? Show your calculation.
Program
l1:
cpl p1.0
acall delay
sjmp l1
delay:
mov r1,#0ffh
l3:
mov r0,#0xff
l2:
djnz r0,l2
djnz r1,l3
ret
end
Post Lab Questions:
1. What is the lowest frequency that can be generated using Mode 1 if the
crystal frequency is 11.0592 MHz? Show your calculation.
2. In mode 1, when is TFx set to high? In mode 2, when is TFx set to high?
Result:
This program is executed without any error.
SQUARE WAVE
AIM:
ALGORITHM:
• Start the window.
• Load TMOD
• Load FF2H into THO and TLO
• Delay sub route without timer is called.
• In the ‘DELAY’ sub-routes, time 0 is started by the SETB TRO,
instructions.
• Timer 0 is stopped by the instruction ‘CLR TRO’, the delay sub routine ends
and the process is repeated.
PRE – LAB :
L1 : MOV R1,@0FFH;
CPL P1.5;
ACALL DELAY;
SJMP L1;
DELAY :
MOV R3,#03H;
AGAIN:
DJNZ R3,AGAIN;
DJNZ R1,AGAIN;
RET;
Result:
This program is executed without any error.
ALGORITHM:
• Start the window.
• Open a new project.
• Create the program for ascending or descending order.
• Compare the different not using ‘SUBB’ Command
• Delay an run the program.
• End
Pre Lab Questions:
MOV R0,#09H
MOV R1,#07H;
MOV R2,#01H;
MOV A,R0;
SUBB A,R1;
JNC L1;
JC L2;
L1 :
MOV A,1;
MOV B,0;
MOV 1,B;
MOV 0,A;
SJMP L3;
L2 : SJMP L3;
L3: MOV A, R1;
SUBB A,R2;
JNC L4;
JC L5;
L4: MOV A,1;
MOV B,2;
MOV 1,B;
MOV 2,A;
SJMP L6;
L5: SJMP L6;
L6: MOV A,1;
SUBB A,0;
JNC L7;
JC L8;
L7: RET;
L8: MOV A,1;
MOV B,0;
MOV 1,B;
MOV 0,A;
END;
DESCENDING ORDER
MOV R0,#03H
MOV R1,#05H;
MOV R2,#07H;
MOV A,R0;
SUBB A,R1;
JC L1;
JNC L2;
L1 :
MOV A,1;
MOV B,0;
MOV 1,B;
MOV 0,A;
SJMP L3;
L2 : SJMP L3;
L3: MOV A, R1;
SUBB A,R2;
JC L4;
JNC L5;
L4: MOV A,1;
MOV B,2;
MOV 1,B;
MOV 2,A;
SJMP L6;
L5: SJMP L6;
L6: MOV A,1;
SUBB A,0;
JNC L7;
JC L8;
L7: RET;
L8: MOV A,1;
MOV B,0;
MOV 1,B;
MOV 0,A;
END;
Post Lab Questions:
1. In the 8051, explain why we must write "1" to a port in order for it to be
used for input.
2. Explain why we need to buffer the switches used as input in order to avoid
damaging the 8051 port.
Result:
The given inputs are set in ascending & descending order in the output.
3. True or False. "DA A" must be used for adding BCD data only.
Program
MOV R0,#023H;
MOV A,R0;
ANL A,#0FH;
ADD A,#030H;
MOV R2,A;
MOV A,R0;
ANL A, #0F0H
SWAP A;
ADD A,#030H;
MOV R3,A;
END;
Result:
Both the conversion is done and thus the program is executed successfully.
1. Can we use the "DA A" instruction to convert data such as 9CH into BCD
without first performing an ADD instruction? Explain your answer.
2. Show a simple program to add 2345H and 56F8H.
1. Find the value of the CY flag after the execution of the following code.
STAIRCASE PROGRAMS
AIM:
To form a stair case program.
ALGORITHM:
• Start the window.
• enable the port.
• Load TMOD.
• Load OFFH into THO and OF2H into TLO.
• Delay sub route, timer is started by the ‘SET TRO’, instructions.
• Timer 0 is stopped by the instructions ‘CLR TRO’, the delay sub route ends
and the process is repeated.
• Use the INC for increment and DEC for decrement.
• Use DJNZ for the decrement and JUMP if no zero bits
Program
MOV P0,#00H
MO TMOD, #01H
L1 :
MOV TLO,
MOV THO,
INC PO
ACALL DELAY;
MOV TLO,#032H
MOV THO,# 0F5H
INC PO
ACALL DELAY;
MOV TLO, #0CBH
MOV THO,# 0F8H
INC PO
ACALL DELAY;
MOV TLO, #065H
MOV THO,# 0FCH
INC PO;
ACALL DELAY;
MOV PO,#00H;
SJMP L1;
2. Can you change the value of the SP register? If yes, explain why you would
want to do that.
3. 0The stack uses the same area of RAM as bank .
1. Name all of the interrupts in the 8051 and their vector table addresses.
COMPLEMENT PROGRAM
AIM:
To create a compliment program.
ALGORITHM:
• Enable the register R and set any value.
• Move ro, to the accumulator.
• Use CPI for the compliment accumulator.
• Add 00011010b to accumulator.
• End
Program:
MOV A,R0;
CPL A;
ADD A,#00000001B;
END;
Result: