0% found this document useful (0 votes)
18 views58 pages

22CEE461 - AEC - MES - Lab Record

The document is a laboratory manual for the Microcontroller and Embedded Systems course at New Horizon College of Engineering for the academic year 2023-2024. It outlines various experiments involving data transfer, arithmetic operations, interfacing with motors and LCDs, and programming using the 8051 microcontroller. Additionally, it includes an introduction to the 8051 architecture, memory organization, and the use of Keil μVision software for programming and emulation.

Uploaded by

srinivas216lk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views58 pages

22CEE461 - AEC - MES - Lab Record

The document is a laboratory manual for the Microcontroller and Embedded Systems course at New Horizon College of Engineering for the academic year 2023-2024. It outlines various experiments involving data transfer, arithmetic operations, interfacing with motors and LCDs, and programming using the 8051 microcontroller. Additionally, it includes an introduction to the 8051 architecture, memory organization, and the use of Keil μVision software for programming and emulation.

Uploaded by

srinivas216lk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

Department of Computer Engineering

II Year / IV Semester

22CEE461 –MICROCONTROLLER AND


EMBEDDED SYSTEMS LABORATORY

LABORATORY MANUAL

Academic Year : 2023 - 2024


Semester : EVEN
New Horizon College of Engineering Date:

Department of Computer Engineering

MICROCONTROLLER AND EMBEDDED SYSTEMS LAB

Course Code : 20CEE461 Credits : 01


L:T:P:S : 0:0:1:0 CIE Marks : 50
Exam Hours : 03 SEE Marks : 50

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).

Dept of Computer Engineering Page | 1


New Horizon College of Engineering Date:

9. Programs using serial port and on-chip timer.


10. 8051 Interfacing: Stepper Motor, DC motor.
11. 8051 Interfacing: LCD.
12. Interfacing of an keypad with 8051.

LAB-IN-CHARGE HOD-CE

Dept of Computer Engineering Page | 2


New Horizon College of Engineering Date:

MICROCONTROLLER AND EMBEDDED SYSTEMS LAB

Course Code : 20CEE461 Credits : 01


L:T:P:S : 0:0:1:0 CIE Marks : 50
Exam Hours : 03 SEE Marks : 50

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.

CO3 Analyse and develop embedded C program to interface the microcontroller to


an external world.
CO4 Develop and embedded system for control applications.

Dept of Computer Engineering Page | 3


New Horizon College of Engineering Date:

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

1.2 Write an ALP to perform Sorting an array

1.3 Write an ALP for exchanging of data

1.4 Write an ALP for finding the largest number in an array

2 PROGRAM INVOLVING ARITHMETIC OPERATIONS

2.1 Write an ALP to Perform Addition of two 16bit numbers.

2.2 Write an ALP for Subtraction of two 16 bit numbers

2.3 Write an ALP for Multiplication of two 16 bit numbers.

2.4 Write an ALP for Division of two 16-bit numbers.

2.5 Write an ALP for Square of a 16 bit number.

2.6 Write an ALP for Cube of a 16 bit number.

3 PROGRAMS FOR COUNTERS AND BIT MANIPULATION

3.1 Write an ALP to simulate an upcounter in the 8051 Microcontroller.

3.2 Write an ALP to simulate a down counter in the 8051 Microcontroller.

3.2 Study and verify the various logical and boolean operations in 8051.

4 PROGRAMS INVOLVING CODE CONVERSIONS

4.1 Write an ALP for conversion of ASCII to BCD.

4.2 Write an ALP for conversion of BCD to ASCII.

4.3 Write an ALP for conversion of Hexadecimal to Decimal.

4.4 Write an ALP for conversion of Decimal to Hexadecimal.

Dept of Computer Engineering Page | 4


New Horizon College of Engineering Date:

5 PROGRAM FOR INTERFACING 8051 WITH DAC

5.1 Write an ALP to interface 8051 Microcontroller with a DAC

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.

7 PROGRAMS FOR INTERFACING 8051 WITH MOTORS

7.1 Write an ALP to interface 8051 with a Stepper and DC Motor.

8 PROGRAM FOR INTERFACING 8051 WITH AN LCD

8.1 Write an ALP to interface 8051 Microcontroller with an LCD display.

Scheme of Evaluation
Evaluation Criteria Weightage
Weekly Assessment 30 Marks
CIE – II (2 – Lab Internals – 10 Marks Each) 20 Marks
SEE 50 Marks

Prepared By Verified By Approved By

DR.C.R.RATHISH
LAB-IN-CHARGE HOD-CE

Dept of Computer Engineering Page | 5


