0% found this document useful (0 votes)
79 views69 pages

Fybca Electronics Practical Updated

The document outlines the lab course syllabus for CA-101 under the Choice Based Credit System (CBCS) for the First Year of Bachelor of Computer Applications, effective from the Academic Year 2024-2025. It includes a list of assignments focused on 8051 microcontroller programming, detailing objectives, requirements, and types of instructions for programming. Additionally, it provides a completion sheet for assignments and a certificate template for successful course completion.

Uploaded by

sanjay37932
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)
79 views69 pages

Fybca Electronics Practical Updated

The document outlines the lab course syllabus for CA-101 under the Choice Based Credit System (CBCS) for the First Year of Bachelor of Computer Applications, effective from the Academic Year 2024-2025. It includes a list of assignments focused on 8051 microcontroller programming, detailing objectives, requirements, and types of instructions for programming. Additionally, it provides a completion sheet for assignments and a certificate template for successful course completion.

Uploaded by

sanjay37932
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/ 69

FYBCA(Science)

Lab course on CA-101 – T

(Faculty of Science & Technology)


(For Colleges Affiliated to Savitribai Phule Pune
University)

Choice Based Credit System (CBCS) Syllabus Under National Education Policy
(NEP)

To be implemented from Academic Year 2024-2025


Title of the Course: B.C.A./B.Sc. (CA)

First Year of Bachelor of Computer


Applications
Semester-II
CA- 154 - P Lab course on CA- 153 - T

Work Book
Name:

College Name:

Roll No.: Division:

Academic Year:
1
F.Y.B.C.A
Semester-II

CA- 154 - P Lab course on CA- 153 - T

CERTIFICATE
This is to certify that
Mr./Ms. has successfully
completed the lab book on 8051 Microcontroller Programming CA- 154 -

P Lab course on CA- 153 - T course work and has scored marks
out of 15.

Instructor H.O.D./Coordinator

Internal examiner External examiner

2
List of Assignments

1. Study of 8051 microcontroller chip, keil µvision-5.


2. Study of proteus simulator for 8051 simulation.
3. Program to find Largest/smallest from a series.
4. Program to perform Addition / subtraction / multiplication/division of
8/16 bit data.
5. Program to perform Arithmetic, logical & code conversion problems
6. Program to perform data transfer/exchange between specified
memory’s locations.
7. Interfacing of LED/LEDs to 8051 microcontroller.
8. Interfacing of switch & LED to 8051 microcontroller.
9. Waveform generation using DAC Interface to 8051 Microcontroller.
10. Traffic light controller using 8051 microcontroller.
11. Interfacing LCD to 8051Microcontroller.
12. Interfacing with IR sensor to 8051 microcontroller and LCD.
13. ADC interfacing to 8051 Microcontroller.
14. Stepper motor interfacing to 8051 microcontroller.
15. DC motor interfacing to 8051 microcontroller.

3
Assignment Completion Sheet

Sr. No. Assignment Name Sign Grade

1 Study of 8051 microcontroller chip, keil µvision-5.


(Demonstration)
2 Study of proteus simulator for 8051 simulation
(Demonstration)

3 Program to perform data transfer/exchange between


specified memories locations
4 Program to perform Arithmetic, logical & code
conversion problems
5 Program to perform Addition / subtraction /
multiplication/division of 8/16 bit data.
6 Program to find Largest/smallest from a series

7 Interfacing of LED/LED s to 8051 microcontroller.


8 Interfacing of switch & LED to 8051 microcontroller.
9 Traffic light controller using 8051 microcontroller.
10 Interfacing LCD to 8051Microcontroller.
11 Interfacing with IR sensor to 8051 microcontroller and LCD.

12 ADC interfacing to 8051 Microcontroller.


13 Waveform generation using DAC Interface to 8051
Microcontroller.
14 DC motor interfacing to 8051 microcontroller.
15 Stepper motor interfacing to 8051 microcontroller.

4
Assignment No. 1
Study of 8051 Microcontroller Chip and Keil μVision-5
Aim: Study of 8051 microcontroller chip, Keil μvision-5.
Requirements: System / PC required min. 04 GB RAM / Installed Keil uvision-5 software.
USB Drivers to be installed and Program Burner with Willar Programmer installed.
Objectives:
1. Understand the architecture, features, and pin configuration of the 8051
microcontrollers.
2. Learn to use Keil μVision-5 IDE for writing, compiling, and debugging programs.
3. Write and simulate simple programs in embedded C or assembly for 8051.
4. Familiarize with the process of generating a .HEX file for hardware interfacing.
5. Build a foundation for interfacing peripherals and embedded system applications.
Circuit Diagram:
The microcontroller is a Dual Inline Package (DIP) integrated circuit and to has a total of 40
pins. It has a total of four input/output ports and each port has 8 pins. So, among the 40 pins,
for ports cover the total of 32 pins other pins are used for other functions such as interrupt,
power supply, oscillation, etc.

5
Special Function Register:
A special function register (SFR) is a memory area in a microcontroller that controls or
monitors the microcontroller's functions. SFRs are used to:
• Control timers, counters, serial I/Os, and port I/Os
• Monitor the processor status, such as if it is servicing an interrupt or running in
protected mode
• Monitor condition codes, which are the result of previous comparisons
• Control the stack pointer, which indicates the next data to be accessed

