Embedded Lab
Embedded Lab
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
Code Implementation
ORG 0000H ; Set program start at memory address 0000H
END
Code Explanation
Observations
Output
Real-World Applications
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
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
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
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
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).
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
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
JMP LOOP
Code Explanation
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
Conclusion
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.