New Horizon College of Engineering Date:

INTRODUCTION TO 8051 MICROCONTROLLERS


8051 microcontroller is designed by Intel in 1981. It is an 8-bit microcontroller. It is built
with 40 pins DIP (dual inline package), 4kb of ROM storage and 128 bytes of RAM storage,
2 16-bit timers. It consists of are four parallel 8-bit ports, which are programmable as well
as addressable as per the requirement. An on-chip crystal oscillator is integrated in the
microcontroller having crystal frequency of 12 MHz.

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.

1. Features of 8051 Microcontroller

An 8051 microcontroller comes bundled with the following features.

● 64K bytes on-chip program memory (ROM)

● 128 bytes on-chip data memory (RAM)

● Four register banks

● 128 user defined software flags

● 8-bit bidirectional data bus

● 16-bit unidirectional address bus

● 32 general purpose registers each of 8-bit

● 16 bit Timers (usually 2, but may have more or less)

● Three internal and two external Interrupts

● Four 8-bit ports,(short model have two 8-bit ports)

● 16-bit program counter and data pointer

Dept of Computer Engineering Page | 6


New Horizon College of Engineering Date:

2. Architecture Of 8051 Microcontroller

Figure 1.4 shows the architecture block diagram of 8051.

2.1 8051 Memory Organization

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).

Dept of Computer Engineering Page | 7


New Horizon College of Engineering Date:

2.2 Timers and Counters

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.

2.3 Serial Port


There are two pins available for serial communication TXD and RXD. Normally TXD is
used for transmitting serial data which is in SBUF register, RXD is used for receiving the
serial data. SCON register is used for controlling the operation.

2.4 Input Output Ports