6
Port1 (Pin1 to Pin8): Port1 includes pin1.0 to pin1.7 and these pins can be configured as
input or output pins.
Pin 9 (RST): Reset pin is used to Reset 8051 Microcontroller by giving a positive pulse to
this Pin.
7
Port3 (Pin 10 to 17): The Port3 Pins are like port1 pins and can be used as universal Input
or output pins. These pins dual-function Pins and the function of each Pin is given as:
Pin 10 (RXD): RXD pin is a Serial Asynchronous Communication Input or Serial
synchronous Communication Output.
Pin 11 (TXD): Serial Asynchronous Communication Output or Serial Synchronous
Communication Clock Output.
Pin 12 (INT0): Input of Interrupt 0
Pin 13 (INT1): Input of Interrupt 1
Pin 14 (T0): Input of Counter 0 clock
Pin 15 (T1): Input of Counter 1 clock
Pin 16 (WR): Writing Signal to write content on external RAM.
Pin 17 (RD): Reading Signal to read contents of external RAM.
Pin 18 and 19 (XTAL2, XTAL1): X2 and X1 pins are input output pins for the oscillator.
These pins are used to connect an internal oscillator to the microcontroller.
Pin 20 (GND): Pin 20 is a ground pin.
Port2 (Pin 21 to Pin28): Port2 includes pin21 to pin28 which can be configured as Input
Output Pins. But this is only possible when we don’t use any external memory. If we use
external memory, then these pins will work as high order address bus (A8 to A15).
Pin 29 (PSEN): This pin is used to enable external program memory. If we use an external
ROM for storing the program, then logic 0 appears on it, which indicates Micro controller to
read data from the memory.
Pin 30 (ALE): Address Latch Enable pin is an active high-output signal. If we use multiple
memory chips, then this pin is used to distinguish between them. This Pin also gives program
pulse input during programming of EPROM.
Pin 31 (EA): If we have to use multiple memories then the application of logic 1 to this pin
instructs the Microcontroller to read data from both memories: first internal and then external.
Port 0 (Pin 32 to 39): Similar to the port 2 and 3 pins, these pins can be used as input output
pins when we don’t use any external memory. When ALE or Pin 30 is at 1, then this port is
used as data bus: when the ALE pin is at 0, then this port is used as a lower order address bus
(A0 to A7)
Pin40 (VCC): This VCC pin is used for power supply.

8
Types of instructions:
Depending on operation they perform, all instructions are divided in several groups:
➢ Arithmetic Instructions
➢ Branch Instructions
➢ Data Transfer Instructions
➢ Logic Instructions
➢ Bit-oriented Instructions
Arithmetic instructions:
Arithmetic instructions perform several basic operations such as addition, subtraction, division,
multiplication etc. After execution, the result is stored in the first operand. For example:
ADD A, R1 - The result of addition (A+R1) will be stored in the accumulator

. Mnemonic Description
ADD A,Rn Adds the register to the accumulator
ADD A,direct Adds the direct byte to the accumulator
ADD A,@Ri Adds the indirect RAM to the
accumulator
ADD A,#data Adds the immediate data to the
accumulator
ADDC A,Rn Adds the register to the accumulator with
a carry flag
ADDC A,direct Adds the direct byte to the accumulator
with a carry flag
ADDC A,@Ri Adds the indirect RAM to the
accumulator with a carry flag

ADDC A,#data Adds the immediate data to the


accumulator with a carry flag
SUBB A,Rn Subtracts the register from the
accumulator with a borrow
SUBB A,direct Subtracts the direct byte from the
accumulator with a borrow
SUBB A,@Ri Subtracts the indirect RAM from the
accumulator with a borrow
SUBB A,#data Subtracts the immediate data from the
accumulator with a borrow
INC A Increments the accumulator by 1
INC Rn Increments the register by 1
INC Rx Increments the direct byte by 1
INC @Ri Increments the indirect RAM by 1
DEC A Decrements the accumulator by 1
DEC Rn Decrements the register by 1
DEC Rx Decrements the direct byte by 1
DEC @Ri Decrements the indirect RAM by 1
INC DPTR Increments the Data Pointer by 1
MUL AB Multiplies A and B
DIV AB Divides A by B
DA A Decimal adjustment of the accumulator
according to BCD code

9
Branch Instructions:
There are two kinds of branch instructions:
Unconditional jump instructions: upon their execution a jump to a new location from
where the program continues execution is executed.
Conditional jump instructions: a jump to a new program location is executed only if a
specified condition is met. Otherwise, the program normally proceeds with the next
instruction.
Mnemonic Description
ACALL addr11 Absolute subroutine call
LCALL addr16 Long subroutine call
RET Returns from subroutine
RETI Returns from interrupt subroutine
AJMP addr11 Absolute jump
LJMP addr16 Long jump
SJMP rel Short jump (from –128 to +127 locations relative to the
following instruction)
JC rel Jump if carry flag is set. Short jump.
JNC rel Jump if carry flag is not set. Short jump.
JB bit,rel Jump if direct bit is set. Short jump.
JBC bit,rel Jump if direct bit is set and clears bit. Short jump.
JMP @A+DPTR Jump indirect relative to the DPTR
JZ rel Jump if the accumulator is zero. Short jump.
JNZ rel Jump if the accumulator is not zero. Short jump.
CJNE A,direct,rel Compares direct byte to the accumulator and jumps if not
equal. Short jump.
CJNE A,#data,rel Compares immediate data to the accumulator and jumps
if not equal. Short jump.
CJNE Rn,#data,rel Compares immediate data to the register and jumps if not

equal. Short jump.


CJNE @Ri,#data,rel Compares immediate data to indirect register and jumps
if not equal. Short jump.
DJNZ Rn,rel Decrements register and jumps if not 0. Short jump.
DJNZ Rx,rel Decrements direct byte and jump if not 0. Short jump.
NOP No operation

Data Transfer Instructions:

Data transfer instructions move the content of one register to another. The register the content of
which is moved remains unchanged. If they have the suffix “X” (MOVX), the data is exchanged with
external memory.

Mnemonic Description

MOV A,Rn Moves the register to the accumulator

MOV A,direct Moves the direct byte to the accumulator

MOV A,@Ri Moves the indirect RAM to the accumulator

10
MOV A,#data Moves the immediate data to the accumulator

MOV Rn,A Moves the accumulator to the register

MOV Rn,direct Moves the direct byte to the register

MOV Rn,#data Moves the immediate data to the register

MOV direct,A Moves the accumulator to the direct byte

MOV direct,Rn Moves the register to the direct byte

MOV direct,direct Moves the direct byte to the direct byte

MOV direct,@Ri Moves the indirect RAM to the direct byte

MOV direct,#data Moves the immediate data to the direct byte

MOV @Ri,A Moves the accumulator to the indirect RAM

MOV @Ri,direct Moves the direct byte to the indirect RAM

