0% found this document useful (0 votes)
234 views

8051 LCD, Keyboard, Stepper Motor, ADC, DAC

This document discusses interfacing a stepper motor with an 8051 microcontroller. It describes the construction and working of stepper motors, including that they rotate in fixed increments based on input pulses. It also covers parameters like step angle and steps per revolution. Finally, it explains different drive modes for stepper motors like wave, full, and half drive, detailing which motor coils are energized in each step.

Uploaded by

arunambrose2004
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
234 views

8051 LCD, Keyboard, Stepper Motor, ADC, DAC

This document discusses interfacing a stepper motor with an 8051 microcontroller. It describes the construction and working of stepper motors, including that they rotate in fixed increments based on input pulses. It also covers parameters like step angle and steps per revolution. Finally, it explains different drive modes for stepper motors like wave, full, and half drive, detailing which motor coils are energized in each step.

Uploaded by

arunambrose2004
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 76

LCD

INTERFACING
8051
INTRODUCTION
• Display units are the most important output
devices in embedded projects and electronics
products.

• 16x2 LCD is one of the most used display unit.


16x2 LCD means that there are two rows in which
16 characters can be displayed per line, and each
character takes 5X7 matrix space on LCD.
CONTINUE…
• We use LCD display for the displaying messages
in a more interactive way to operate the system
or displaying error messages etc.
• It supports all the ASCII chars and is basically
used for displaying the alpha numeric characters.
• We can use any type of LCD like 16×2, 8×1,
16×4, 8×2, 16×1, 20×1, 20×2 etc.
PIN DIAGRAM
DESCRIPTION
LCD REGISTERS
• EN pin is for enabling the module. A high to low

transition at this pin will enable the LCD module.

ThisLM016L has two built in registers namely:

• Data register

• Command register
DATA REGISTER:
• It is for placing the data which is to be displayed.
• Data can be any character, alphabet or number.
• High logic at the RS pin will select the data
register.
• By making RS pin high and putting data in the 8
bit data line (DB0 to DB7), the LCD module
will recognize it as a data to be displayed.
COMMAND REGISTER:
• It is for placing the commands. There is a set of
commands for LCD to perform specific tasks.
• Low logic at the RS pin will select the command
register.
• By making RS pin low and putting data on the
data line, the LCD module will recognize it as a
command. Some of the instructions/commands
are given below:
Code (in Hex) Working of LCD commands

0x01 Clear displays

0x02 return home

0x06 for entry mode

0x08 Display off, cursor off

0x0E Display on, cursor on

0x0C Display on, cursor off

0x0F Display on, cursor blinking

0x10 Shift cursor position to left

0x14 Shift cursor position to right


LCD INTERFACING WITH 8051
• This LCD can be operated in 4-bit mode (using only 4 data
lines) or 8-bit mode (using all 8 data lines). Here we will use
it in 8-bit mode.
• First of all LCD is initialized and then it can be used for
sending data and commands.
• Reset and Enable of LCD is connected to port 1 of 8051
microcontroller. Data lines of LCD are connected to port 2
of 8051 microcontroller.

• R/W is connected to ground since we have to just


write data and command (not read operation).
TO INITIALIZE LCD FOR INTERFACING

• To initialize LCD with 8051 microcontroller,


following instruction are to be executed:
• 0x38 (is used for 8-bit data initialization)
• 0x0C (display on, cursor off)
• 0x01 (for clearing screen)
• 0x80 (force cursor to beginning of 1st line)
TO SEND DATA:
• For displaying any character whether it is number,
alphabet or character, following steps should be follow:
• For display data, register select (RS pin) should be high,
RS = 1.
• Place data byte on the data register.

• Pulse the Enable pin (EN pin) from high to low.

• Configure the R/W to write mode. For write mode, R/W =


0.
• Repeat above steps for sending another data.
TO SEND COMMAND:
• To instruct LCD for performing specific task for example
displaying character in second row instead of one,
following steps should be taken:
• For command mode, register select (RS pin) should be
low, RS = 0.
• Place data byte on the command register.

• Pulse the Enable pin (EN pin) from high to low.

• Read/Write should be low (write mode), R/W = 0.

• Repeat above steps for sending another command.


KEYBOARD
INTERFACING
8051
INTRODUCTION
• Keypad is used as an input device to read the key
pressed by user and to process it.
• A keypad is the most widely used devices of digital
circuits, microcontrollers or telephone circuits.
• A keypad is generally a matrix arrangement of tact
switches which are basically push button switches.
• 4x4 keypad consists of 4 rows and 4 columns.
Switches are placed between the rows and columns.
CONTINUE…
• A key press establishes a connection between
corresponding row and column between which the
switch is placed.

