22CEE461 - AEC - MES - Lab Record
22CEE461 - AEC - MES - Lab Record
II Year / IV Semester
LABORATORY MANUAL
LIST OF EXPERIMENTS
1. Data transfer – Program for block data movement, sorting, exchanging, finding largest
element in an array.
2. Program for exchanging of data between the array of a memory.
3. Program to find largest and smallest number in an array.
4. Program for sorting of a numbers.
5. Arithmetic instructions: Addition, subtraction, multiplication and division. Square and cube
operations for 16-bit numbers.
6. Counters, Boolean and logical instructions (bit manipulation).
7. Code conversion programs – BCD to ASCII, ASCII to BCD, ASCII to decimal, Decimal
to ASCII, Hexa decimal to and Decimal to Hexa.
8. 8051 Interfacing: DAC (wave form generation).
LAB-IN-CHARGE HOD-CE
Course
Expt. No Topics
Outcomes
1. Data transfer – Program for block data movement, sorting, exchanging,
finding largest element in an array.
CO1, CO2
1 2. Arithmetic instructions: Addition, subtraction, multiplication and division.
Square and cube operations for 16-bit numbers.
3. Counters, Boolean and logical instructions (bit manipulation).
4. Code conversion programs – BCD to ASCII, ASCII to BCD, ASCII to
CO3
2 decimal, Decimal to ASCII, Hexa decimal to and Decimal to Hexa.
5. 8051 Interfacing: DAC (wave form generation)
6. Programs using serial port and on-chip timer
3 7. 8051 Interfacing: Stepper Motor, DC motor. CO4
8. 8051 Interfacing: LCD.
CO1 Write assembly level programs for basic operations and the memories.
CO2 Apply the knowledge of assembly language program for data processing.
INDEX
Expt.
Name of the Experiment
No. Signature Marks
Introduction - 8051 Microcontroller and Keil μVision
Introduction to Proteus
1 PROGRAMS INVOLVING DATA TRANSFER
1.1 Write an ALP to perform Block Data transfer
3.2 Study and verify the various logical and boolean operations in 8051.
6.1 Write an ALP to utilize the serial port and on-chip timer of 8051.
Scheme of Evaluation
Evaluation Criteria Weightage
Weekly Assessment 30 Marks
CIE – II (2 – Lab Internals – 10 Marks Each) 20 Marks
SEE 50 Marks
DR.C.R.RATHISH
LAB-IN-CHARGE HOD-CE
The 8051 memory is organized in a Harvard Architecture. Both the code memory space and
data memory space begin at location 0x00 for internal or external memory which is different
from the Princeton Architecture where code and data share same memory space. The
advantage of the Harvard Architecture is not only doubling the memory capacity of the
microcontroller with same number of address lines but also increases the reliability of the
microcontroller, since there are no instructions to write to the code memory which is read
only.
8051 microcontroller has an internal program of 4K size and if needed an external memory
can be added (by interfacing) of size 60K maximum. So in total 64K size memory is
available for 8051 micro controller. By default, the External Access (EA) pin should be
connected Vcc so that instructions are fetched from internal memory initially. When the
limit of internal memory (4K) is crossed, control will automatically move to external
memory to fetch remaining instructions. If the programmer wants to fetch instruction from
external memory only (bypassing the internal memory), then he must connect External
Access (EA) pin to ground (GND).
Timer means which can give the delay of particular time between some events. For
example, on or off the lights after every 2 sec. This delay can be provided through some
assembly program but in microcontroller two hardware pins are available for delay
generation. These hardware pins can be also used for counting some external events. How
much times a number is repeated in the given table is calculated by the counter.
In MC8051, two timer pins are available T0 and T1, by these timers we can give the delay
of particular time if we use these in timer mode. We can count external pulses at these
pins if we use these pins in counter mode. 16 bits timers are available. Means we can
generate delay between 0000H to FFFFH. Two special function registers are available. If
we want to load T0 with 16 bit data then we can load separate lower 8 bit in TL0 and
higher 8 bit in TH0. In the same way for T1. TMOD, TCON registers are used for
controlling timer operation.
– RD – Signal for reading from external memory. When external memory is interfaced
with 8051 then P0 and P2 can’t be worked as I/O port they works as address bus and data
bus, otherwise they can be accessed as I/O ports.
2.5 Oscillator
It is used for providing the clock to MC8051 which decides the speed or baud rate of MC.
We use crystal which frequency vary from 4MHz to 30 MHz, normally we use 11.0592
MHz frequency.
2.6 Interrupts
Interrupts are defined as requests because they can be refused (masked) if they are not
used, that is when an interrupt is acknowledged. A special set of events or routines are
followed to handle the interrupts. These special routines are known as interrupt handler or
interrupt service routines (ISR). These are located at a special location in memory. • INT0
and INT1 are the pins for external interrupts.
Pin Description
The EA' (External Access) pin is used to control the internal or external memory access. The
signal 0 is for external memory access and signal 1 for internal memory access. The PSEN'
(Program Store Enable) is for reading external code memory when it is low (0) and EA is
also 0. The ALE (Address Latch Enable) activates the port 0 joined with port 2 to provide
16 bit external address bus to access the external memory. The ALE multiplexes the P0: 1
for latching address on P0 as A0-A7 in the 16 bit address buss, 0 for latching P0 as data I/O.
P0.x is named ADx because P0 is multiplexed for Address bus and Data bus at different
clock time. WR' provides the signal to write external data memory RD' provides the signal
to read external data and code memory.
❖ PORT P1 (Pins 1 to 8): The port P1 is a port dedicated for general I/O purpose. The other
ports P0, P2 and P3 have dual roles in addition to their basic I/O function.
❖ PORT P0 (pins 32 to 39): When the external memory access is required then Port P0 is
multiplexed for address bus and data bus that can be used to access external memory in
conjunction with port P2. P0 acts as A0-A7 in address bus and D0-D7 for port data. It
can be used for general purpose I/O if no external memory presents.
❖ PORT P2 (pins 21 to 28): Similar to P0, the port P2 can also play a role (A8-A15) in the
address bus in conjunction with PORT P0 to access external memory.
❖ PORT P3 (Pins 10 to 17): In addition to acting as a normal I/O port,
⮚ P3.0 can be used for serial receive input pin(RXD) • P3.1 can be used for serial
transmit output pin(TXD) in a serial port,
⮚ P3.2 and P3.3 can be used as external interrupt pins(INT0’ and INT1’),
⮚ P3.4 and P3.5 are used for external counter input pins(T0 and T1),
⮚ P3.6 and P3.7 can be used as external data memory write and read control signal
pins(WR’ and RD’)read and write pins for memory access
Keil μvision is a software that allows us to write assembly or embedded-c programs and
emulate them on a multitude of devices. In this scenario we are going to use this software for
studying the behaviour of 8051 microcontroller by writing applications and programs in
assembly language/embedded-c for the same and emulating these programs.
Step 2: Open the Project tab located in the menu on top and click on New μVision
Project.
Step 3: After that, you will be presented with a dialog box like this. Select the directory
and give the file name and click on Save button.
Step 4: Another window will pop up, enter AT89C51 in the search option in it as given
below and then select AT89C51 from the list that appears below and click on OK.
Step 5: On left side, in Project tab, click on the + symbol beside Target 1 folder, and
the Right Click on Source Group 1 folder and select Add New Item option.
Step 6: In the next dialog box select Asm file or C file, and then give filename below
and click on Add button.
Step 7: Write the code in the file, then click on Build icon or press F7 to build the
target file and check the Build Output tab below to check if any errors exist.
Step 8: If no errors exist then click on debug icon and then OK in the pop up next.
Step 9: Then in debug mode close all the tabs below that are unnecessary and only
keep memory tab.
Step 10: In Memory 1 tab below access any memory using d:[Address] command
(ex: d:040h). Then click on the Run command on the top left corner or press F5.
Introduction to Proteus
Proteus Professional 2022 is a fast and powerful yet simple-to-use application which can be used to
easily and quickly create any kind of printed circuit board designs. It is a comprehensive application
which offers an extensive library of electronic components for creating any kind of electrical circuits.
It allows electrical engineers to simulate the operation of a wide range of programmable gadgets such
as micro controllers, microprocessors, DSP and many more. The program offers a neat and clean
interface which provides an intuitive development environment.
Procedure for using proteus:
Step 2: Open the New Project tab located in the start and choice your path and click
on next
• Step 4: In the central area surrounded by blue lines, we design our circuit by placing
the components and then join them together to run the program.
Step 5: After clicking on P button and new window will open up and
• Step 6: In this new window there's a textbox on which Keyword is written, this text
box is used for the component search. Proteus database has unlimited components in
it so now in order to get your desired component search for AT89C51 Proteus provided
the component along with its preview in top right corner and PCB package and click
on OK
Step 8: There are few measuring instruments available in Proteus, which you can
open by clicking the virtual Instruments Icon, as shown in figure and you can your
component according to the program
Step 9: further on to find the output,after designing the components double link on
the AT89C51 component , a dialogue box will appear as shown below
Step 10: Choose the file from the program files and check the clock frequency to
always be 11.0592
Step 11: To run the program, click on run at the bottom left side
EXPERIMENT: 1
DATA TRANSFER OPERATIONS USING 8051
EXPERIMENT: 1
PROGRAM:
ORG 0000H
START:
MOV R0, #40H
MOV R1, #50H
MOV R7, #05H
BACK:MOV A, @R0
MOV @R1, A
INC R0
INC R1
DEC R7
JNZ R7, BACK
END
OUTPUT:
LOCATION DATA
40H 01
41H 02
INPUT 42H 03
43H 04
44H 05
50H 01
51H 02
OUTPUT 52H 03
53H 04
54H 05
RESULT: The program for transfer of data from one memory location to another was
verified and successfully executed
PROGRAM:
MOV R0,#05H;
MOV R1,#05H;
MOV B,A
INC DPTR
MOVX A, @DPTR ;
CLR C;
MOV R2,A;
SUBB A,B;
JNC NOEXCHG;
MOV A,B;
MOVX @DPTR ,A
DEC DPL;
MOV A,R2
MOVX @DPTR ,A
INC DPTR
DJNZ R0,LOOP1;
END
RESULT: The program for sorting an array in ascending order was verified and
successfully executed.
PROGRAM:
MOV R0 ,#30H
MOV R4,A
MOV A,@R1
MOV @R0,A
MOV A,R4
MOV @R1,A
INC R0
INC R1
DJNZ R7,BACK
END
RESULT: The program to exchange the data between specified memory locations was
verified and successfully executed.
PROGRAM:
MOVX A, @DPTR
MOV R1, A
MOVX A, @ DPTR
CLR C;
MOV R2, A;
SUBB A R1;
JC SKIP;
MOV A, R2;
MOV R1, A
MOV A, R1;
MOVX @DPTR, A;
END
INPUT: 01H,05H,03H,09H,04H
OUTPUT: 09H
RESULT: The program to find the largest number in an array was verified and
successfully executed.
EXPERIMENT: 2
PROGRAM INVOLVING ARITHMETIC
OPERATIONS
PROGRAM:
ORG 0000H
CLR C
MOV A, #020H
ADD A, #0DEH
MOV R1, A
MOV A, #65H
ADDC A, #0ABH
MOV R0, A
END
OUTPUT: 10FE
RESULT: The program for addition of two 16-bit numbers was verified and
successfully executed.
PROGRAM:
ORG 0000H
CLR C ;
MOV A,#020H;
SUBB A,#0DEH;
MOV R1,A;
MOV A,#65H;
SUBB A,#0ABH;
MOV R0,A;
END
OUTPUT: 46BEh
RESULT: The program for subtraction of two 16-bit numbers was verified and
successfully executed.
PROGRAM:
ORG 0000H
MOV A,R2
MOV B,R3
MUL AB
MOV R4,A
MOV R5,B
MOV A,R2
MOV B,R1
MUL AB
MOV R6,B
ADDC A,R5
MOV R5,A
MOV A,R1
MOV B,R4
MUL AB
ADDC A,R5
MOV R5,A
MOV A,B
ADDC A,R6
MOV R6,A
MOV A,R1
MOV B,R2
MUL AB
ADDC A,R6
MOV R6,A
MOV A,B
ADDC A,#00H
MOV R7,A
END
OUTPUT: EE5C1A63h
RESULT: The program for multiplication of two 16-bit numbers was verified and
successfully executed.
PROGRAM:
START:
MOV A, @R0
INC R0
MOV B, @R0
DIV AB
MOV @R1, A
INC R1
MOV @R1, B;
END
RESULT: The program for division of two 16-bit numbers was verified and
successfully executed.
PROGRAM:
MOV A,#03
MOV B,A
MUL AB
MOV 30H,A
MOV 31H,B
END
INPUT: 03H
OUTPUT: 09H
RESULT: The program for square of two 16-bit numbers was verified and successfully
executed.
PROGRAM:
MOV R0,#0FH
MOV A,R0
MOV B,50
MUL AB
MOV R1,B
MOV B,R0
MUL AB
MOV 32H,A
MOV R2,B
MOV A,R1
MOV B,R0
MUL AB
ADD A,R2
MOV 31H,A
MOV A,B
ADDC A,#00H
MOV 30H,A
END
INPUT: 0Fh
OUTPUT: D2Fh
RESULT: The program for cube of two 16-bit numbers was verified and successfully
executed.
EXPERIMENT: 3
PROGRAMS INVOLVING COUNTERS AND BIT
MANIPULATION
3.1 write an ALP to utilise the counter present in the 8051 Microcontroller
PROGRAM:
ADD A, #99H
DAA
JNZ BACK
DJNX R3, $
RET
END
OUTPUT: Go to view, click on watch windows, select watch1 and enter ‘a’ to view the
output.
RESULT: The program to utilise the counter present in the 8051 Microcontroller is
executed and the output is verified
3.2 Study and verify the various logical and boolean operations in 8051.
PROGRAM:
START;
MOV A, #1b
ANL A, #1b
MOV 30H, A
MOV A, #1b
ORL A, #0b
MOV 31H, A
MOV A, #1b
XRL A, #0b
MOV 32H, A
END
INPUT: For AND - #1b, #1b For OR - #1b, #0b For XOR - #1b, #0b
RESULT: The program to verify the various logical and boolean operations in 8051 is
executed and the output is verified.
EXPERIMENT: 4
PROGRAMS INVOLVING CODE
CONVERSIONS
PROGRAM:
START:
MOV A, @R0
SUBB A, #30H
INC R0
MOV @R0, A
END
INPUT: AAh
OUTPUT: 7Ah
RESULT: The program for conversion of ASCII to BCD is executed and the output is
verified.
PROGRAM:
START:
MOV A, @R0
ADD A, #30H
INC R0
MOV @R0, A
END
INPUT: 7Ah
OUTPUT: AAh
RESULT: The program for conversion of BCD to ASCII is executed and the output is
verified.
PROGRAM:
MOV A, #0FEH
MOV B, #0AH
DIV AB
MOV R0, B
MOV B, #0AH
DIV AB
MOV 30H, A
MOV A, B
SWAP A
ORL A, R0
MOV 31H, A
END
INPUT: 0FEh
OUTPUT: 254
RESULT: The program for conversion of Hexadecimal to Decimal is executed and the
output is verified.
PROGRAM:
MOV B, #10H
DIV AB
MOV R1, B
MOV B, #0AH
MUL AB
ADD A, R1
MOV 30H, A
END
INPUT: 95
OUTPUT: 5Fh
RESULT: The program for conversion of Decimal to Hexadecimal is executed and the
output is verified.
EXPERIMENT: 5
PROGRAMS TO INTERFACE 8051 WITH A DAC
AIM: To Write an ALP that interfaces 8051 with a Digital to Analog Converter.
PROGRAM:
ORG 0000H
MAIN:CPL P1.3
ACALL DELAY
SJMP MAIN
CLR TR1
CLR TF1
RET
END
OUTPUT:
RESULT: The program for utilizing the serial port and on-chip timer is executed and
the output is verified.
EXPERIMENT: 6
PROGRAMS USING SERIAL PORT AND ON
CHIP TIMER
6.1 Write an ALP to utilize the serial port and on-chip timer of 8051.
AIM: To Write an ALP that utilizes the serial port and on-chip timer of 8051.
PROGRAM:
#include<reg51.h>
void main()
SCON=0X50;
TMOD=0X20;
TR1=1;
SBUF = 'I';
OUTPUT:
RESULT: The program for utilizing the serial port and on-chip timer is executed and
the output is verified.
EXPERIMENT: 7
PROGRAMS FOR INTERFACING 8051 WITH
MOTORS
AIM: To Write an ALP that interfaces 8051 with a stepper and dc motor.
PROGRAM:
#include<reg51.h>
sbit l1=P1^0;
sbit l2=P1^1;
sbit l3=P1^2;
sbit l4=P1^4;
unsigned int i;
l1=l2=l3=l4=0;
while(1){
l1=1;
l2=l3=l4=0;
for(i=0;i<60000;i++);
l2=1;
l1=l3=l4=0;
for(i=0;i<60000;i++);
l3=1;
l1=l2=l4=0;
for(i=0;i<60000;i++);
l4=1;
l1=l2=l3=0;
OUTPUT:
RESULT: The program for interfacing 8051 microcontroller with a stepper motor is
executed and the output is verified.
EXPERIMENT: 8
PROGRAMS FOR INTERFACING 8051 WITH
AN LCD
PROGRAM:
#include<reg51.h>
unsigned i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
display_port = command;
rs= 0;
rw=0;
e=1;
msdelay(1);
e=0;
display_port = disp_data;
rs= 1;
rw=0;
e=1;
msdelay(1);
e=0;
msdelay(10);
msdelay(10);
msdelay(10);
msdelay(10);
void main(){
int l=0;
lcd_init();
lcd_data(a[l]);
l++;
msdelay(50);
OUTPUT:
RESULT: The program for interfacing 8051 microcontroller with an LCD is executed
and the output is verified.