MOV @Ri,#data Moves the immediate data to the indirect RAM

MOV DPTR,#data Moves a 16-bit data to the data pointer

MOVC Moves the code byte relative to the DPTR to the


A,@A+DPTR accumulator (address=A+DPTR)

MOVC A,@A+PC Moves the code byte relative to the PC to the accumulator
(address=A+PC)

MOVX A,@Ri Moves the external RAM (8-bit address) to the accumulator

MOVX A,@DPTR Moves the external RAM (16-bit address) to the


accumulator
MOVX @Ri,A Moves the accumulator to the external RAM (8-bit address)

MOVX @DPTR,A Moves the accumulator to the external RAM (16-bit address)

PUSH direct Pushes the direct byte onto the stack

POP direct Pops the direct byte from the stack/td>

XCH A,Rn Exchanges the register with the accumulator

XCH A,direct Exchanges the direct byte with the accumulator

11
XCH A,@Ri Exchanges the indirect RAM with the accumulator

XCHD A,@Ri Exchanges the low-order nibble indirect RAM with the
accumulator

Logic Instructions:

Logic instructions perform logic operations upon corresponding bits of two registers. After execution,
the result is stored in the first operand.

Mnemonic Description

ANL A,Rn AND register to accumulator

ANL A,direct AND direct byte to accumulator

ANL A,@Ri AND indirect RAM to accumulator

ANL A,#data AND immediate data to accumulator

ANL direct,A AND accumulator to direct byte

ANL direct,#data AND immediate data to direct register

ORL A,Rn OR register to accumulator

ORL A,direct OR direct byte to accumulator

ORL A,@Ri OR indirect RAM to accumulator

ORL direct,A OR accumulator to direct byte

ORL direct,#data OR immediate data to direct byte

XRL A,Rn Exclusive OR register to accumulator

XRL A,direct Exclusive OR direct byte to accumulator

XRL A,@Ri Exclusive OR indirect RAM to accumulator

XRL A,#data Exclusive OR immediate data to


accumulator
XRL direct,A Exclusive OR accumulator to direct byte
XORL direct,#data Exclusive OR immediate data to direct byte

CLR A Clears the accumulator

CPL A Complements the accumulator (1=0, 0=1)

12
SWAP A Swaps nibbles within the accumulator

RL A Rotates bits in the accumulator left

RLC A Rotates bits in the accumulator left


through carry
RR A Rotates bits in the accumulator right

RRC A Rotates bits in the accumulator right


through carry

Bit-oriented Instructions
Similar to logic instructions, bit-oriented instructions perform logic operations. The difference is that
these are performed upon single bits.

Mnemonic Description

CLR C Clears the carry flag

CLR bit Clears the direct bit

SETB C Sets the carry flag

SETB bit Sets the direct bit

CPL C Complements the carry flag

CPL bit Complements the direct bit

ANL C,bit AND direct bit to the carry flag

ANL C,/bit AND complements of direct bit to the carry


flag

ORL C,bit OR direct bit to the carry flag

ORL C,/bit OR complements of direct bit to the carry flag

MOV C,bit Moves the direct bit to the carry flag

MOV bit,C Moves the carry flag to the direct bit

Description of all 8051 instructions:

Here is a list of the operands and their meanings:

• A - accumulator; Rn - is one of working registers (R0-R7) in the currently active


RAM memory bank;
13
• Direct - is any 8-bit address register of RAM. It can be any general-purpose register
or a SFR (I/O port, control register etc.);
• @Ri - is indirect internal or external RAM location addressed by register R0 or R1;
• #data - is an 8-bit constant included in instruction (0-255);
• #data16 - is a 16-bit constant included as bytes 2 and 3 in instruction (0-65535);
• addr16 - is a 16-bit address. May be anywhere within 64KB of program memory;
• addr11 - is an 11-bit address. May be within the same 2KB page of program memory as
the first byte of the following instruction;
• Rel - is the address of a close memory location (from -128 to +127 relative to the first byte
of the following instruction). On the basis of it, assembler computes the value to add or
subtract from the number currently stored in the program counter;
• bit - is any bit-addressable I/O pin, control or status bit; and
• C - is carry flag of the status register (register PSW).
8051 Addressing modes:

The way of specifying the address of the operand is called as addressing mode. The 8051
microcontroller is having four addressing modes for accessing data.

1. Immediate Addressing mode


2. Register Addressing mode
3. Direct Addressing mode
4. Indirect Addressing mode
5. Indexed Addressing mode

1. Immediate addressing mode:


The operand comes immediately after the op-code. The immediate data must be preceded by the hash
sign, "#".
MOV A, #25H ;load 25H into A
MOV R4, #62 ;load the decimal value 62 into R4
MOV B, #40H ;load 40H into B
MOV DPTR, #4512H ; DPTR=4512H

14
2. Register Addressing mode:
Register addressing mode involves the use of registers to hold the data to be manipulated. In
this addressing mode register which is having the data is part of the instruction.
MOV A, R0 ;copy the contents of RO into A
MOV R2,A
; copy the contents of A into R2
ADD A, R5
ADD A, R7 ; add the contents of R5 to contents
MOV R6, A of A

3. Direct Addressing mode:


In the direct addressing mode, the data is in a RAM memory location whose address is
known, and this address is given as a part of the instruction.

MOV R0,40H ; save content of RAM location 40H in RO


MOV 56H, A ; save content of A in RAM location 56H
MOV R4,7FH
4. Indirect Addressing mode:
A register is used as a pointer to the data. If the data is inside the CPU, only registers R0
and R 1 are used for this purpose. R2 - R7 cannot be used to hold the address of an
operand located in RAM when using indirect addressing mode. When RO and R1 are
used as pointers they must be preceded by the @ sign.

MOV A, @R0 ; move contents of RAM location whose ;address is held by RO


MOV @R1, B into A

5. Indexed Addressing mode


