0% found this document useful (0 votes)
15 views13 pages

Embedded Lab

The document outlines four experiments using the 8051 microcontroller, focusing on arithmetic operations, waveform generation, and controlling a 7-segment display. Each experiment includes a theoretical background, code implementation, and practical applications, demonstrating the microcontroller's capabilities in various embedded systems. The experiments cover addition operations, square and triangular waveform generation, and displaying digits on a 7-segment display.

Uploaded by

gopalsharma98011
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)
15 views13 pages

Embedded Lab

The document outlines four experiments using the 8051 microcontroller, focusing on arithmetic operations, waveform generation, and controlling a 7-segment display. Each experiment includes a theoretical background, code implementation, and practical applications, demonstrating the microcontroller's capabilities in various embedded systems. The experiments cover addition operations, square and triangular waveform generation, and displaying digits on a 7-segment display.

Uploaded by

gopalsharma98011
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/ 13

Experiment 1: Addition Operation using 8051 Microcontroller

Introduction

The 8051 microcontroller is a widely used embedded system for automation, control systems,
and data processing. One of the fundamental operations in any computing system is arithmetic
computation, particularly addition. In this experiment, we perform an addition operation using
Assembly language for an 8051 microcontroller. The objective is to load the accumulator with a
value, add another value to it, and store the result in a register. This experiment provides insight
into how arithmetic operations are handled at the hardware level.

Theory

The 8051 microcontroller consists of an 8-bit accumulator (A), general-purpose registers


(R0-R7), and an Arithmetic Logic Unit (ALU). The ALU performs arithmetic and logical
operations, including addition. The addition operation in an 8051 microcontroller follows these
principles:

●​ Immediate Addressing Mode: The operand is directly provided in the instruction.


●​ Register Operations: The accumulator (A) is primarily used for arithmetic operations.
●​ Status Flags: The Carry (CY) and Auxiliary Carry (AC) flags in the Program Status Word
(PSW) are updated based on the result of addition.

Code Implementation
ORG 0000H ; Set program start at memory address 0000H

MOV A, #05H ; Load the accumulator (A) with 5H

ADD A, #05H ; Add another 5H to the accumulator

MOV R0, A ; Store the result in register R0

SJMP $ ; Infinite loop to stop execution

END

Code Explanation

1.​ MOV A, #05H - Loads the accumulator with 5H (decimal 5).


2.​ ADD A, #05H - Adds 5H to the accumulator’s existing value (5H + 5H = 0AH).
3.​ MOV R0, A - Stores the computed sum (0AH) into register R0.
4.​ SJMP $ - Creates an infinite loop to halt execution, ensuring the program does not
proceed further.

Observations

●​ The accumulator initially holds 05H (5 in decimal).


●​ After the addition operation, the accumulator holds 0AH (10 in decimal).
●​ The value 0AH is stored in R0, confirming successful execution.

Output

●​ The final value stored in R0 is 0AH (decimal 10).


●​ The Carry (CY) flag remains unset (0) because there was no overflow beyond 8 bits.
●​ The Auxiliary Carry (AC) flag remains unset (0) since no carry occurred from bit 3 to bit 4.

Real-World Applications

●​ Embedded Calculators: Microcontrollers perform basic arithmetic in low-power


handheld devices.
●​ Data Processing in IoT Devices: Sensor data aggregation often requires simple
arithmetic before transmission.
●​ Automated Control Systems: Industrial automation relies on embedded arithmetic for
process calculations.
Conclusion

The addition program was successfully executed on the 8051 microcontroller. The experiment
demonstrated the use of immediate addressing mode for arithmetic operations and how the
accumulator and general-purpose registers store computed results. Understanding this
operation is essential for developing more complex embedded applications that involve
arithmetic processing.
Experiment 2: Square Waveform Generation using 8051
Microcontroller

Introduction

Waveform generation is a crucial aspect of embedded systems, used in applications such as


signal processing, pulse-width modulation (PWM), and clock signal generation. In this
experiment, we generate a square waveform using the 8051 microcontroller by toggling an
output pin at regular intervals. The generated waveform alternates between high and low states
with a fixed delay, demonstrating how microcontrollers can control signal patterns.

Theory

