100% found this document useful (1 vote)
152 views32 pages

8051 Interfacing

The document discusses various external devices that can be interfaced with an 8051 microcontroller, including: - 8255 PPI for extending I/O capabilities - LEDs, 7-segment displays, LCDs, keyboard matrices, stepper motors, DC motors for input/output applications - ADCs and DACs for converting analog signals to digital and vice versa It provides details on interfacing and programming each device, with examples for flashing LEDs, displaying numbers on a 7-segment display, and controlling motors based on switch inputs. Interfacing techniques like multiplexing are discussed for devices with many I/O pins like keyboards.

Uploaded by

Srikar Namburu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
152 views32 pages

8051 Interfacing

The document discusses various external devices that can be interfaced with an 8051 microcontroller, including: - 8255 PPI for extending I/O capabilities - LEDs, 7-segment displays, LCDs, keyboard matrices, stepper motors, DC motors for input/output applications - ADCs and DACs for converting analog signals to digital and vice versa It provides details on interfacing and programming each device, with examples for flashing LEDs, displaying numbers on a 7-segment display, and controlling motors based on switch inputs. Interfacing techniques like multiplexing are discussed for devices with many I/O pins like keyboards.

Uploaded by

Srikar Namburu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

8051 Interfacing with

External Devices

Contents

8255 - PPI

LED

7-segment display

LCD

Keyboard matrix

Stepper motor

DC motor

ADC

DAC

Microcontroller lab, Dept. of E&C.

Programmable Peripheral
Interface(PPI)
Programmable Peripheral Interface
(PPI) devices are used for
extending the I/O capabilities of processors/controllers.
8255A is a popular PPI device for 8 bit processors/controllers.
8255A supports 24 I/O pins and these I/O pins can be grouped as either
three 8-bit parallel ports (Port A, Port B and Port C) or two 8 bit parallel
ports (Port A and Port B) with Port C in any one of the following
configuration.
As 8 individual I/O pins.
Two 4bit Ports namely Port CUPPER (CU) and Port CLOWER (CL).
The Configuration of ports is done through the Control Register of
8255A.

Microcontroller lab, Dept. of E&C.

Programmable Peripheral
Interface(PPI)

Microcontroller lab, Dept. of E&C.

Programmable Peripheral
Interface(PPI)

For example, write the CW to program port C PC.5 of 8255 as input pin.

8255 should be in BSR mode.


0 XXX 101 1 = 0Bh or 7Bh.

Write CW to program port A & B as input ports in mode 0 and port C as


output port.

8255 should be in IO mode.


1 00 1 0 0 1 0 = 92h

Microcontroller lab, Dept. of E&C.

LED

Light Emitting Diode (LED) is an output device for visual indication in


any mechatronics system.

LED can be used as an indicator for the status of various signals or


situations. Typical examples are indicating the presence of power
conditions like Device ON, Battery low or Charging of battery etc.

LED is a p-n junction diode and it contains a anode and a cathode. For
functioning of the LED, the anode of it should be connected to +ve
terminal of the supply voltage and cathode to the ve terminal of supply
voltage.

The current flowing through the LED must be limited to a value below
the maximum current that it can conduct. A resister is used in series
between the power supply and the resistor to limit the current through
the LED.

Microcontroller lab, Dept. of E&C.

LED

LEDs can be interfaced to the port pin of a processor/ controller in 2


ways.

In first case anode of LED is connected directly to the port pin.


Whenever the port pin is in logic high state, LED glows.

In the second case cathode of LED is connected to port pin and anode to
power supply. Whenever port pin is in low state, LED glows.

In first case brightness will not be as per the requirement. But in second
case brightness can be obtained as per the requirement.

Microcontroller lab, Dept. of E&C.

Write a program to flash the LEDs connected to port1 of 8051 MC.


ORG 8000h
rpt: MOV A,#0FFH
MOV P1,A
ACALL DELAY
MOV A,#00H
MOV P1,A
ACALL DELAY
SJMP rpt.
DELAY : MOV R0,#0FFH
L1:DJNZ R0,L1
RET
END
Microcontroller lab, Dept. of E&C.

7-Segment LED Display

The 7 segment LED display is an output device for displaying alpha


numeric characters.

It contains 8 light-emitting diode (LED) segments arranged in a special


form. Out of the 8 LED segments, 7 are used for displaying alpha
numeric characters.

The LED segments are named A to G and the decimal point LED
segment is named as DP.

The LED Segments A to G and DP should be lit accordingly to display


numbers and characters.