Indexed addressing mode is widely used in accessing data elements of look-up table
entries located in the program ROM space of the 8051.
The instruction used for this purpose is :
MOVC A, @ A+DPTR
The 16-bit register DPTR and register A are used to form the address of the data
element stored in on-chip ROM.
Because the data elements are stored in the program (code) space ROM of the 8051,
the instruction MOVC is used instead of MOV. The "C" means code.
In this instruction the contents of A are added to the 16-bit register DPTR to form the
16bit address of the needed data.

Applications
• Home appliances (e.g., washing machines).
• Robotics and automation.

15 | P a g e
• Automotive systems.
• Industrial control systems.

Keil – 5 Software:

How to Download the software: Search / Browse the link : https://www.keil.com/

Go to the Download Option click on C51 Software:

16 | P a g e
Next step is to run setup file C51V954A.EXE and then we’ll get pop-up box, hit on Next and Proceed
Installation.

Read license agreement, check I agree to all the terms…., and click Next

Select Destination folder where you want to install Keil, or default destination is already there. And
hit on Next. Wait for installation completes and hit on Next. Tick on show release notes, deselect
remaining (as per your choice) and click on Finish.

Download is free for evaluation version.


1. Find Keil Setup 8051.

2. Download Setup Keil 8051.

3. Proceed Installation Keil 8051.

4. Accept Terms and Conditions.

5. Choose Installation Directory.

6. Proceed with Registered Credentials.

7. Wait until Installation finishes.

8. Click Finish and Installation Done.

17 | P a g e
The Arm® Keil Microcontroller Tools include C/C++ compilers, integrated
development environments, RTOS, middleware, as well as debug adapters and
evaluation boards for Arm Cortex®-M based devices
Embedded C is the most popular programming language in the software field for
developing electronic gadgets.
Features of Keil uvision-5:
Cross-platform compiler:
Supports multiple microcontroller architectures, mainly focusing on ARM Cortex-
M series, allowing you to develop code for various devices using the same IDE
Integrated development environment (IDE):
Provides a user-friendly interface with code editor, project management tools, build
system, and debugger all within one window
Real-time operating system (RTOS):
Keil RTX, a lightweight RTOS, can be integrated into projects for managing real-
time tasks with deterministic behavior.
Advanced debugging:
Includes features like real-time variable monitoring, breakpoint setting, single-step
execution, and hardware breakpoint support for in-depth code analysis
How to Execute Assembly Language Programs in Keil Micro-vision?
Keil Microvision software is an open-source software, or an IDE used for executing assembly
language programs and embedded C programs. Let’s see the steps to execute the assembly
language program in Keil Microvision software.
Executing assembly language programs in Keil Microvision Software
Follow the following steps to execute assembly language programs in Keil Microvision software:

18 | P a g e
Step 1: Open Keil Microvision software then click on the project then click on the new
Microvision project.

Step 2: Save your file with .asm extension for example (addition of numbers.asm) and save it.

Step 3: Select microchip AT89S52 and click on ok.

19 | P a g e
Step 4: Now click on target 1 and then double click on source group 1, select the file
that you saved previously with extension .asm add it to the source group, and close
it.

Step 5: Now click on the + sign shown before source group 1, then double click on
the file that comes after clicking on +sign. Then write assembly language code in
the plane text area that appears.

20 | P a g e
Step 6: Click on build and rebuild to check errors then click on debug and start
debug session.

Step 7: Then click on run you can run directly, or you can run step by step by clicking
every time on the step or pressing F11 and then check the output here the output is
visible in blue color.
By following the above-mentioned steps, you can execute any type of assembly language
statements or instructions and assembler directives in Keil Microvision software.

Assignment Evaluation

0: Not Done [ ] 1: Incomplete [ ] 2:Late Complete [ ]

3: Needs Improvement [ ] 4: Complete [ ] 5: Well Done [ ]

Signature of Instructor

21 | P a g e
Assignment No. 3
Program to find Largest/smallest from a series.
Aim: To write an assembly language program for the 8051 microcontroller to find the
largest and smallest numbers from a given series of data.

Objectives:
1. Learn to handle arrays in assembly language.
2. Implement comparison logic to find the largest or smallest number.
3. Use 8051 registers (Accumulator and general-purpose registers).
4. Practice 8051 assembly syntax and instructions.
5. Test and verify the program through simulation.

Requirements: Keil uvision-5 software


Block Diagram:
Internal RAM organization of 8051 Microcontroller.

22 | P a g e
Algorithm:
1. Load the 56H location with 00H which is considered as the largest number
2. Initialize a counter based on no. of numbers given
3. Move the first number into the accumulator
4. Compare the content of accumulator with 00H in 56H
5. If there is no carry, which means (A) is the largest so, move the content of accumulator to the
56H
6. If there is a carry leave the content of accumulator as it is.
7. Repeat the loop until all the numbers are compared and the counter value becomes zero
8. The largest number will be in the 56H location.
Code 1: To find out the Largest Number from the given Array: -

Output:
Check the Output in Register Window in Keil Vision-5.

23 | P a g e
Code 2: To find the smallest number of the given set of numbers:
Algorithm:
1. Load the 70H location with 0FFH which is considered as the smallest no. initially
2. Initialize a counter based on no. of numbers given
3. Move the first number into the accumulator
4. Compare the content of accumulator with 0FFH in 2H
5. If there is carry, which means (A) is the smallest so, move the content of accumulator to the 70H
6. If there is no carry leave the content of accumulator as it is.
7. Repeat the loop until all the numbers are compared and the counter value becomes zero
8. The smallest number will be in the 2H location.

Program:

24 | P a g e
OUTPUT:

25 | P a g e
Assignment No. 4
Program to Perform Addition, Subtraction, Multiplication, and
Division of 8/16-Bit Data

Aim: To perform arithmetic, logical, and code conversion operations using the 8051
microcontroller in Assembly language and simulate the program in Keil μVision.

Objectives
1. To implement basic arithmetic and logical operations.
2. To perform code conversions (binary, BCD, hexadecimal).
3. To write and simulate programs in Keil μVision.

Requirements: Keil uvision-5 software


Block Diagram:

Register Banks and Stack Memory Allocation in 8051 Microcontroller

