Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 44

Interfacing of 8051

UNIT 4
Contents
• Interfacing of 7 segment display, LCD and
keyboard.

• Interfacing of DC motor, stepper motor and


relay.

• Interfacing of ADC, DAC and sensors.


7 segment display
Interfacing of 7 segment display
7 segment code for CC

DP G F E D C B A NUMBER

0 0 0 0 0 1 1 0 1

0 1 0 1 1 0 1 1 2

0 1 0 0 1 1 1 1 3
PROGRAM 7 SEGMENT DISPLAY
• To display ‘1’

MOV A,#06H
MOV P1,A
SJMP $
LCD Interfacing
Pin No: Name Function

1 VSS This pin must be connected to the


ground
2 VCC Positive supply voltage pin (5V DC)

3 VEE Contrast adjustment


4 RS Register selection
5 R/W Read or write
6 E Enable
7 DB0 Data
8 DB1 Data
9 DB2 Data
10 DB3 Data
11 DB4 Data
12 DB5 Data
13 DB6 Data
14 DB7 Data
15 LED+ Back light LED+
16 LED- Back light LED-
1 Clear display screen
2 Return Home
4 Decrement cursor (shift cursor to left)
5 Increment cursor (shift cursor to right)
6 shift display right
7 shift display left
8 Display off, cursor off
A Display off, cursor on
C Display on, cursor off
E Display on, cursor blinking
F Display on, cursor blinking
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift the entire display to the left
1C Shift the entire display to the right
80 Force cursor to the beginning of 1st line
C0 Force cursor to the beginning of 2nd line
38 2 lines and 5 x 7 matrix
Interface Program
MOV A,#38H // Use 2 lines and MOV A,#’W’
5x7 matrix ACALL DISP
ACALL CMND MOV A,#’E’
MOV A,#0FH // LCD ON, cursor ACALL DISP
ON, cursor blinking ON MOV A,#’L’
ACALL CMND ACALL DISP
MOV A,#01H //Clear screen MOV A,#’C’
ACALL CMND ACALL DISP
MOV A,#06H //Increment cursor MOV A,#O
ACALL CMND ACALL DISP
MOV A,#82H //Cursor line one , MOV A,#’M’
position 2 ACALL DISP
ACALL CMND MOV A,#’E’
MOV A,#3CH //Activate second ACALL DISP
line
ACALL CMND
CMND: MOV P1,A DISP:MOV P1,A
CLR P3.5 SETB P3.5
CLR P3.4 CLR P3.4
SETB P3.3 SETB P3.3
CLR P3.3 CLR P3.3
ACALL DELY ACALL DELY
RET; RET;
DELY: MOV R0,#0FFH • Subroutine CMND sets
HERE: DJNZ R0, HERE the logic of the RS, R/W, E
RET; pins of the LCD module so
that the module
recognizes the input data
( given to DB0 to DB7) as
a command.
• Subroutine DISP sets the
logic of the RS, R/W, E
pins of the module so
that the module
recognizes the input data
as a data to be displayed .
8051 & dc motor interface
ORG 00H // initial starting address
MAIN: MOV P1,#00000001B // motor runs clockwise
ACALL DELAY // calls the 1S DELAY
MOV P1,#00000010B // motor runs anti clockwise
ACALL DELAY // calls the 1S DELAY
SJMP MAIN // jumps to label MAIN for repeating the
cycle

DELAY: MOV R4,#0FH


WAIT1: MOV R3,#0FFH
WAIT2: MOV R2,#0FFH
WAIT3: DJNZ R2,WAIT3
DJNZ R3,WAIT2
DJNZ R4,WAIT1
RET
END
Stepper Motor Interfacing
• What is stepper motor?
– Stepper motors consist of a permanent magnetic
rotating shaft, called the rotor, and
electromagnets on the stationary portion that
surrounds the motor, called the stator.
– a motor with a resolution of 5 degrees would
move its rotor 5 degrees per step, thereby
requiring 72 pulses (steps) to complete a full 360
degree rotation.
Stepper motor operation
• At position 1, we can see that the rotor is
beginning at the upper electromagnet, which
is currently active (has voltage applied to it).
• To move the rotor clockwise (CW), the upper
electromagnet is deactivated and the right
electromagnet is activated, causing the rotor
to move 90 degrees CW, aligning itself with
the active magnet.
• This process is repeated in the same manner
at the south and west electromagnets until we
once again reach the starting position.
• In the above example, we used a motor with a
resolution of 90 degrees or demonstration
purposes.
• In reality, this would not be a very practical
motor for most applications. The average
stepper motor's resolution -- the amount of
degrees rotated per pulse is much higher than
this.
• You may double the resolution of some
motors by a process known as "half-stepping".
• Instead of switching the next electromagnet in
the rotation on one at a time, with half
stepping you turn on both electromagnets,
causing an equal attraction between, thereby
doubling the resolution.
• Both the top and right electromagnets are
active, causing the rotor to position itself
between the two active poles
Sequence Polarity Name Description
Wave Drive, One- Consumes the least power. Only one
Phase phase is energized at a time. Assures
0001 ---+ positional accuracy regardless of any
0010 --+- winding imbalance in the motor.
0100 -+--
1000 +---