The 7 segment LED displays are available in two different


configurations, namely; Common anode and Common cathode.
Microcontroller lab, Dept. of E&C.

7-Segment LED Display

10

In the Common anode configuration, the anodes of the 8 segments are


connected commonly whereas in the Common cathode configuration,
the 8 LED segments share a common cathode line.

Microcontroller lab, Dept. of E&C.

7-Segment LED Display

11

Based on the configuration of the 7 segment LED unit, the LED


segment anode or cathode is connected to the Port of the
processor/controller in the order A segment to the Least significant port
Pin and DP segment to the most significant Port Pin.

The current flow through each of the LED segments should be limited to
the maximum value supported by the LED display unit

The current through each segment can be limited by connecting a


current limiting resistor to the anode or cathode of each segment

Microcontroller lab, Dept. of E&C.

12

A switch S1 is connected to P1.2. A common cathode 7-segment display is connected


to port2 of 8051 MC. Write a program to check status of switch and display
appropriately on the display. S1 ON display 1 & S1 OFF display 0.

ORG 8000H
MOV P1,#0FFH
LOOP: JNB P1.2, L1
MOV A,#06H
MOV P2,A
SJMP LOOP
L1: MOV A,#3FH
MOV P2,A
SJMP LOOP

Microcontroller lab, Dept. of E&C.

13

LCD

It is a display device used to display alpha numeric characters.

Microcontroller lab, Dept. of E&C.

14

LCD
Pin Description for LCD

Microcontroller lab, Dept. of E&C.

15

LCD
Command Codes for LCD

Microcontroller lab, Dept. of E&C.

LCD

16

Before displaying anything on LCD it has to be initialized. Store the


command words as an array and also store data to be displayed as
an array.

LCD initialisation: make RS(register select) = 0 to select command


register; make R/W(read/write) = 0 to write to the register; give a
high to low pulse to E(enable). (hence make E=1, after some delay
make E=0).

To write data to LCD: make RS(register select) = 1 to select data


register; make R/W(read/write) = 0 to write to the register; give a
high to low pulse to E(enable). (hence make E=1, after some delay
make E=0).

Microcontroller lab, Dept. of E&C.

Write a program to display MMC course on the LCD connected to 8051 MC. Note the following: P1.1 en pin,
P1.2

RS
pin,
P1.3

R/W
pin
and
port
2

data
pins
of
LCD.

17

ORG 8000H
RPT:MOV DPTR,#CMD
ACALL L1
MOV DPTR,#MSG
ACALL L2
SJMP RPT
L1: MOVC A,@A+DPTR

L2: MOVC A,@A+DPTR

JZ EXIT
INC DPTR
MOV P1,#04H
MOV P2,A
MOV P1,#01H
ACALL DELAY
MOV P1,#00H

JZ EXIT

SJMP L2

INC DPTR

EXIT: RET

MOV P1,#00H

DELAY: MOV R0, #0FFH ; Delay function

MOV P2,A

GO: MOV R1, #0FFH

MOV P1,#01H

HERE: DJNZ R1, HERE

ACALL DELAY

DJNZ R0, GO

MOV P1,#00H

RET

SJMP L1

ORG 9800H

EXIT: RET

CMD: DB 01H,06H,02H,0EH,85H,0
MSG: DB MMC COURSE, 0

Microcontroller lab, Dept. of E&C.

END

18

Motors- Stepper motor

Stepper motor is an electro mechanical device which generates discrete displacement


(motion) in response to dc electrical signals.

It differs from the normal dc motor in its operation. The dc motor produces continuous
rotation on applying dc voltage whereas a stepper motor produces discrete rotation in
response to the dc voltage applied to it.

Stepper motors are widely used in industrial embedded applications, consumer


electronic products and robotics control systems.

The stepping of stepper motor can be implemented in different ways by changing the
sequence of activation of the stator windings.

The different stepping modes supported by stepper motor are-

o Full step
o Wave step
o Half step
Microcontroller lab, Dept. of E&C.

19

Motors- Stepper motor

Microcontroller lab, Dept. of E&C.

20

Motors- Stepper motor


WAVE STEP SEQUENCE

FULL STEP SEQUENCE

HALF STEP SEQUENCE

Microcontroller lab, Dept. of E&C.

21

Motors- Stepper motor

Store the hex equivalent codes for energizing the windings as a LUT.

Get every code from the table and give it to the motor through Port with
some delays to observe motor rotation.

Microcontroller lab, Dept. of E&C.

Write a program to rotate the stepper motor in clockwise direction.


22