• To read the key press, we need to configure the


rows as outputs and columns as inputs.
• Columns are read after applying signals to the
rows in order to determine whether or not a key is
pressed and if pressed, which key is pressed.
SCANNING OF KEYS

• To detect a pressed key, the microcontroller


grounds all rows by providing 0 to the output latch,
and then it reads the columns shown in above fig.
• If the data read from columns is = 1111, no key has
been pressed shown in above fig. and the process
continues till key press is detected.
CONTINUE…
• Now, consider highlighted key in above fig. is pressed.
After pressing key, it makes contact of row with column
shown below.

• If one of the column bits has a zero, this means that a


key press has occurred.

• For example, if C1:C4 = 1011, this means that a key in


the C2 column has been pressed.

• After detecting a key press, microcontroller will go


through the process of identifying the key.
Process of Identifying the
Key
• Starting from the top row, the microcontroller will ground it by

providing a low to row R1 only.

• Now read the columns, if the data read is all 1s, no key in that

row is pressed and the process continues for the next row.

• So, now ground the next row, R2. Read the columns, check for

any zero and this process continues until the row is identified.

CONTINUE…
• E.g. In above case we will get row 2 in which

column is not equal to 1111.

• So, after identification of the row in which the key

has been pressed we can easily find out the key by

row and column value.


.
Interfacing Keypad with 8051
• For the interfacing of keypad with the microcontroller, it
is good to connect LCD also, so that we can observe
specific changes if the keypad is pressed.
• Keypad 4×3 (having 4 rows and 3 columns) is
connected to Port 2 of 8051 microcontroller to scan
input.
• LCD is connected to Port 1 of the microcontroller for
displaying output.
• Port 3 pin0 and pin2 of microcontroller is connected to
RS and EN pins of LCD respectively.
SETB RS=1 DATA
*
STEPPER MOTOR
INTERFACING
8051
STEPPER MOTOR
• Stepper motors are used to translates electrical
pulses into mechanical movements.
• In some disk drives, dot matrix printers, and some
other different places the stepper motors are used.
• The main advantage of using the stepper motor is
the position control.
• Stepper motors generally have a permanent magnet
shaft (rotor), and it is surrounded by a stator.
CONSTRUCTION
CONTINUE…
• The most common stepper motors have four
stator windings that are paired with a center-
tapped common as shown in figure.
CONTINUE…
• As the name indicates it rotates in steps according
to the input pulses.
• A stepper motor usually have a number of field coils
(phases) and a toothed rotor. The step size of the
motor is determined by the number of phases and
the number of teeth on the rotor
• Normal motor shafts can move freely but the stepper
motor shafts move in fixed repeatable increments
which allows one to move it to a precise position.
CONTINUE…
• This is possible as a result basic magnetic theory
where poles of the same polarity repel and opposite
poles attract.
• The direction of the rotation is dictated by the stator
poles.
• The stator poles are determined by the current sent
through the wire coils.
• As the direction of the current is changed, the polarity is
also changed causing the reverse motion of the motor.
ADVANTAGES of stepper motor

Stepper motors are used because of their:


• Low cost
• High reliability (because of no contact brushes)
• Good performance in starting, stopping and
reversing the direction
• High torque at low speed
• Gravel construction (can be used in variable
environment)
SOME PARAMETERS OF STEPPER MOTORS:

• Step Angle - The step angle is the angle which the


rotor moves when one pulse is applied as an
input of the stator. This parameter is used to
determine the positioning of a stepper motor.

• Steps per Revolution - This is the number of step


angles required for a complete revolution. So the
formula is 360° /Step Angle.
CONTINUE…
• Steps per Second - This parameter is used to
measure a number of steps covered in each
second.

• RPM - The RPM is the Revolution Per Minute. It


measures the frequency of rotation. By this
parameter, we can measure the number of
rotations in one minute.
WAVE DRIVE MODE:
• In this mode, one coil is energized at a time. So all four
coils are energized one after another. This mode produces
less torque than full step drive mode.

steps Winding A Winding B Winding C Winding D

1 1 0 0 0

2 0 1 0 0

3 0 0 1 0

4 0 0 0 1
FULL DRIVE MODE:
• In this mode, two coils are energized at the same time.
This mode produces more torque. Here the power
consumption is also high
• The following table is showing the sequence of input
states in different windings.

steps Winding A Winding B Winding C Winding D

1 1 1 0 0

2 0 1 1 0

3 0 0 1 1