A square waveform is a periodic signal that transitions between two discrete voltage levels,
typically high (logic 1) and low (logic 0). The 8051 microcontroller achieves this by controlling
the state of an output port (P1) in a loop with a programmed delay. The fundamental concepts
include:

●​ GPIO Control: General-purpose I/O ports (P1) are used to send output signals.
●​ Timing Delay: Delays are introduced using a simple loop to maintain a stable waveform
period.
●​ Continuous Execution: The waveform is generated indefinitely by looping the toggling
process.

Code Implementation
CLR P0.7 ; Clear P0.7 to start with LOW state
START: MOV A, #2CH
MOV P1, A ; Set P1 to 2CH (LOW state)
CALL DLY ; Call delay subroutine
MOV A, #05AH
MOV P1, A ; Set P1 to 5AH (HIGH state)
CALL DLY ; Call delay subroutine
JMP START ; Repeat the cycle indefinitely

DLY: MOV R1, #01FH


LOOP1: DJNZ R1, LOOP1
RET

Code Explanation

1.​ CLR P0.7 - Clears pin P0.7, initializing the waveform at a low state.
2.​ MOV P1, A - Assigns values to port P1 to generate alternating high and low states.
3.​ CALL DLY - Calls the delay subroutine to maintain waveform timing.
4.​ JMP START - Creates an infinite loop for continuous waveform generation.

Observations

●​ The waveform toggles between 0x2C (low) and 0x5A (high) at a fixed interval.
●​ The delay subroutine ensures a stable square wave cycle.
●​ The cycle repeats indefinitely as programmed.

Output

●​ A square waveform is observed on P1, switching between high and low states.
●​ The waveform's frequency can be adjusted by modifying the delay loop.

Real-World Applications

●​ Clock Signals: Used in timing circuits and synchronization.


●​ PWM Control: Applied in motor speed control and LED dimming.
●​ Digital Communication: Square waves are fundamental in digital signal transmission.
Conclusion

The experiment successfully demonstrated square waveform generation using the 8051
microcontroller. By toggling an output pin at regular intervals, the microcontroller produces a
stable periodic signal. This knowledge is essential for developing embedded applications that
require precise timing and signal control
Experiment 3: Triangular Waveform Generation using 8051
Microcontroller
Introduction

Waveform generation is a crucial aspect of embedded systems, used in signal processing,


audio synthesis, and test equipment. In this experiment, we generate a triangular waveform
using an 8051 microcontroller and its Digital-to-Analog Converter (DAC). The DAC converts
digital values into corresponding analog voltages, forming a linearly increasing and
decreasing wave.

Theory

A triangular waveform is characterized by a linear rise and fall of voltage over time, unlike
square waves which have abrupt transitions. The 8051 microcontroller lacks an inbuilt DAC but
can generate an analog output using a resistor ladder network (R-2R DAC) or by interfacing
with an external DAC (e.g., DAC0808).

The waveform is generated by:

1.​ Incrementing a digital value from 0x00 to 0xFF, creating the rising edge.
2.​ Decrementing the value back to 0x00, forming the falling edge.
3.​ Repeating the cycle continuously to create the triangular shape.

Circuit Components

●​ 8051 Microcontroller (AT89C51)

Code:

CLR P0.7
MOV A, #00H
LOOP:
MOV P1, A
ADD A, #3
CJNE A, #0FFH, LOOP
LOOP1:
MOV P1, A
SUBB A, #3

CJNE A, #00H, LOOP1

JMP LOOP
Code Explanation

1.​ Incrementing Phase:


○​ Start at 0x00, continuously increase the value up to 0xFF.
2.​ Decrementing Phase:
○​ Once at 0xFF, continuously decrease back to 0x00.
3.​ DAC Output:
○​ P1 sends values to the DAC, which converts them to an analog voltage.
4.​ Delay Control:
○​ The delay loop controls frequency—adjusting R6 and R7 changes the speed of
transitions.

Observations

●​ The waveform gradually rises and falls between 0V and max DAC output voltage.
●​ The smoothness of the waveform depends on the delay loop.
●​ On an oscilloscope, the output looks like a triangular signal with equal rise and fall
time.
Real-World Applications

Signal Generators – Used in function generators for testing circuits.​


Audio Synthesis – Triangle waves are used in synthesizers and sound effects.​
Motor Control – Smooth PWM signals for AC motor speed control.​
Analog Simulation – Useful in emulating natural analog signals in control systems.