ORG E000H
HERE: MOV DPTR, #TABLE
ACALL SEND
SJMP HERE
SEND: CLR A
MOVC A,@A+DPTR
JZ EXIT
INC DPTR
MOV P2,A
LCALL DELAY
SJMP SEND
EXIT: RET
DELAY: MOV R0, #F7H
REPEAT: MOV R1, #FFH
GO: DJNZ R1, GO
DJNZ R0, REPEAT
RET
ORG EE00H
TABLE: DB 0DH, 0EH, 07H, 0BH, 0
END
Microcontroller lab, Dept. of E&C.

23

Motors DC Motor

A direct current (DC) motor is widely used device that translates


electrical pulses into mechanical movement.

In DC motor only + and leads are present. Connecting them to a DC


voltage source moves the motor in one direction.

Reversing the polarity, the DC motor will move in the opposite direction.

Microcontroller lab, Dept. of E&C.

24

Motors DC Motor

For a given fixed load a steady speed can be maintained by using a


method called pulse width modulation (PWM).

By changing (modulating) the width of the pulse applied to the DC


motor , amount of power supplied to the motor can be increased or
decreased.

Although the voltage has a fixed amplitude, it has a variable duty cycle.
That means wider the pulse, higher is the speed.

Microcontroller lab, Dept. of E&C.

25

A DC motor is connected to P1.2. Write a program to control speed of the DC motor


with 2 different speeds depending on the condition of a switch connected to P2.4.
ORG 8000H
MOV P2,#0FFH
HERE:JNB P2.4, L1
BACK: SETB P1.2
ACALL DELAY

DELAY: MOV R0, #F7H

CLR P1.2

REPEAT: MOV R1, #FFH

ACALL DELAY

GO: DJNZ R1, GO

SJMP BACK
L1: SETB P1.2
ACALL DELAY
ACALL DELAY
CLR P1.2
ACALL DELAY
SJMP L1
Microcontroller lab, Dept. of E&C.

DJNZ R0, REPEAT


RET
END

26

Keyboard

Keyboard is an input device for user interfacing.

If the number of keys required is very limited, push button


switches can be used and they can be directly interfaced to
the port pins for reading.

Matrix keyboard is an optimum solution for handling large


number of key requirements.

Matrix keyboard greatly reduces the number of interface


connections.

Matrix keyboard connects the keys in a row column fashion.

Microcontroller lab, Dept. of E&C.

Keyboard

27

For example, for interfacing 16


keys, in the direct interfacing
technique 16 port pins are
required, where as in the
matrix
keyboard
only
4
columns and 4 rows are
required for interfacing 16
keys.

The key press in matrix


keyboard is identified with rowcolumn scanning technique.

Microcontroller lab, Dept. of E&C.

ADC

28

An ADC is a device used to convert analog input to digital.

When sensors collect data, it will be in analog form and the MC cannot
process analog data. Hence an ADC is used to convert such data and
then given to the MC.

Generally an ADC has the following:

SOC

OE

EOC

Digital data outputs

Analog input

Microcontroller lab, Dept. of E&C.

ADC

29

SOC (start of conversion) is an input pin of ADC. A H-L pulse should be


given on this pin after the analog input is given to the ADC.

EOC (end of conversion) is an output pin of ADC. The output signal


should be monitored to accept the digital data.

OE (output enable) is an input pin of ADC. This signal should be given so


that converted digital data is latched and can be read from ADC.

Microcontroller lab, Dept. of E&C.

Write a program to interface an ADC with 8051 and read the digital data from ADC and store it in location
40h. Note that SOCP1.2 EOCP2.1 OEP1.4 digital data P3.

30

ORG 8000H
MOV R0,#40H
BACK: SETB P1.2
ACALL DELAY
CLR P1.2
L1:MOV A, P2
JNB ACC.1,L1
SETB P1.4
ACALL DELAY
MOV A,P3
MOV @R0,A
CLR P1.4
INC R0
SJMP BACK
END
Microcontroller lab, Dept. of E&C.

31

DAC

In certain controlling applications analog signals are required which the


MC cannot provide. Hence a DAC, digital to analog converter is used.

The digital data which have to be given for conversion is provided


through the MC port to the digital input of DAC.

Microcontroller lab, Dept. of E&C.

Write a program to generate sawtooth wave of 4V amplitude.


32
ORG 8000H
L2: MOV A,#00H
L1: MOV P1,A
INC A
CJNE A,#CCH,L1
SJMP L2

Microcontroller lab, Dept. of E&C.

You might also like