4 1 0 0 1
HALF DRIVE MODE:
• In this mode, one and two coils are energized
alternately.
• At first, one coil is energized then two coils are
energized.
• This is basically a combination of wave and full drive
mode. It increases the angular rotation of the motor
steps Winding A Winding B Winding C
Winding D

1 0 0 0
1

2 1 1 0 0

3 0 1 0 0

4 0 1 1 0

5 0 0 1 0

6 0 0 1 1

7 0 0 0 1

8 1 0 0
1
Interfacing Stepper Motor with 8051
• We are using Port P0 of 8051 for connecting the stepper
motor. Here ULN2003 is used.
• This is basically a high voltage, high current Darlington
transistor array. Each ULN2003 has seven NPN Darlington
pairs.
• It can provide high voltage output with common cathode
clamp diodes for switching inductive loads.
• The Unipolar stepper motor works in three modes. The circuit
diagram is like below: We are using the full drive mode.
Assembly language program to interface stepper motor with 8051
// Wave Drive Mode
ORG 00H
MOV TMOD, #01H
MAIN:
MOV P2, #08H
ACALL DELAY
MOV P2, #04H
ACALL DELAY
MOV P2, #02H
ACALL DELAY
MOV P2, #01H
ACALL DELAY
SJMP MAIN
// To generate a delay of 200 *1 ms
DELAY:MOV R0,#200 //change this value to required delay in ms
BACK: MOV TH0,#0FCH
MOV TL0,#018H
SETB TR0
wait: JNB TF0,wait
CLR TR0
CLR TF0
DJNZ R0,BACK
RET
END

// Full Drive Mode


ORG 00H
MOV TMOD,#01H
MAIN:
MOV P2, #0CH
ACALL DELAY
MOV P2, #06H
ACALL DELAY
MOV P2, #03H
ACALL DELAY
MOV P2, #09H
ACALL DELAY
SJMP MAIN
// Half Drive Mode
ORG 00H
MOV TMOD,#01H
MAIN:
MOV P2, #08H
ACALL DELAY
MOV P2, #0CH
ACALL DELAY
MOV P2, #04H
ACALL DELAY
MOV P2, #06H
ACALL DELAY
MOV P2, #02H
ACALL DELAY
MOV P2, #03H
ACALL DELAY
MOV P2, #01H
ACALL DELAY
MOV P2, #09H
ACALL DELAY
SJMP MAIN

// To generate a delay of 200 *1ms


DELAY:MOV R0, #200 //change this value to required delay in ms
BACK: MOV TH0, #0FCH
MOV TL0, #018H
SETB TR0
wait: JNB TF0, wait
CLR TR0
CLR TF0
DJNZ R0, BACK
RET
END
ANALOG-TO-DIGITAL CONVERTER (ADC) INTERFACING:
• ADCs (analog-to-digital converters)are among the most widely used devices
for data acquisition.
• A physical quantity, like temperature, pressure, humidity, and velocity, etc., is
converted to electrical (voltage, current)signals using a device called a
transducer or sensor
• We need an analog-to-digital converter to translate the analog signals to
digital numbers, so microcontroller can read and process them.
• An ADC has n-bit resolution where n can be 8, 10, 12, 16 or even 24 bits.
• The higher-resolution ADC provides a smaller step size, where step size is the
smallest change that can be discerned by an ADC. This is shown in table 5.3
ANALOG-TO-DIGITAL CONVERTER (ADC) INTERFACING:

Table 5.3 Resolution Vs Step Size for ADC


ANALOG-TO-DIGITAL CONVERTER (ADC) INTERFACING:

• In addition to resolution, conversion time is another major factor


in judging an ADC.
• Conversion time is defined as the time it takes the ADC to
convert the analog input to a digital (binary) number.
• The ADC chips are either parallel or serial.
• In parallel ADC, we have 8 of more pins dedicated to bringing out
the binary data, but in serial ADC we have only one pin for data
out.
ADC804 chip:
• ADC804 IC is an 8-bit parallel analog-to-digital converter.
• It works with +5 volts and has a resolution of 8bits.
• In ADC804 conversion time varies depending on the clocking
signals applied to the CLK R and CLK IN pins, but it cannot be
faster than 110μs.
• Figure 5.5 Pin out of ADC0804 in free running mode.
• The following is the ADC0804 pin description.
ADC804 chip:

Figure 5.5 ADC0804 Chip (Testing ADC0804 in Free Running Mode)