0011 --++ Hi-Torque, Two- Hi Torque - This sequence energizes two


0110 -++- Phase adjacent phases, which offers an
1100 ++-- improved torque-speed product and
1001 +--+ greater holding torque.
0001 ---+ Half- Half Step - Effectively
0011 --++ Step doubles the stepping
0010 --+- resolution of the motor, but
0110 -++- the torque is not uniform for
0100 -+-- each step. (Since we are
1100 ++-- effectively switching
1000 +--- between Wave Drive and Hi-
1001 +--+ Torque with each step,
torque alternates each
step.) This sequence
reduces motor resonance
which can sometimes cause
a motor to stall at a
particular resonant
frequency. Note that this
sequence is 8 steps.
Stepper motor programming
org 0H delay:
mov r7,#4
stepper equ P3 wait2:
mov r6,#0FFH
main: wait1:
mov stepper, #0CH mov r5,#0FFH
acall delay wait:
mov stepper, #06H djnz r5,wait
acall delay djnz r6,wait1
mov stepper, #03H djnz r7,wait2
acall delay ret
mov stepper, #09H
acall delay
sjmp main
Analog to Digital Converter
• Commonly used ADC device – ADC804
• Pin out of ADC
– CS – Chip Select , active low
– RD – Read Digital data from ADC, H-L edge triggered
– WR -- Start conversion, L-H pulse edge triggered
– INTR -- end of conversion, Goes low to indicate conversion done
– Data bits -- D0-D7
• CLK IN & CLK R
– CLK IN is an input pin connected to an external clock source when an external
clock is used for timing. However, ADC804 has an internal clock generator.

• To use the internal clock generator of the ADC804, the CLK IN and CLK R pins are
connected to a capacitor and a resistor. In that case, the clock frequency is
determined by the equation.
f = 1/1.1RC
R=10K and C=150pF f=606Hz
the conversion time is 110us.
Input Voltage range of ADC
Vref/2 Vin
Step size (mV)
(Volts) (Volts)

Open (2.5) 0 to 5 5/256 = 19.53

2.56 0 to 5.12 5.12/256 =20

1.28 0 to 2.56 2.56/256 = 10

0.5 0 to 1 1/256=3.90
• Default 0-5V. Can be changed by setting
different value for Vref/2 pin.
Vin=Vin(+) – Vin (-)
• Range = 0 to 2x Vref/2.
for Vin = 2x Vref/2. we get 256 as a digital
output on D0-D7
• Step Size a Smallest change
– (2 x Vref/2)/ 256 for ADC804
for eg for step size 10mv ,digital output on
D0-D7 changes by one count for every 10mv
change of the input analog voltage.
Algorithm
• Make CS=0 and send a low-to-high to pin
WR to start the conversion.
• Keep monitoring INTR
– If INTR =0, the conversion is finished and we
can go to the next step.
– If INTR=1, keep polling until it goes low.
• After INTR=0, we make CS=0 and send a
high-to-low pulse to RD to get the data out of
the ADC804 chip.
ADC Interfacing
ADC_IO:
mov P1, #0xff ; To configure as input
setb p3.4
clr p3.7 ;Chip select
AGAIN
setb P3.6 ;RD=1
clr P3.5 ;WR=0
setb P3.5 ;WR=1- low to high transition
WAIT:
jb P3.4, WAIT ;wait for INTR
clr P3.6 ;RD=0 -High to low transition
mov A, P1 ;read digital o/p
sjmp AGAIN
DAC Interfacing
• Iout= Iref (D7/2+D6/4+D5/8+D4/16+D3/32+D2/64+D1/128+D0/256)
• Vout=Iout x R
Interfacing of Relay with 8051
Interfacing LDR with 8051

You might also like