Conclusion

This experiment successfully generated a triangular waveform using an 8051 microcontroller


and a DAC. The code efficiently cycles through increment and decrement operations to achieve
the desired shape. Understanding this technique is essential for advanced signal processing,
PWM control, and waveform synthesis applications.
Experiment 4: 7-Segment Display Using 8051 Microcontroller

Introduction
A 7-segment display is an electronic display device used to show decimal numbers, making it
widely used in digital clocks, counters, and embedded systems. It consists of seven LED
segments (labeled a to g) arranged in the shape of the number 8. By selectively illuminating
these segments, different digits from 0 to 9 can be displayed.

In this experiment, we use the 8051 microcontroller to control a common cathode 7-segment
display, cycling through digits 0 to 9 in sequence. The display is interfaced with Port 1 of the
microcontroller, and predefined hexadecimal values are used to turn on the correct segments for
each digit.

Theory
A 7-segment display can be categorized into two types:

1.​ Common Cathode (CC) – The negative terminal (cathode) of all LEDs is connected to
GND, and individual segments are turned ON by applying HIGH (1) voltage.
2.​ Common Anode (CA) – The positive terminal (anode) of all LEDs is connected to VCC,
and individual segments are turned ON by applying LOW (0) voltage.

In this experiment, we use a Common Cathode display. The 8051 microcontroller sends
predefined hex values to Port 1 (P1), corresponding to each digit's segment configuration. A
delay function is used to ensure each digit remains visible before switching to the next.

Working Principle
1.​ Segment Activation:
○​ Each digit (0-9) is represented by a unique 8-bit pattern (hex value), which
determines which segments light up.
○​ The microcontroller outputs these patterns to Port 1, where the display is
connected.
2.​ Digit Display:
○​ The program sequentially loads hex values into P1 to display digits from 0 to 9.
○​ A delay is inserted after each digit to make it visible for a short duration.
3.​ Continuous Loop:
○​ The cycle repeats indefinitely, displaying digits 0-9 in a loop.
CODE:

ORG 0000H
SETB P0.7
SETB P3.3
CLR P3.4
MOV P1, #0C0H
ACALL DELAY
MOV P1, #0F9H
ACALL DELAY
MOV P1, #0A4H
ACALL DELAY
MOV P1, #0B0H
ACALL DELAY
MOV P1, #099H
ACALL DELAY
MOV P1, #092H
ACALL DELAY
MOV P1, #082H
ACALL DELAY
MOV P1, #0F8H
ACALL DELAY
MOV P1, #080H
ACALL DELAY
MOV P1, #098H
ACALL DELAY
SJMP $

DELAY:
MOV R0, #255
MOV R1, #255
RET

Code Explanation
1.​ Initializing Control Pins:
○​ SETB P0.7 – Sets Port 0.7 to HIGH.
○​ SETB P3.3 – Enables the display control pin.
○​ CLR P3.4 – Clears another control pin to configure the display.
2.​ Sending Digits to Display:
○​ MOV P1, #0C0H – Sends 0 to the display.
○​ MOV P1, #0F9H – Sends 1 to the display.
○​ MOV P1, #0A4H – Sends 2, and so on until 9.
○​ After each command, a delay is inserted before moving to the next digit.
3.​ Delay Subroutine:
○​ Introduces a small pause to allow each digit to be visible before switching
to the next.
○​ This creates a smooth transition between digits.
4.​ Infinite Loop:
○​ SJMP $ keeps the program running continuously.

Observations
●​ The 7-segment display successfully cycles through digits 0 to 9.
●​ Each digit remains visible for a short duration before switching to the next.
●​ The displayed numbers appear clear and stable due to the added delay.

Real-World Applications
Digital Counters – Used in frequency counters, timers, and event counters.​
Clocks & Timers – Found in digital clocks and countdown timers.​
Microwave Ovens & Appliances – Numeric displays in consumer electronics.​
Elevators & Scoreboards – Indicating floors and scores in real-time.
Conclusion
This experiment successfully demonstrated how to control a 7-segment display using an 8051
microcontroller. By sending predefined hex values to Port 1, we were able to display numbers
from 0 to 9 sequentially. This fundamental concept is widely applicable in various digital display
systems, laying the foundation for more advanced embedded system applications.

You might also like