26 | P a g e
Program to perform Addition / subtraction / /multiplication/division
of 8/16 bit data
1. ADDITION OF TWO 8-BIT NUMBERS
AIM: To Perform addition of two 8-bit numbers with 8051 microcontroller and Keil uvision
Software
Experiment Required: Keil uvision Software
ALGORITHM:
1. Load two RAM locations with two operands
2. Move the 1st operand to the accumulator
3. Add the accumulator content with the next location
4. Check the carry flag
5. If the carry is set indicate it by moving 1 in a location
6. Move the result to a RAM location

Program:

27 | P a g e
Output:

2. SUBTRACTION OF TWO 8-BIT NUMBERS

ALGORITHM:
1. Load the two 8-bit operands into the locations 40H and 41H
2. Load the larger into the accumulator
3. Subtract the content of accumulator with the smaller number in 40H location.
4. Store the result in 60H location
5. To subtract from smaller to larger number, load the smaller number into the accumulator
6. Subtract the larger number from the smaller number.
7. Now doing this carry flag will set so take the 2’s complement of the result
8. Store the result in 62H location
9. Load the R0 with 1 to indicate negative sign

28 | P a g e
Program:

Output:

29 | P a g e
3. MULTIPLICATION OF TWO 8-BIT NUMBERS
ALGORITHM:
1. Load the accumulator with an immediate data
2. Load ‘B’ register with an immediate data
3. Multiply (A)*(B) using “MUL AB “instruction
4. The lower byte is in accumulator
5. The higher byte is in the ‘B’ register
6. Move the result to the appropriate location.

Program:

Output:

30 | P a g e
4. DIVISION OF TWO 8-BIT NUMBERS
Algorithm:
1. Get the Dividend in the accumulator
2. Get the Divisor in the Register B
3. Divide A by B
4. Store the Quotient and Remainder in the memory.
Program:

OUTPUT:

31 | P a g e
Assignment 5
Aim: Program to perform Arithmetic, logical & code conversion problems

Aim
To perform arithmetic, logical, and code conversion operations using the 8051 microcontroller
in Assembly language and simulate the program in Keil μVision.
Objectives
1. To implement basic arithmetic and logical operations.
2. To perform code conversions (binary, BCD, hexadecimal).
3. To write and simulate programs in Keil μVision.
Experiment Required: Keil µvision software
Block Diagram:

32 | P a g e
1. Addition:
Algorithm:
1. Load the value 10H (16 in decimal) into register A.
2. Load the value 08H (8 in decimal) into register B.
3. Add the values in registers A and B using the ADD instruction.
4. The result of the addition is stored in register A.
5. Move the result from register A into register R1.
6. End the Program:

2. Subtraction:

Alogirithm :

1. Load the value 10H (16 in decimal) into register R1.


2. Load the value 08H (8 in decimal) into register R2.
3. Move Value from R1 to Accumulator:
4. Move the value of R1 (which is 10H) into the accumulator A.
Subtraction Step:
5. Subtract the value in R2 (which is 08H) from the accumulator A using the SUBB
instruction.
6. The result of the subtraction is stored in A.
7. Store the Result:
8. Move the result from the accumulator A into register R4.

33 | P a g e
3. Division:
Algorithm:
1. Load the value 25H (37 in decimal) into the accumulator A.
2. Load the value 10H (16 in decimal) into register B.
3. Use the DIV AB instruction, which divides the value in register A (dividend)
by the value in register B (divisor).
4. The quotient will be stored in register A.
5. The remainder will be stored in register B.
6. Move the quotient (stored in A) to register R3.
7. Store the Remainder:
8. Move the remainder (stored in B) to register R4.
Program:

34 | P a g e
4. Multiplication:
Algorithm:
1. Load the value 25H (37 in decimal) into the accumulator A.
2. Load the value 25H (37 in decimal) into register B.
3. Use the MUL AB instruction, which multiplies the value in register A by the
value in register B.
4. The lower byte of the result will be stored in register A.
5. The higher byte of the result will be stored in register B.
6. Move the lower byte of the result (stored in register A) to register R3.
7. Move the higher byte of the result (stored in register B) to register R4.
Program:

35 | P a g e
5. Write a Program to Convert Hexadecimal number into Decimal Number

Algorithm:

1. Set B to 16 (the divisor, since we are converting from decimal to


hexadecimal).
2. Start a loop that will repeatedly divide the decimal number by 16.
3. Use the DIV AB instruction to divide the value in A (decimal number)
by 16.
4. The quotient will be stored back in A, and the remainder (which is the
hexadecimal digit) will be stored in B.
5. Move the value in register B (the remainder, which is the hexadecimal
digit) to the memory location pointed to by R0.
6. Increment R0 to point to the next memory location for the next
hexadecimal digit.
7. Check the quotient in A. If it is 0, the conversion is complete.
8. If the quotient is not 0, repeat the loop by jumping back to the division
step.
9. End

• Program to write Hexadecimal to Decimal

36 | P a g e
6. Write a Program to Convert Decimal number into Hexadecimal Number
Algorithm:
• Program to write Decimal to Hexadecimal.

1. Loads the decimal number 205 into the accumulator register A.


2. Sets the divisor 16 for converting the decimal number to hexadecimal.
3. Divides A by B. The quotient is stored in A, and the remainder (hex digit) is stored
in B.
3. Saves the remainder (which is a hexadecimal digit) into R1.
4. Updates the quotient for further divisions.
5. The loop continues until the quotient (A) becomes zero.
6. A placeholder for extending the program with further functionality, such as
outputting the result.
Program:

37 | P a g e
Assignment 6
Program to perform data transfer/exchange between specified
memory’s locations.
Aim: To implement data transfer and exchange between specified memory locations using the
8051 microcontroller in Assembly language and simulate the program in Keil μVision.

Objectives
1. To learn data transfer techniques between different memory locations in the 8051.
2. To write Assembly programs for memory data exchange.
3. To simulate and debug the program using Keil μVision.
1) To perform the exchange of the given data starting from the locations 30H
to 39H to 40H to 49H.
EQUIPMENT REQUIRED: Keil µvision software
BLOCK DIAGRAM:

