ESD File
ESD File
Aim: To write a program for a Traffic Light Control System using 8051 Microcontroller in
assembly language and simulate it on Proteus (SDL format).
Theory:
Traffic lights operate in a sequence: Red → Green → Yellow → Red.
Hardware Interface
Each LED is controlled via a microcontroller pin. Delay routines control how long each light
stays ON.
The 8051 microcontroller outputs high or low signals to turn LEDs ON or OFF. In this
experiment, we interface three LEDs (Red, Yellow, Green) with Port 1 (P1.0 to P1.2) of the
8051. The program turns them ON/OFF in sequence with delays to simulate traffic signals.
SOURCE CODE:
OFF
Green ON
Green OFF
#250
DJNZ R2, D1
RET
END
OBSERVATION:
CONNECTIONS:
• Connect a resistor (e.g., 330Ω) to the cathode (shorter pin) of each LED.
LED.
Experiment: 7
Aim: Write a program to interface DC Motor with 8051 Microcontroller.
Theory:
A DC motor converts electrical energy into mechanical motion. In embedded systems,
controlling the speed and direction of a DC motor is a common task, often required in
robotics and automation projects.
However, a microcontroller like the 8051 cannot directly drive a DC motor because: •
allows:
OUT1
Output to Motor terminal 1
OUT2
Output to Motor terminal 2
VCC1
Logic power (usually 5V)
VCC2
Motor supply (typically 9–12V)
GNDCommon Ground
Motor
P2.1 Behaviour:
IN2 Motor direction control
IN1 IN2 Output (Motor Rotation)
P2.2 EN1 Enable pin
1 0 Forward (Clockwise)
0 1 Reverse (Anti-Clockwise)
0 0 Motor Off
SORCE CODE:
ORG 0000H
ACALL DELAY
SJMP $
DELAY: MOV
R2, #255
RET
END
WORKING:
2. L293D boosts the current and drives the motor terminals (OUT1/OUT2).
OBSERVATION:
CONNECTION:
:
Experiment: 8
Aim: To interface with stepper motor and rotate clockwise & anticlockwise.
Theory:
A stepper motor is an electromechanical device that converts a series of electrical pulses
into precise mechanical movement. Unlike DC motors, stepper motors move in fixed angular
increments, called steps, which makes them ideal for applications requiring accurate
positioning like printers, CNC machines, and robotics.
1. Each pulse rotates the motor shaft by a fixed angle (e.g., 1.8° per step).
For a 4-phase unipolar stepper motor, coils are energized in a specific order to rotate:
Clockwise Sequence:
Anti-Clockwise Sequence:
A stepper motor moves in small steps—each step turns the shaft by a small angle (like 1.8°).
To make it move:
• That’s what these values like 09H, 0CH, 06H, and 03H
do: they turn ON/OFF different coils.
Step Hex Binary Coils (P1.3–P1.0)
SOURCE CODE:
ORG 0000H
CW_LOOP:
ACALL DELAY
ACALL DELAY
ACALL DELAY
DJNZ R3, CW_LOOP ; Repeat 4 times
MOV A, #04H
ACW ACW_LOOP:
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL OUTPORT
ACALL DELAY
ULN2003) RET
DELAY: MOV
R1, #0FFH
RET
END
EXPLANATION:
• This code rotates a 4-step stepper motor: 4 steps clockwise, then 4 steps anticlockwise
Each step is given a short delay to make the rotation visible and functional.
• Setting value of R3 executes 4 steps in Clockwise direction.
• The pattern 09H → 0CH → 06H → 03H is standard for 4-step clockwise control.
• OUTPORT sends the value to Port 1 (connected to motor through ULN2003).
• DELAY slows the signal so the motor visibly turns.
• DJNZ reduces R3 by 1 and loops until it's 0.
• Repeats the opposite pattern for anticlockwise direction. Sequence: 03H → 06H → 0CH →
09H
• DELAY: Provides a delay loop to make the step visible.
Loops through registers R1 and R2 to waste time (simple software delay).
OBSERVATION:
CONNECTION:
• 8051 to ULN2003
8051 Port ULN2003 INx Description
Pin Pin
P1.0 IN1 Coil A
OUT2 Coil B
OUT3 Coil C
OUT4 Coil D
Row pins (R1–R4) Input pins The microcontroller reads these (checks if any key is
pressed)
Column pins (C1– Output The microcontroller sets these HIGH or LOW to scan
C4) pins the keypad
o This tells us the row and column → thus which key was pressed.
Example: If C2 is LOW and R3 is read LOW, then the key at Row 3, Column 2 was pressed.
SOURCE CODE:
ORG 0000H ; Start of code
MAIN:
MOV P1, #0FFH ; Set all P1 pins high (input pull-up)
MOV P2, #00H ; Clear Port 2 for output
SCAN:
; Column 1 LOW (P1.4 = 0), others HIGH
MOV A, #0EFH
ACALL CHECK_ROW
KEY_PRESSED:
MOV A, P1
CPL A ; Invert to get active-low logic (0 = pressed ? 1)
ANL A, #0F0H ; Mask only row bits
SWAP A
WAIT_RELEASE:
MOV A, P1
ANL A, #0F0H
CJNE A, #0F0H, WAIT_RELEASE
RET
; Delay subroutine
DELAY: MOV
R2, #200
D1: MOV R1, #255
D2: DJNZ R1, D2
DJNZ R2, D1
RET
END
WORKING:
• P1 is connected to the keypad.
• P2 is used to show output (e.g., on 8 LEDs).
• SCAN: Each line sends a different column LOW.
After each, it calls CHECK_ROW to see if any key in that column is
pressed.
• CHECK-ROW: Applies column pattern to P1.
• Reads the value of P1 again to check if any row line (P1.0–P1.3) has gone
LOW.
If yes (i.e., key is pressed), it jumps to KEY_PRESSED.
• KEY_PRESSED: Determines which row is pressed.
• Combines it with the current column value to get a unique binary
code per key.
• Displays it on P2 — could be used for LEDs or further processing.
• WAIT_RELEASE: Loops here until all rows are HIGH (i.e., no key
is pressed).
Prevents key bouncing or double counting.
• DELAY: Provides a basic delay by
looping. Used to hold the key output
briefly on P2.
OBSERVATION:
CONNECTION:
→ P1.5 o C3 → P1.6
Types of SSD
together to GND.
1 bc 00000110 0x06
SOURCE CODE:
ORG 0000H
LOOP:
MOV A, R1
INC R1
DB 77H,7CH,39H,5EH,79H,71H ; A–F
DELAY: MOV
R2, #255
DJNZ R2, D1
RET
END
WORKING:
OBSERVATION:
CONNECTION:
a A P2.0
b B P2.1
c C P2.2
d D P2.3
e E P2.4
f F P2.5
g G P2.6
Add resistors (220Ω) between each segment pin and P2.0–P2.6 (optional in simulation).
3. Segment Placement
• Place 7SEG-CC