ADC804 chip:
CLK IN and CLK R:
• CLK IN is an input pin connected to an external clock source when
an external clock is used for timing.
• However, the 0804 has an internal clock generator.
• To use the internal clock generator (also called self-clocking), CLK IN
and CLK R pins are connected to a capacitor and a resistor and the
clock frequency is determined by:
• Typical values are R = 10K ohms and C =150pF.
• By substituting, we get f = 606 kHz and the conversion time is 110μs.
ADC804 chip:
➢ Vref/2: (Pin 9)
• • It is used for the reference voltage.
• • If this pin is open (not connected),
the analog input voltage is in the range
of 0 to 5 volts (the same as the Vcc pin).
• • If the analog input range needs to be
0 to 4 volts, Vref/2 is connected to 2
volts.
• • Table 5.4 shows the Vin range for
various Vref/2 inputs.
ADC804 chip:
➢ D0-D7:
• D0-D7 are the digital data output pins.
• •These are tri-state buffered and the converted data is accessed
only when CS =0 and RD is forced low.
• To calculate the output voltage, use the following formula
• Dout = digital data output (in decimal),
• Vin = analog voltage, and
• Step size (resolution) is the smallest change, which is (2 *
Vref/2)/256 for ADC 0804
ADC804 chip:

➢ Analog ground and digital ground:


• Analog ground is connected to the ground of the analog Vin and digital ground is
connected to the ground of the Vcc pin.
• The reason that to have ground pin is to isolate the analog Vin signal from
transient voltages caused by digital switching of the output D0 – D7. This
contributes to the accuracy of the digital data output.
➢ Vin(+) & Vin(-):
• Differential analog inputs where Vin= Vin (+) – Vin (-).
• Vin (-) is connected to ground and Vin(+) is used as the analog input to be
converted.
ADC804 chip:

➢ RD:
• This is an input signal and is active low.
• The ADC converts the analog input to its binary equivalent and holds it in an internal
register.
• RD is, used to get the converted data out of the ADC0804 chip.
• Is “output enable” a high-to-low RD pulse is used to get the 8-bit converted data out of
ADC804.
➢ INTR:
• This is an output pin and is active low.
• It is “end of conversion” When the conversion is finished, it goes low to signal the CPU
that the converted data is ready to be picked up.
ADC804 chip:
WR:
• This is an active low input
• •It is “start conversion” When WR makes a low-to-high transition, ADC804 starts converting the
analog input value of Vin to an 8-bit digital number.
• •When the data conversion is complete, the INTR pin is forced low by the ADC0804.
➢ CS:
• It is an active low input used to activate ADC804.
➢ Steps to Be followed For Data Conversion:
• The following steps must be followed for data conversion by the ADC804 chip: o Make CS= 0 and
send a L-to-H pulse to pin WR to start conversion.
• Monitor the INTR pin, if high keep polling but if low, conversion is complete, go to next step.
• Make CS= 0 and send a H-to-L pulse to pin RD to get the data out.
• Figure 5.6 shows the timing diagram for ADC process.
ADC804 chip:

Figure 5.6 Read and Write Timing for ADC08804


ADC804 chip:
• Clock source for ADC0804:
➢ The speed at which an analog input is converted to the digital output depends on
the speed of the CLK input.
➢ According to the ADC0804 datasheets, the typical operating frequency is
approximately 640kHz at 5 volts.
➢ Figures 5.7 and 5.8 show two ways of providing clock to the ADC0804.
➢ In Figure 5.8, notice that the clock in for the ADC0804 is coming from the crystal of
the microcontroller.
➢ Since this frequency is too high, we use D flip-flops (74LS74) to divide the frequency.
➢ A single D flip-flop divides the frequency by 2 if we connect its 𝑄̅ to the D input.
➢ For a higher-frequency crystal, you can use 4 flip-flops
ADC804 chip:

Figure 5.7 8051 Connection to ADC0804 with Self-Clocking


ADC804 chip:

Figure 5.8 8051 Connection to ADC0804 with Clock from XTAL2 of the 8051
Example:
• Write a program to monitor the INTR pin and bring an analog input
into register A. Then call a hex-to ACSII conversion and data display
subroutines. Do this continuously.
;p2.6=WR (start conversion needs to L-to-H pulse)
;p2.7 When low, end-of-conversion)
;p2.5=RD (a H-to-L will read the data from ADC chip)
;p1.0 – P1.7= D0 - D7 of the ADC804
;
MOV P1,#0FFH ;make P1 = input
BACK: CLR P2.6 ;WR = 0
SETB P2.6 ;WR = 1 L-to-H to start conversion
HERE: JB P2.7,HERE ;wait for end of conversion
CLR P2.5 ;conversion finished, enable RD
MOV A,P1 ;read the data
ACALL CONVERSION ;hex-to-ASCII conversion
ACALL DATA_DISPLAY ;display the data
SETB P2.5 ;make RD=1 for next round
SJMP BACK

You might also like