38 | P a g e
39 | P a g e
ALGORITHM:
1. Load R0 with 30H to acts as source pointer
2. Load R1 with 40H to act as a destination pointer
3. Initialize the counter with by moving the appropriate value into register (R2 =10)
4. Load the accumulator with the content pointed by R0
5. Exchange the content of accumulator to the destination location pointed by R1
6. Move the content of accumulator into the location pointed by R0.
7. Repeat the loop until the counter value becomes zero.
Program:

OUTPUT:

40 | P a g e
2) To perform the block transfer of the given data starting from the locations 30H to
39H to 40H to 49H.
ALGORITHM:
1. Load R0 with 30H to acts as source pointer
2. Load R1 with 40H to act as a destination pointer
3. Load the accumulator with the content pointed by R0
4. Move the content of accumulator to the destination location pointed by R1
5. Repeat the loop until the counter value becomes zero.

Program:

41 | P a g e
Assignment 7
Aim: To interface LEDs with the 8051 microcontroller and control on-off action of an
using Embedded C programming .

Objectives
1. To write a simple program in Embedded C to turn an LED on and off using
the 8051 microcontroller.
2. To control the LED through a microcontroller's I/O port.
3. To demonstrate basic digital output control with the 8051.
4. To test the functionality using simulation software (Keil μVision) and physical
hardware (circuit board).

EQUIPMENT REQUIRED: Keil µvision software, 8051 development board, Universal


programmer, Willar Software (To Copy Hex file to the 8051 microcontroller), 1- LED
Circuit Diagram:

42 | P a g e
Algorithm:
Step 1: Initialize the Microcontroller
1. Start the program.
2. Define an LED output pin (e.g., P1.0).
3. Set the LED pin as an output.
Step 2: Enter an Infinite Loop for Blinking
4. Enter an infinite loop (while (1)).
Step 3: Toggle LED State with a Delay
5. Turn ON the LED (set P1.0 = 1).
6. Call a delay function (to keep LED ON for some time).
7. Turn OFF the LED (set P1.0 = 0).
8. Call the delay function again (to keep LED OFF for some time).
Step 4: Repeat the Process
9. Go back to Step 5 and repeat the process indefinitely.
Program: Program in Embedded C
1. Blinking a Single LED

43 | P a g e
1. Blinking Multiple LEDs

#include <reg51.h> // Header file for 8051 microcontroller

void delay_ms(unsigned int ms) {


unsigned int i, j;
for (i = 0; i < ms; i++) {
for (j = 0; j < 1275; j++); // Approximate delay for 1 ms
}
}
void main() {
unsigned char LED_pattern = 0x01; // Initial LED pattern
while (1) {
P1 = ~LED_pattern; // Send pattern to Port 1 (active-
low) delay_ms(500); // Delay of 500 ms
LED_pattern = LED_pattern << 1; // Shift the LED pattern to the
left if (LED_pattern == 0x00) { // Reset the pattern after 8
shifts
LED_pattern = 0x01;
}
}
}

In 8051, 1 machine cycle requires 12 crystal pulses to execute and we have use 11.0592Mhz
crystal.
So, time required for 1 machine cycle: 12/11.0592 = 1.085us
So, 1275*1.085=1.3ms, 1275 times of “for” loop gives nearly 1ms of delay.
The exact time delay produce by “C” program is very difficult to compute, when measuring from
oscilloscope (CRO), for (j=0; j<1275; j++) give delay of nearly 1ms.

44 | P a g e
Assignment No. 8
Interfacing of Switch & LED to 8051 Microcontroller

Aim: Interfacing of switch & LED to 8051 microcontrollers.


Objective
To interface a switch and an LED with the 8051 microcontroller and control the LED
based on the switch's state using Embedded C.

EQUIPMENT REQUIRED: Keil µvision software, 8051 development board, Universal


programmer, Willar Software (To Copy Hex file to the 8051 microcontroller), 1- LED, 1 – Push
Button

Circuit Diagram:

Push button interfaced with microcontroller

45 | P a g e
Circuit Diagram:

Algorithm:
• Start
• Initialize Ports:

• Configure P1.0 (Push button) as input.


• Configure P1.1 (LED) as output.

• Enter Infinite Loop:

• Continuously check the button status.

• Check Button Status:

• If the button (P1.0) is pressed (button == 1):


o Turn ON the LED (P1.1 = 1).
• Else:

46 | P a g e
o Turn OFF the LED (P1.1 = 0).

• Repeat the process indefinitely


• End

Program:

Interfacing Switch (Push Button)


A simple switch has an open state and closed state. However, a microcontroller needs to see a
definite high or low voltage level at a digital input. A switch requires a pull-up or pull-down
resistor to produce a definite high or low voltage when it is open or closed. A resistor placed
between a digital input and the supply voltage is called a “pull-up” resistor because it normally
pulls the pin’s voltage up to the supply.
We now want to control the LED by using switches in 8051 Development board. It works by
turning ON a LED & then turning it OFF when switch is going to LOW or HIGH.
How led is interfaced with microcontroller?
One end (cathode or anode) of led is connected to microcontroller pin and the other with power
rail. In the below picture led cathode is connected to microcontroller directly and anode is
connected to +5 volts source in series with a resistor. Resistor is used to limit the current. How the
below circuit works.
• When microcontroller pin is made low (from code). Microcontroller pin becomes ground
and current start flowing from 5-volt source to ground making led to switch on.

47 | P a g e
• When microcontroller pin is made high (in code). Microcontroller pin becomes high and
current will find no way to flow and led switches off.

You can also change the polarity of the circuit by connecting led anode to microcontroller and
cathode to external ground. In that configuration microcontroller will supply current to glow led.
Which is not good. There is a very big chance of microcontroller to reset due to power shortage.
Hence the below led microcontroller configuration is recommended to utilize in circuits involving
led and microcontroller. In below configuration external source will supply current to led.

How is Push button interfaced with microcontroller?


Same as led, push button is interfaced with microcontroller. One leg of button is connected to
microcontroller and other to power source. Now
• When button is open (not pressed) ground will appear on microcontroller pin. There is no
path for 5 volts to circulate.
• When button is pressed current starts flowing through the circuit and 5 volts will appear on
the microcontroller pin.