There are four input output ports available P0, P1, P2, P3. Each port is 8 bit wide and has
special function register P0, P1, P2, P3 which are bit addressable means each bit can be
set or reset by the Bit instructions (SETB for high, CLR for low) independently. The data
at any port which is transmitting or receiving is in these registers. The port 0 can perform
dual works. It is also used as Lower order address bus (A0 to A7) multiplexed with 8 bit
data bus P0.0 to P0.7 is AD0 to AD7 respectively the address bus and data bus is
demultiplex by the ALE signal and latch which is further discussed in details. Port 2 can
be used as I/O port as well as higher order address bus A8 to A15. Port 3 also have dual
functions it can be worked as I/O as well as each pin of P3 has specific function. P3.0 –
RXD – {Serial I / P for Asynchronous communication Serial O / P for synchronous
communication. P3.1 – TXD – Serial data transmit. P3.2 – INT0 – External Interrupt 0.
P3.3 – INT1 – External Interrupt 1. P3.4 – T0 – Clock input for counter 0. P3.5 – T1 –
Clock input for counter 1. P3.6 – WR – Signal for writing to external memory. P3.7

Dept of Computer Engineering Page | 8


New Horizon College of Engineering Date:

– 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 Diagram Of 8051 microcontroller

Dept of Computer Engineering Page | 9


New Horizon College of Engineering Date:

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

Dept of Computer Engineering Page | 10


New Horizon College of Engineering Date:

Introduction to Keil μvision

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.

Procedure for using Keil μvision:

Step 1: Open Keil μVision software from start menu.

Step 2: Open the Project tab located in the menu on top and click on New μVision
Project.

Dept of Computer Engineering Page | 11


New Horizon College of Engineering Date:

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.

Dept of Computer Engineering Page | 12


New Horizon College of Engineering Date:

Step 4: Click on No in the dialog box that appears next.

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.

Dept of Computer Engineering Page | 13


New Horizon College of Engineering Date:

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.

Dept of Computer Engineering Page | 14


New Horizon College of Engineering Date:

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.

Dept of Computer Engineering Page | 15


New Horizon College of Engineering Date:

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 1: Open proteus software from start menu.

Step 2: Open the New Project tab located in the start and choice your path and click
on next

Dept of Computer Engineering Page | 16


New Horizon College of Engineering Date:

Step 3: click on next in the continues tabs opened and finish

Dept of Computer Engineering Page | 17


New Horizon College of Engineering Date:

• 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.

Dept of Computer Engineering Page | 18


New Horizon College of Engineering Date:

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

Dept of Computer Engineering Page | 19


New Horizon College of Engineering Date:

Step 7: double click on the central area to insert the component

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

Dept of Computer Engineering Page | 20


New Horizon College of Engineering Date:

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

Dept of Computer Engineering Page | 21


New Horizon College of Engineering Date:

Step 11: To run the program, click on run at the bottom left side

Dept of Computer Engineering Page | 22


New Horizon College of Engineering Date:

EXPERIMENT: 1
DATA TRANSFER OPERATIONS USING 8051

Dept of Computer Engineering Page | 23


New Horizon College of Engineering Date:

EXPERIMENT: 1

1.1 Block Data transfer using 8051 Microcontroller

AIM: To transfer data between specified memory locations.

SOFTWARE REQUIRED: Keil μvision

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

Dept of Computer Engineering Page | 24


New Horizon College of Engineering Date:

1.2 Write an ALP to perform Sorting an array

AIM: To sort the array in ascending order

SOFTWARE REQUIRED: Keil μvision

PROGRAM:

MOV R0,#05H;

LOOP1: MOV DPTR,#9000H;

MOV R1,#05H;

LOOP2: MOVX A,@DPTR;

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

NOEXCHG : DJNZ R1,LOOP2;

DJNZ R0,LOOP1;

END

Dept of Computer Engineering Page | 25


New Horizon College of Engineering Date:

INPUT : 23H, 34H, 45H, 2AH, 01H

OUTPUT : 01H, 23H, 2AH, 34H, 45H

RESULT: The program for sorting an array in ascending order was verified and
successfully executed.

Dept of Computer Engineering Page | 26


New Horizon College of Engineering Date:

1.3 Write an ALP for exchanging of data

AIM: To exchange the data between specified memory locations.

SOFTWARE REQUIRED: Keil μvision

PROGRAM:

MOV R0 ,#30H

MOV R1, #40H

MOV R7, #05H

BACK: MOV A,@R0

MOV R4,A

MOV A,@R1

MOV @R0,A

MOV A,R4

MOV @R1,A

INC R0

INC R1

DJNZ R7,BACK

END

INPUT: address 30h - data 20h, address 40h – data 25h

OUTPUT: address 30h – data 25h, address 40h – data 20h

RESULT: The program to exchange the data between specified memory locations was
verified and successfully executed.

Dept of Computer Engineering Page | 27


New Horizon College of Engineering Date:

1.4 Write an ALP for finding the largest number in an array


AIM: To find the largest number in a given array

SOFTWARE REQUIRED: Keil μvision

PROGRAM:

MOV R3, #6;

MOV DPTR, #4000H

MOVX A, @DPTR

MOV R1, A

NEXTBYTE: INC DPTR

MOVX A, @ DPTR

CLR C;

MOV R2, A;

SUBB A R1;

JC SKIP;

MOV A, R2;

MOV R1, A

SKIP: DJNZ R3, NEXTBYTE

MOV DPTR, #5000H;

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.

Dept of Computer Engineering Page | 28


New Horizon College of Engineering Date:

EXPERIMENT: 2
PROGRAM INVOLVING ARITHMETIC
OPERATIONS

Dept of Computer Engineering Page | 29


New Horizon College of Engineering Date:

2.1 Write a ALP to perform addition of two 16 bit numbers

AIM: To find the addition of two 16-bit numbers

SOFTWARE REQUIRED: Keil μvision

PROGRAM:

ORG 0000H

CLR C

MOV A, #020H

ADD A, #0DEH

MOV R1, A

MOV A, #65H

ADDC A, #0ABH

MOV R0, A

END

INPUT: 6520H, ABDEh

OUTPUT: 10FE

RESULT: The program for addition of two 16-bit numbers was verified and
successfully executed.

Dept of Computer Engineering Page | 30


New Horizon College of Engineering Date:

2.2 Write an ALP for Subtraction of two 16-bit numbers

AIM: To find the subtraction of two 16-bit numbers

SOFTWARE REQUIRED: Keil μvision

PROGRAM:

ORG 0000H

CLR C ;

MOV A,#020H;

SUBB A,#0DEH;

MOV R1,A;

MOV A,#65H;

SUBB A,#0ABH;

MOV R0,A;

END

INPUT: 6520H, ABDEh

OUTPUT: 46BEh

RESULT: The program for subtraction of two 16-bit numbers was verified and
successfully executed.

Dept of Computer Engineering Page | 31


New Horizon College of Engineering Date:

2.3 Write an ALP for Multiplication of two 16-bit numbers.

AIM: To find the multiplication of two 16-bit numbers

SOFTWARE REQUIRED: Keil μvision

PROGRAM:

ORG 0000H

MOV R0,#0FFH ;MSB1

MOV R1,#0EFH ;MSB2

MOV R2,#0FFH ;LSB1

MOV R3,#9DH ;LSB2

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

Dept of Computer Engineering Page | 32


New Horizon College of Engineering Date:

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

INPUT: FFFFh, EF9Dh

OUTPUT: EE5C1A63h

RESULT: The program for multiplication of two 16-bit numbers was verified and
successfully executed.

Dept of Computer Engineering Page | 33


New Horizon College of Engineering Date:

2.4 Write an ALP for Division of two 16-bit numbers.

AIM: To find the division of two 16-bit numbers

SOFTWARE REQUIRED: Keil μvision

PROGRAM:

START:

MOV R0, #20H

MOV R1, #30H

MOV A, @R0

INC R0

MOV B, @R0

DIV AB

MOV @R1, A

INC R1

MOV @R1, B;

END

INPUT: Dividend - 99h, Divisor - 0Fh

OUTPUT: Quotient - 0Ah, Reminder - 03h

RESULT: The program for division of two 16-bit numbers was verified and
successfully executed.

Dept of Computer Engineering Page | 34


New Horizon College of Engineering Date:

2.5 Write an ALP for Square of a 16-bit number

AIM: To find the square of a 16-bit numbers

SOFTWARE REQUIRED: Keil μvision

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.

Dept of Computer Engineering Page | 35


New Horizon College of Engineering Date:

2.6 Write an ALP for Cube of a 16-bit number

AIM: To find the square of a 16-bit numbers

SOFTWARE REQUIRED: Keil μvision

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.

Dept of Computer Engineering Page | 36


New Horizon College of Engineering Date:

EXPERIMENT: 3
PROGRAMS INVOLVING COUNTERS AND BIT
MANIPULATION

Dept of Computer Engineering Page | 37


New Horizon College of Engineering Date:

3.1 write an ALP to utilise the counter present in the 8051 Microcontroller

AIM: To utilise the counter present in the 8051 Microcontroller

SOFTWARE REQUIRED: Keil μvision

PROGRAM:

MOV A, #00H ; MOV A, #FF for down counter

BACK: ACALL DELAY

ADD A, #99H

DAA

JNZ BACK

HERE: SIMP HERE

DELAY:MOV R1, #0FFH

DCR1:MOV R2, #0FFH

DECR: MOV R3, #0FFH

DJNX R3, $

DJNZ R2, DECR

DJNZ R1, DECR1

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

Dept of Computer Engineering Page | 38


New Horizon College of Engineering Date:

3.2 Study and verify the various logical and boolean operations in 8051.

AIM: To verify the various logical and boolean operations in 8051.

SOFTWARE REQUIRED: Keil μvision

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

OUTPUT: AND - 1 OR - 1 XOR - 1 in 30h, 31h and 32h respectively

RESULT: The program to verify the various logical and boolean operations in 8051 is
executed and the output is verified.

Dept of Computer Engineering Page | 39


New Horizon College of Engineering Date:

EXPERIMENT: 4
PROGRAMS INVOLVING CODE
CONVERSIONS

Dept of Computer Engineering Page | 40


New Horizon College of Engineering Date:

4.1 Write an ALP for conversion of ASCII to BCD

AIM: To Write an ALP for conversion of ASCII to BCD

SOFTWARE REQUIRED: Keil μvision

PROGRAM:

START:

MOV R0, #40H

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.

Dept of Computer Engineering Page | 41


New Horizon College of Engineering Date:

4.2 Write an ALP for conversion of BCD to ASCII.

AIM: To Write an ALP for conversion of BCD to ASCII.

SOFTWARE REQUIRED: Keil μvision

PROGRAM:

START:

MOV R0, #40H

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.

Dept of Computer Engineering Page | 42


New Horizon College of Engineering Date:

4.3 Write an ALP for conversion of Hexadecimal to Decimal.

AIM: To Write an ALP for conversion of Hexadecimal to Decimal.

SOFTWARE REQUIRED: Keil μvision

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.

Dept of Computer Engineering Page | 43


New Horizon College of Engineering Date:

4.4 Write an ALP for conversion of Decimal to Hexadecimal

AIM: To Write an ALP for conversion of Decimal to Hexadecimal

SOFTWARE REQUIRED: Keil μvision

PROGRAM:

MOV A, #95H //A = DECIMAL NUMBER TO BE CONVERTED TO


THE BINARY(HEX)

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.

Dept of Computer Engineering Page | 44


New Horizon College of Engineering Date:

EXPERIMENT: 5
PROGRAMS TO INTERFACE 8051 WITH A DAC

Dept of Computer Engineering Page | 45


New Horizon College of Engineering Date:

5.1 Write an ALP to interface 8051 with a DAC.

AIM: To Write an ALP that interfaces 8051 with a Digital to Analog Converter.

SOFTWARE REQUIRED: Keil μvision and Proteus

PROGRAM:

ORG 0000H

MOV TMOD, #20H

MOV TH1, #1AH

MAIN:CPL P1.3

ACALL DELAY

SJMP MAIN

DELAY: SETB TR1

AGAIN: JNB TF1, AGAIN

CLR TR1

CLR TF1

RET

END

Dept of Computer Engineering Page | 46


New Horizon College of Engineering Date:

OUTPUT:

RESULT: The program for utilizing the serial port and on-chip timer is executed and
the output is verified.

Dept of Computer Engineering Page | 47


New Horizon College of Engineering Date:

EXPERIMENT: 6
PROGRAMS USING SERIAL PORT AND ON
CHIP TIMER

Dept of Computer Engineering Page | 48


New Horizon College of Engineering Date:

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.

SOFTWARE REQUIRED: Keil μvision and Proteus

PROGRAM:

#include<reg51.h>

void main()

SCON=0X50;

TMOD=0X20;

TH1=-3; // BAUDRATE 9600

TR1=1;

SBUF = 'I';

while(TI==0); // COMPLETION OF TRANSMISSION

TI=0; // NEXT TRANSMISSION

OUTPUT:

RESULT: The program for utilizing the serial port and on-chip timer is executed and
the output is verified.

Dept of Computer Engineering Page | 49


New Horizon College of Engineering Date:

EXPERIMENT: 7
PROGRAMS FOR INTERFACING 8051 WITH
MOTORS

Dept of Computer Engineering Page | 50


New Horizon College of Engineering Date:

7.1 Write an ALP to interface 8051 with a stepper and dc motor

AIM: To Write an ALP that interfaces 8051 with a stepper and dc motor.

SOFTWARE REQUIRED: Keil μvision and Proteus

PROGRAM:

#include<reg51.h>

sbit l1=P1^0;

sbit l2=P1^1;

sbit l3=P1^2;

sbit l4=P1^4;

void main (){

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;

Dept of Computer Engineering Page | 51


New Horizon College of Engineering Date:

OUTPUT:

RESULT: The program for interfacing 8051 microcontroller with a stepper motor is
executed and the output is verified.

Dept of Computer Engineering Page | 52


New Horizon College of Engineering Date:

EXPERIMENT: 8
PROGRAMS FOR INTERFACING 8051 WITH
AN LCD

Dept of Computer Engineering Page | 53


New Horizon College of Engineering Date:

8.1 Write an ALP to interface 8051 with an LCD

AIM: To Write an ALP that interfaces 8051 with an LCD.

SOFTWARE REQUIRED: Keil μvision and Proteus

PROGRAM:

#include<reg51.h>

#define display_port P2 //Data pins connected to port 2 on microcontroller

sbit rs = P3^2; //RS pin connected to pin 2 of port 3

sbit rw = P3^3; // RW pin connected to pin 3 of port 3

sbit e = P3^4; //E pin connected to pin 4 of port 3

void msdelay(unsigned int time) { // Function for creating delay in milliseconds.

unsigned i,j ;

for(i=0;i<time;i++)

for(j=0;j<1275;j++);

void lcd_cmd(unsigned char command){ //Function to send command instruction to LCD

display_port = command;

rs= 0;

rw=0;

e=1;

msdelay(1);

e=0;

Dept of Computer Engineering Page | 54


New Horizon College of Engineering Date:

void lcd_data(unsigned char disp_data) { //Function to send display data to LCD

display_port = disp_data;

rs= 1;

rw=0;

e=1;

msdelay(1);

e=0;

void lcd_init() { //Function to prepare the LCD and get it ready

lcd_cmd(0x38); // for using 2 lines and 5X7 matrix of LCD

msdelay(10);

lcd_cmd(0x0F); // turn display ON, cursor blinking

msdelay(10);

lcd_cmd(0x01); //clear screen

msdelay(10);

lcd_cmd(0x81); // bring cursor to position 1 of line 1

msdelay(10);

void main(){

unsigned char a[15]="HELLO CE"; //string of 14 characters with a null terminator.

Dept of Computer Engineering Page | 55


New Horizon College of Engineering Date:

int l=0;

lcd_init();

while(a[l] != '\0') // searching the null terminator in the sentence

lcd_data(a[l]);

l++;

msdelay(50);

OUTPUT:

Dept of Computer Engineering Page | 56


New Horizon College of Engineering Date:

RESULT: The program for interfacing 8051 microcontroller with an LCD is executed
and the output is verified.

Dept of Computer Engineering Page | 57

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy