0% found this document useful (0 votes)
7 views22 pages

ESD File

The document outlines experiments involving the 8051 microcontroller, including traffic light control, DC motor interfacing, stepper motor control, and matrix keypad interfacing. Each experiment includes a theoretical background, source code, and hardware connection details. The experiments demonstrate various applications of the microcontroller in controlling different types of motors and input devices.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views22 pages

ESD File

The document outlines experiments involving the 8051 microcontroller, including traffic light control, DC motor interfacing, stepper motor control, and matrix keypad interfacing. Each experiment includes a theoretical background, source code, and hardware connection details. The experiments demonstrate various applications of the microcontroller in controlling different types of motors and input devices.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Experiment: 6

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

• Red LED → P1.0

• Yellow LED → P1.1

• Green LED → P1.2

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:

ORG 0000H ; Program starts at address 0 START:

; RED ON, others OFF

SETB P1.0 ; Turn on

Red CLR P1.1 ; Yellow

OFF CLR P1.2 ; Green

OFF

ACALL DELAY ; ~1 second delay

; GREEN ON, others OFF

CLR P1.0 ; Red OFF

CLR P1.1 ; Yellow

OFF SETB P1.2 ;

Green ON

ACALL DELAY ; ~1 second delay


; YELLOW ON, others

OFF CLR P1.0 ; Red

OFF SETB P1.1 ;

Yellow ON CLR P1.2 ;

Green OFF

ACALL DELAY ; ~1 second delay

SJMP START ; Repeat forever

; ===== Delay Subroutine =====

; Simple ~1 second delay

DELAY: MOV R2,

#250

D1: MOV R1, #255

D2: DJNZ R1, D2

DJNZ R2, D1

RET

END

• SETB Px.y: Sets pin HIGH (LED ON if active-high).


• CLR Px.y: Sets pin LOW (LED OFF).
• SJMP START: Infinite loop to repeat the sequence.
• DELAY: Roughly 1-second delay (depends on crystal clock).

OBSERVATION:
CONNECTIONS:

For each LED:

• Connect the anode (longer pin) of the LED to:

o P1.0 for Red, o

P1.1 for Yellow,

o P1.2 for Green.

• Connect a resistor (e.g., 330Ω) to the cathode (shorter pin) of each LED.

• Connect the other end of the resistor to

GND. The resistor limits current and protects the

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

It cannot supply the required current (~250–600 mA),

• It only provides logic-level voltage (0 or 5V).

This is where the L293D motor driver IC comes into

play. The L293D is a dual H-Bridge driver IC that

allows:

• Bidirectional control of two DC motors.

• Handling up to 600 mA per channel.

• Logical control of direction and speed using input pins.

L293D Pin Configuration (1 Motor):


Pin Description

IN1 Control Input 1

IN2 Control Input 2

OUT1
Output to Motor terminal 1

OUT2
Output to Motor terminal 2

EN1 Enable (must be HIGH to run)

VCC1
Logic power (usually 5V)

VCC2
Motor supply (typically 9–12V)

GNDCommon Ground

Control 1 DC Motor using Port 2:


8051 Pin L293D Pin
Description
P2.0 IN1 Motor direction control

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

1 1 Motor Off (Brake)

SORCE CODE:

ORG 0000H

MOV P2, #00000101B ; IN1=1, IN2=0, EN=1 ? Forward

ACALL DELAY

MOV P2, #00000011B ; IN1=0, IN2=1, EN=1 ?

Reverse ACALL DELAY

MOV P2, #00000000B ; Motor Off

SJMP $

DELAY: MOV

R2, #255

HERE1: MOV R1, #255

HERE2: DJNZ R1, HERE2

DJNZ R2, HERE1

RET

END
WORKING:

1. The 8051 sends logic signals to the L293D.

2. L293D boosts the current and drives the motor terminals (OUT1/OUT2).

3. Enable pin must be HIGH for the motor to operate.

4. The direction of current determines rotation direction.

OBSERVATION:

CONNECTION:

• Connect the crystal between XTAL1 and XTAL2 of 8051.

• Connect two 22pF capacitors from each crystal pin to GND.

• Connect 10kΩ resistor between RST pin and VCC.

• Connect push-button between RST and GND. • L293D and


Motor Connections:

• P2.0 (8051) → IN1 (L293D)

• P2.1 (8051) → IN2 (L293D)

• P2.2 (8051) → EN1 (L293D)

• OUT1 and OUT2 → DC Motor terminals

• VCC1 (L293D) → 5V (logic)


• VCC2 (L293D) → 9V battery (motor power)

• GND (L293D) → Common Ground with 8051

Be sure VCC1 and VCC2 are not swapped.

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

2. The speed of rotation is controlled by the rate of pulses.

3. The direction of rotation depends on the sequence of pulses applied.


The 8051 Microcontroller cannot supply enough current to drive a stepper motor directly.
The ULN2003 is a Darlington transistor array used to amplify current and drive the coils of
the motor.

• It acts as an interface between 8051 and the motor.


• You connect the ULN2003 inputs to 8051 output pins and its outputs to the
motor coils.

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:

• You energize coils inside the motor in a specific sequence.

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

1 09H 1001 A and D ON

2 0CH 1100 B and A ON

3 06H 0110 B and C ON

4 03H 0011 C and D ON

SOURCE CODE:

ORG 0000H

MOV A, #04H ; Set number of steps =

4 MOV R3, A ; Store step count in R3

CW_LOOP:

MOV A, #09H ; Step 1 (1001)

ACALL OUTPORT ; Output to P1

ACALL DELAY ; Wait

MOV A, #0CH ; Step 2

(1100) ACALL OUTPORT

ACALL DELAY

MOV A, #06H ; Step 3

(0110) ACALL OUTPORT

ACALL DELAY

MOV A, #03H ; Step 4

(0011) ACALL OUTPORT

ACALL DELAY
DJNZ R3, CW_LOOP ; Repeat 4 times

MOV A, #04H

MOV R3, A ; Set step count for

ACW ACW_LOOP:

MOV A, #03H ; Step 1

(0011) ACALL OUTPORT

ACALL DELAY

MOV A, #06H ; Step 2

(0110) ACALL OUTPORT

ACALL DELAY

MOV A, #0CH ; Step 3

(1100) ACALL OUTPORT

ACALL DELAY

MOV A, #09H ; Step 4 (1001)

ACALL OUTPORT

ACALL DELAY

DJNZ R3, ACW_LOOP OUTPORT:

MOV P1, A ; Send step signal to P1 (connected to

ULN2003) RET

DELAY: MOV

R1, #0FFH

D1: MOV R2, #0FFH

D2: DJNZ R2, D2


DJNZ R1, D1

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

P1.1 IN2 Coil B


P1.2 IN3 Coil C

P1.3 IN4 Coil D

• ULN2003 to Stepper Motor


ULN2003 OUTx Stepper Motor
Pin Coil
OUT1 Coil A

OUT2 Coil B

OUT3 Coil C

OUT4 Coil D

• ULN2003 Pin 9 (COM): Connect to motor VCC (for flyback diodes).


• ULN2003 Pin 8 (GND): Connect to Ground.
• Motor Power Supply: Use separate 12V or 5V supply (as needed by motor).
• 8051 Power: 5V from regulated supply or USB programmer.
Experiment: 9
Aim: Write a program to interface a matrix keyboard microcontroller 8051.
Theory:
A matrix keypad is a collection of push-button switches arranged in a grid (matrix) of rows
and columns (e.g., 4x4 or 4x3).
Instead of connecting each key separately, rows and columns reduce the number of
microcontroller I/O pins needed.

For a 4x4 keypad, there are:

• 4 Rows → Connected to P1.0-P1.3

• 4 Columns → Connected to P1.4-P1.7


• Output (Pressed Key Code) shown on → Port 2 (P2) (e.g., via LEDs or
logic analyzer)
Pin Type Role Direction

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

1. Set All Columns HIGH.

2. Pull One Column LOW at a time (others HIGH).

3. Read All Rows:


o If a key is pressed in that column, the row line connected to the key will
become LOW.

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

; Column 2 LOW (P1.5 = 0), others HIGH


MOV A, #0DFH
ACALL CHECK_ROW

; Column 3 LOW (P1.6 = 0), others HIGH


MOV A, #0BFH
ACALL CHECK_ROW
SJMP SCAN ; Keep scanning

; Subroutine to check rows


CHECK_ROW:
MOV P1, A ; Apply column
pattern MOV R0, A ; Save
column pattern MOV A, P1
ANL A, #0F0H ; Mask out column bits (ensure upper 4 bits are unaffected)
MOV A, P1
ANL A, #0F0H
CJNE A, #0F0H, KEY_PRESSED
RET

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

ANL A, #0F0H ; Adjust nibble


ORL A, R0 ; Combine row and column to form unique pattern
MOV P2, A ; Show key code on P2 (e.g., LEDs)
ACALL DELAY

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:

1. Keypad to Port 1 (P1)

Assuming your keypad has 4 rows and 3 columns (7 pins total):

• Connect Rows to: o R1 → P1.0 o R2


→ P1.1 o R3 → P1.2
o R4 → P1.3
• Connect Columns to: o C1 → P1.4 o C2

→ P1.5 o C3 → P1.6

2. LEDs to Port 2 (P2)


• Connect 8 LEDs (with 330Ω resistors)
to P2.0 to P2.7 P2.0 → Resistor →
LED → GND
• Repeat for P2.1 to P2.7 This way,
each key press will show a unique 8-
bit pattern on the LEDs.
Experiment: 10
Aim: To interface with seven segment and display alphanumeric values.
Theory:
A Seven Segment Display (SSD) is an output device that shows numbers (0–9) and some
letters (A–F) using 7 LEDs arranged like this:

Types of SSD

1. Common Cathode (CC) o All cathodes (negative terminals) are connected

together to GND.

o Send HIGH (1) to a pin to turn ON a segment.

2. Common Anode (CA)

o All anodes (positive terminals) are connected to VCC.

o Send LOW (0) to turn ON a segment.

Each digit/letter is shown by turning ON certain segments.


Character Segments ON
Binary Pattern Hex

0 abcdef 00111111 0x3F

1 bc 00000110 0x06

2 abdeg 01011011 0x5B

A abcefg 01110111 0x77


B cdefg 01111100 0x7C

C adef 00111001 0x39

D bcdeg 01011110 0x5E

E adefg 01111001 0x79

F aefg 01110001 0x71

Patterns are stored in a Lookup Table for easy access.

SOURCE CODE:

ORG 0000H

MOV DPTR, #TABLE ; Point to the lookup table

MOV R0, #16 ; 16 characters to display

MOV R1, #00H ; Index register

LOOP:

MOV A, R1

MOVC A, @A+DPTR ; Get segment

pattern MOV P2, A ; Output to 7-segment

ACALL DELAY ; Wait

INC R1

DJNZ R0, LOOP ; Display all 16 values

SJMP LOOP ; Repeat forever

; Lookup table: 0–9 and A–F for Common Cathode 7-segment

TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH ; 0–9

DB 77H,7CH,39H,5EH,79H,71H ; A–F

; Simple delay routine

DELAY: MOV

R2, #255

D1: MOV R3, #255


D2: DJNZ R3, D2

DJNZ R2, D1

RET

END

WORKING:

• DPTR is a 16-bit data pointer.


• It is set to point to the start of the TABLE, which contains the segment patterns for
0– F.
• R0 is the loop counter: 16 iterations for 0–F.
• R1 is the index into the Lookup Table, starting at 0.
• MOV A, R1: Copy index into Accumulator.
• MOVC A, @A+DPTR: Use DPTR + A as address to get a pattern from the
lookup table.
• MOV P2, A: Send the segment pattern to Port 2, which drives the 7-segment display.
• After each character is displayed, there's a small delay.
• INC R1: Move to the next character.
• DJNZ R0, LOOP: Decrease R0 and loop if not zero (runs 16 times). • SJMP
LOOP: Restart the whole display forever.

OBSERVATION:
CONNECTION:

1. Connect Microcontroller to Display

Assuming you're using Port 2 (P2.0 – P2.6) for segments a–g:


SSD Segment Pin Name Connect to Microcontroller

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

dp (optional) DP P2.7 or leave unconnected

COM Common cathode GND

Add resistors (220Ω) between each segment pin and P2.0–P2.6 (optional in simulation).

2. Clock and Reset Circuit

• Crystal Oscillator (11.0592 MHz) between XTAL1 and XTAL2


• Two 22pF capacitors from XTAL1/XTAL2 to GND

• Connect Pin 31 (EA) to VCC

• Connect Pin 9 (RST) to:

o 10kΩ resistor → GND o


Push Button → VCC This
acts as a manual RESET

3. Segment Placement

• Place 7SEG-CC

• Rotate and place it near Port 2 (P2.0 to P2.6)

• Connect Common Cathode pins (COM1, COM2) of the display to GND

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