48 | P a g e
Assignment No. 9
Waveform generation using DAC Interface to 8051 Microcontroller.
Aim: Waveform Generation Using DAC Interface to 8051 Microcontroller
Objective To generate analog waveforms (e.g., sine wave, triangular wave, square wave) using
the 8051 microcontroller and a Digital-to-Analog Converter (DAC).
Theory
1. Digital-to-Analog Converter (DAC): o Converts digital signals from the microcontroller into
analog signals. o Common DACs, like the DAC0808, accept an 8-bit digital input and provide an
equivalent analog output.
2. Waveform Generation:
o Square Wave: Alternating between high and low digital values at regular intervals.
o Triangular Wave: Gradually increasing and decreasing digital values to form a triangular shape.
o Sine Wave: Approximated by sending precomputed sine values from a lookup table to the DAC.
2. 8051-DAC Interface: o DAC data pins are connected to an 8-bit port

Digital-to-analog conversion can degrade a signal, so conversion details are normally chosen so
that the errors are negligible.
Due to cost and the need for matched components DACs are almost exclusively manufactured on
integrated circuits (ICs).
The suitability of a particular DAC for an application is determined by a variety of measurements
including speed and resolution.
Microcontroller are used in wide variety of applications like for measuring and control of physical
quantity like temperature, pressure, speed, distance, etc.
In these systems microcontroller generates output which is in digital form, but the controlling
system requires analog signal as they don't accept digital data thus making it necessary to use DAC
which converts digital data into equivalent analog voltage.

49 | P a g e
Circuit Diagram – IC – 0808 (DAC)

❑ For generating sinewave, at first, we need a look-up table to represent the


magnitude of the sine value of angles between 0° to 360°.

50 | P a g e
❑ In this example we will consider 30° increments and calculate the values from
degree to DAC input. We are assuming full-scale voltage of 10V for DAC output.
We can follow this formula to get the voltage ranges.

For Sinusoidal waveform


Algorithm:
• Start
• Include the required header file (reg51.h) to support 8051 microcontroller-specific
functions.
• Define the Special Function Register (sfr) DAC at address 0x80.
• Define the main function void main().
• Declare and initialize an array sin_value[12] with 12 integer values representing a sine
wave pattern.
• Declare an integer variable i to be used as a loop counter.
• Enter an infinite loop using while(1) to continuously output the sine wave values.
• Iterate through the sin_value array using a for loop:

• Set i = 0 and increment i until it reaches 12.


• Assign sin_value[i] to DAC (Digital-to-Analog Converter output).

• Repeat the loop infinitely to continuously generate the sine wave pattern.
• End.

51 | P a g e
Program:

Waveform:

For Triangular Waveform:


Algorithm:
• Start
• Include the required header file (reg51.h) to support 8051 microcontroller-specific
functions.
• Define the main function void main().
• Declare an integer variable j for loop iteration.
• Enter an infinite loop using while(1) to continuously generate a waveform pattern.
• Execute the first for loop:

• Initialize j = 0.
• Increment j until it reaches 255.

52 | P a g e
• Assign j to P0, sending an increasing pattern to Port 0.

• Execute the second for loop:

• Initialize j = 255.
• Decrement j by 2 in each iteration until j > 0.
• Assign j to P0, sending a decreasing pattern to Port 0.

• Repeat the process infinitely to generate a triangular waveform on P0.


• End.

Program:

53 | P a g e
Triangular waveform:

For Square waveform Generation:


Algorithm:
• Start
• Include the required header file (reg51.h) to support 8051 microcontroller-specific
functions.
• Define the main function void main().
• Declare an unsigned integer variable i for the delay loop.
• Initialize Port 3 (P3) to 0x00, setting all bits to 0.
• Enter an infinite loop using while(1), ensuring continuous execution.
• Toggle all bits of P3 by assigning P3 = ~P3.
• Create a delay using an empty for loop:

• Initialize i = 0.
• Increment i until it reaches 100.
• This loop acts as a simple time delay.

• Repeat the process infinitely to keep toggling P3 at regular intervals.


• End.
Program:

54 | P a g e
Square Waveform:

For Sawtooth Waveform:


Algorithm:
• Start
• Include the required header file (reg51.h) to support 8051 microcontroller-specific
functions.
• Define the main function void main().
• Declare an integer variable j for loop iteration.
• Enter an infinite loop using while(1) to ensure continuous execution.
• Execute a for loop to increment j from 0 to 255:

• Assign j to P1 (Port 1 of the 8051 microcontroller).

• Repeat the process infinitely to generate a continuously increasing pattern on P1.


• End.

55 | P a g e
Program:

Sawtooth Waveform:

56 | P a g e
Assignment No. 10
Interfacing LCD to 8051 Microcontroller
Objective:
To interface a 16x2 LCD with the 8051 microcontroller in 8-bit mode and display a message.

LCD 16 X 2 Display:

57 | P a g e
To initialize LCD to the 8051 the following instruction and commands are
to be embed in to the functions
• 0x38 is used for 8-bit data initialization.
• 0xoC for making LCD display on and cursor off.
• 0X01 for clearing the display of the LCD.
• 0x80 for positioning the cursor at first line .
Sending Commands to the LCD
• E=1; enable pin should be high
• RS=0; Register select should be low for sending commands
• Placing the data on the data registers
• R/W=0; Read/Write pin should be low for writing the data.
Writing the Data to the LCD
• E=1; enable pin should be high
• RS=1; Register select should be high for writing data
• Placing the data on the data registers
• R/W=0; Read/Write pin should be low for writing the data.

58 | P a g e
LCD HEX Commands :
There are some preset command instructions in LCD, we have used them in our
program below to prepare the LCD (in lcd_init() function). Some important
command instructions are given below:

59 | P a g e
Circuit Diagram :

Algorithm:
1. Start
2. Include the header file reg51.h.
3. Define display_port as P2 for LCD data pins.
4. Define control pins (RS, RW, E) connected to P3.2, P3.3, and P3.4.
5. Create a function msdelay(time) to generate a time delay.
6. Create a function lcd_cmd(command) to send commands to the LCD.
7. Create a function lcd_data(disp_data) to send data to the LCD.
8. Create a function lcd_init() to initialize the LCD with required settings:
9. Use lcd_cmd() to set LCD mode, turn display ON, clear screen, and set cursor
position.
10. Define main () function:
11. Declare a string a[] = "FYBCA_Practical".
12. Call lcd_init() to initialize the LCD.

60 | P a g e
13. Use a while loop to send each character of the string to the LCD until the null
terminator (\0) is encountered.
14. Add a small delay after displaying each character.
15. End.

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 instr to LCD
{
display_port = command;
rs= 0;
rw=0;
e=1;
msdelay(1);
e=0;
}
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;
}

61 | P a g e
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]="FYBCA_Practical"; //string of 14 characters with a null
terminator.
int l=0;
lcd_init();
while(a[l] != '\0') // searching the null terminator in the sentence
{
lcd_data(a[l]);
l++;
msdelay(50);
}}

62 | P a g e
Assignment: 11
Stepper motor interfacing to 8051 microcontrollers.

Objective
To interface a Stepper Motor with the 8051 microcontroller and control its rotation direction
(clockwise and counterclockwise) and steps.

Stepper Motor:
A stepper motor works on the principle of magnetic attraction and repulsion. The coils of stators
are placed on electromagnets which are energized and de-energized by the pulses of the
microcontroller which creates magnetic north and south on the stator poles.

Some parameters of stepper motors:


• Step Angle − The step angle is the angle in which the rotor moves when one pulse is applied
as an input of the stator. This parameter is used to determine the positioning of a stepper
motor.
• Steps per Revolution − This is the number of step angles required for a complete
revolution. So, the formula is 360° /Step Angle.
• Steps per Second − This parameter is used to measure several steps covered in each
second.
• RPM − The RPM is the Revolution Per Minute. It measures the frequency of rotation. By
this parameter, we can measure the number of rotations in one minute.
Stepper motor is brushless DC motor, which can be rotated in small angles, these angles are called
steps.
Generally, stepper motor use 200 steps to complete 360-degree rotation, means its rotate 1.8 degree
per step.
Stepper motor used in many devices which needs precise rotational movement like robots,
antennas, hard drives etc. We can rotate stepper motor to any particular angle by giving it proper
instructions.

Interfacing stepper motor to 8051 Microcontroller


1. Wave Drive Mode
2. Full Drive Mode
3. Half Drive Mode

1. Wave drive mode


In this mode only one coil is energized at a time, all the four coils are energized
one after the other in a sequence. In terms of power consumption, this mode is a
power saver, but the torque produced is less compared to the full drive mode.

63 | P a g e
Steps A B C D HEX

1 1 0 0 0 0x08

2 0 1 0 0 0x04

3 0 0 1 0 0x02

4 0 0 0 1 0x01

2. Full Drive mode


In this mode two coils are energized at a time, i.e. Logic 1 is given to 2 coils at the same time,
this results in higher torque, but the power consumption also increases and precision of the
stepper motor increases two folds.

Steps A B C D HEX

1 1 1 0 0 0x0C

2 0 1 1 0 0x06

3 0 0 1 1 0x03

4 1 0 0 1 0x09

3.Half Drive Mode


This mode works on the alternate energizing principle, i.e. at one moment only 1 coil is
energized, but in the very next moment 2 coils are energized, then again back to 1. This sequence
is repeated to make the motor more power-efficient while maintaining the high torque and
increase the angular rotation of the motor.

64 | P a g e
Steps A B C D HEX
1 1 0 0 0 0x08
2 1 1 0 0 0x0C
3 0 1 0 0 0x04
4 0 1 1 0 0x06
5 0 0 1 0 0x02
6 0 0 1 1 0x03
7 0 0 0 1 0x01

IC L293D:

65 | P a g e
Circuit Diagram:

Algorithm:
1. Start
2. Include the header file reg52.h.
3. Define motor phase values (phase_a, phase_b, phase_c, phase_d) corresponding to
P2.
4. Define EN (Enable pin) at P0.0 as active high.
5. Create a delay(cnt) function to introduce a small delay.
6. Create a clockwise() function to drive the stepper motor in a clockwise direction:
7. Set P2 to phase_a, delay.
8. Set P2 to phase_b, delay.
9. Set P2 to phase_c, delay.
10. Set P2 to phase_d, delay.
11. Define main() function:
12. Set EN = 1 to enable the motor.
13. Use an infinite while(1) loop to continuously call clockwise() function.
14. End.

66 | P a g e
Program:
Write a Program for Anticlockwise direction:

#include<reg52.h>

#define phase_a 0x0a //P2.0 = a


#define phase_b 0x06 //P2.1 = b
#define phase_c 0x05 //P2.2 = c
#define phase_d 0x09 //P2.3 = d

sbit EN=P0^0;//active high

void delay(int cnt);


void delay(int cnt)
{
int i,j;
for(i=0;i<cnt;i++)
for(j=0;j<100;j++);
}

void clockwise(void);

void clockwise(void)
{
P2=phase_a;
delay(100);

P2=phase_b;
delay(100);

P2=phase_c;
delay(100);

P2=phase_d;
delay(100);
}
void main(void)
{
EN=1;
while(1)
{
clockwise();
}
}

67 | P a g e
Write a Program for clockwise direction:
#include<reg52.h>
#define phase_d 0x09
#define phase_c 0x05
#define phase_b 0x06
#define phase_a 0x0a
sbit EN=P0^0;
void delay(int cnt);
void delay(int cnt)
{
int i,j;
for(i=0;i<cnt;i++)
for(j=0;j<00;j++);
}
void clockwise(void);
void clockwise(void)
{
P2=phase_d;
delay(100);
P2=phase_c;
delay(100);
P2=phase_b;
delay(100);
P2=phase_a ;
delay(100);
}
void main(void)

68 | P a g e
{
EN=1;
while(1)
{
clockwise();
}
}

69 | P a g e

You might also like