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

r4 Unit 5 m&m Ppt

The document covers assembly programming and interfacing of various components with the 8051 microcontroller, including LCD, keyboard, ADC, DAC, and stepper motors. It provides detailed instructions on how to connect and program these components, along with example code snippets for each interfacing scenario. Additionally, it discusses the principles of operation for each component and the significance of signal conditioning in data acquisition.

Uploaded by

aditya14201
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
0% found this document useful (0 votes)
12 views

r4 Unit 5 m&m Ppt

The document covers assembly programming and interfacing of various components with the 8051 microcontroller, including LCD, keyboard, ADC, DAC, and stepper motors. It provides detailed instructions on how to connect and program these components, along with example code snippets for each interfacing scenario. Additionally, it discusses the principles of operation for each component and the significance of signal conditioning in data acquisition.

Uploaded by

aditya14201
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/ 42

MICROPROCESSOR KEC-502

& UNIT-V
MICROCONTROLLER
By: Sakshi Mittal
UNIT V: Assembly programming and KEC-
instruction of 8051 502

Interfacing:
• LCD & Keyboard Interfacing
• ADC, DAC & Sensor Interfacing
• Stepper motor Interfacing
LCD AND KEYBOARD
INTERFACING

• LCD is finding widespread use


replacing LEDs
• The declining prices of LCD
• The ability to display numbers,
characters and graphics
• Incorporation of a refreshing
controller into the LCD, thereby
relieving the CPU of the task of
refreshing the LCD
• Ease of programming for
characters and graphics
LCD CONNECTION
• To send any of the
commands to the LCD,
make pin RS=0.
• For data, make RS=1.
• Then send a high-to-low
pulse to the E pin to enable
the internal latch of the
LCD. This is shown in the
code below.
• ;calls a time delay before
sending next
data/command
• ;P1.0-P1.7 are connected to
LCD data pins D0-D7
• ;P2.0 is connected to RS
pin of LCD
• ORG 0H
• MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX
• ACALL COMNWRT ;call command subroutine
• ACALL DELAY ;give LCD some time
• MOV A,#0EH ;display on, cursor on
• ACALL COMNWRT ;call command subroutine
• ACALL DELAY ;give LCD some time
• MOV A,#01 ;clear LCD
• ACALL COMNWRT ;call command subroutine
• ACALL DELAY ;give LCD some time
• MOV A,#06H ;shift cursor right
• ACALL COMNWRT ;call command subroutine
• ACALL DELAY ;give LCD some time
• MOV A,#84H ;cursor at line 1, pos. 4
• ACALL COMNWRT ;call command subroutine
• ACALL DELAY ;give LCD some time
• MOV A,#’N’ ;display letter N
• ACALL DATAWRT ;call display subroutine
• ACALL DELAY ;give LCD some time
• MOV A,#’O’ ;display letter O
• ACALL DATAWRT ;call display subroutine
• AGAIN: SJMP AGAIN ;stay here

COMNWRT: ;send command to LCD


• MOV P1,A ;copy reg A to port 1
• CLR P2.0 ;RS=0 for command
• CLR P2.1 ;R/W=0 for write
• SETB P2.2 ;E=1 for high pulse
• ACALL DELAY ;give LCD some time
• CLR P2.2 ;E=0 for H-to-L pulse
• RET
DATAWRT: ;write data to LCD
• MOV P1,A ;copy reg A to port 1
• SETB P2.0 ;RS=1 for data
• CLR P2.1 ;R/W=0 for write
• SETB P2.2 ;E=1 for high pulse
• ACALL DELAY ;give LCD some time
• CLR P2.2 ;E=0 for H-to-L pulse
• RET
DELAY:
• MOV R3,#50 ;50 or higher for fast CPUs
• HERE2: MOV R4,#255 ;R4 = 255
• HERE: DJNZ R4,HERE ;stay until R4 becomes 0
• DJNZ R3,HERE2
• RET
• END
KEYBOARD INTERFACING

• Keyboards are organized in a matrix of rows and columns.


• The CPU accesses both rows and columns through ports.
Therefore, with two 8-bit ports, an 8 x 8 matrix of keys can be
connected to a microprocessor.
• When a key is pressed, a row and a column make a contact.
• Otherwise, there is no connection between rows and columns.
• In IBM PC keyboards, a single microcontroller takes care of
hardware and software interfacing
KEYBOARD INTERFACING…

• It is the function of the microcontroller to scan the keyboard


continuously to detect and identify the key pressed.
• To detect a pressed key, the microcontroller grounds all rows by
providing 0 to the output latch, then it reads the columns.
• If the data read from columns is D3 – D0 = 1111, no key has been
pressed and the process continues till key press is detected.
• If one of the column bits has a zero, this means that a key press
has occurred.
• For example, if D3 – D0 = 1101, this means that a key in the D1
column has been pressed.
• After detecting a key press, microcontroller will go through the
KEYBOARD INTERFACING…

• Starting with the top row, the microcontroller grounds it by


providing a low to row D0 only.
• It reads the columns, if the data read is all 1s, no key in that
row is activated and the process is moved to the next row.
• It grounds the next row, reads the columns, and checks for
any zero.
• This process continues until the row is identified.
• After identification of the row in which the key has been
pressed, finds out which column the pressed key belongs to.
• A 4x4 matrix connected to two ports ¾ The rows are
connected to an output port and the columns are
connected to an input port
Keyboard
programming…
Keyboard
Programming…
Keyboard
Programming

ADC AND DAC 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 them
• ADC804 IC is an analog-to-digital converter. It works with +5 volts and has
a resolution of 8 bits.
• 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.
• In ADC804 conversion time varies depending on the clocking signals
applied to CLK R and CLK IN pins, but it cannot be faster than 110 µs.
ADC804
ADC804:

• CLK IN and CLK R:


• CLK IN is an input pin connected to an external clock source.
• 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 = 150 Pf. We get f =


606 kHz and the conversion time is 110 µs
ADC804:
Vref/2:
•It is used for the reference Voltage
•If this pin is open (not connected), the analog input voltage is in the range of 0-5 Volts(same as VCC pin)
•If the analog Input Range needs to be 0-4 volts, Vref/2 is connected to 2Volts
ADC804:

D0-D7:
• The digital data output pins.
• These are tri-state buffered .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
ADC804:

Analog ground and digital ground:


• Analog ground is connected to the ground of the analog
Vin.
• Digital ground is connected to the ground of the Vcc pin.
• 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
The following steps must be followed for data conversion by
the ADC804 chip:

• Make CS = 0 and send a low-to-high


pulse to pin WR to start conversion.
• Keep monitoring the INTR pin.
• If INTR is low, the conversion is finished.
• If the INTR is high, keep polling until it
goes low.
• After the INTR has become low, we make
CS = 0 and send a high-to-low pulse to
the RD pin to get the data out of the
ADC804
ADC INTERFACING
ORG 00H
MOV P1,#11111111B // initiates P1 as the input port
MAIN: CLR P3.7 // makes CS=0
SETB P3.6 // makes RD high
CLR P3.5 // makes WR low
SETB P3.5 // low to high pulse to WR for starting conversion
WAIT: JB P3.4,WAIT // polls until INTR=0
CLR P3.7 // ensures CS=0
CLR P3.6 // high to low pulse to RD for reading the data from ADC
MOV A,P1 // moves the digital data to accumulator
CPL A // complements the digital data(ADC 0804 has active low outputs)
MOV P0,A // outputs the data to P0 for the LEDs
SJMP MAIN // jumps back to the MAIN program END
Digital-to-Analog (DAC) converter
• The digital-to-analog converter (DAC) is a device widely used to
convert digital pulses to analog signals.
• There are two methods of creating a DAC: binary weighted and
R/2R ladder.
• The vast majority of integrated circuit DACs, including the MC1408
(DAC0808) use the R/2R method since it can achieve a much
higher degree of precision.
• The first criterion for judging a DAC is its resolution, which is a
function of the number of binary inputs. The common ones are 8,
10, and 12 bits. The number of data bit inputs decides the
resolution of the DAC since the number of analog output levels is
equal to 2n, where n is the number of data bit inputs. Therefore, an
DAC0808:
In the MC1408 (DAC0808), the digital inputs are converted to current
(Iout), and by connecting a resistor to the I out pin, we convert the
result to voltage.
The total current provided by the Iout pin is a function of the binary
numbers at the DO – D7 inputs of the DAC0808 and the reference
current (Iref), and is as follows:

where D0 is the LSB, D7 is the MSB for the inputs, and Iref is the input
current that must be applied to pin 14. The Iref current is generally set to
2.0 mA. Figure 13-18 shows the generation of current reference (setting Iref
= 2 mA) by using the
standard 5-V power supply and IK and 1.5K-ohm standard resistors. Some
INTERFACING DAC0808:
DATA TABLE FOR SINE WAVE GENERATION
DAC INTERFACING
START:MOV DPTR,#TABLE
MOV R1,#13
CLR A
LOOP: MOVC A,@A+DPTR
MOV P1,A
INC DPTR
DJNZ R1,LOOP
SJMP START
TABLE: ORG 200H
DB 128,192,238,255,238,192,128,64,17,0,17,64,128
SENSOR INTERFACING

• A thermistor responds to temperature change by changing resistance, but


its response is not linear.
• The complexity associated with writing software for such nonlinear
devices has led many manufacturers to market the linear temperature
sensor.
• The sensors of the LM34/LM35 series are precision integrated-circuit
temperature sensors whose output voltage is linearly proportional to the
Fahrenheit/Celsius temperature. The LM34/LM35 requires no external
calibration since it is inherently calibrated. It outputs 10 mV for each
degree of Fahrenheit/Celsius temperature.
SENSOR INTERFACING…

Signal conditioning is a widely used term in the


world of data acquisition.
It is the conversion of the signals (voltage,
current, charge, capacitance, and resistance)
produced by transducers to voltage, which is
sent to the input of an Ato-D converter.
Signal conditioning can be a current-to-voltage
conversion or a signal amplification.
The thermistor changes resistance with
temperature, while the change of resistance
must be translated into voltage in order to be
of any use to an ADC
ADC804 & LM35
INTERFACING WITH
8051
Stepper Motor

• Stepper motors are used to translate


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.
Stepper Motor

• The Stepper motor is a brushless DC motor that divides


the full rotation angle of 360° into a number of equal
steps.
• The motor is rotated by applying a certain sequence of
control signals. The speed of rotation can be changed by
changing the rate at which the control signals are
applied.
• Various stepper motors with different step angles and
torque ratings are available in the market.
• A microcontroller can be used to apply different control
The Unipolar stepper motor works in three modes:

• 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.
The Unipolar stepper motor works in three modes…

• 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 Unipolar stepper motor works in three modes…

• 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
STEPPER MOTOR
INTERFACING
Port P2 of 8051 has been
used for connecting 6 wires
Unipolar Stepper Motor the
stepper motor.
•Only four wires are required
to control the stepper motor.
•Two common wires of
stepper motor connected to
the 5V supply.
Here, ULN2003 is used to
drive stepper motor.
This is basically a high
voltage, high current
Wave Drive Mode Program:
• ORG 00H
• MOV TMOD, #01H
To generate a delay of 200 *1 ms
• MAIN:
• MOV P2, #08H DELAY:MOV R0,#200 //change this value to
• ACALL DELAY required delay in ms
• MOV P2, #04H BACK: MOV TH0,#0FCH
MOV TL0,#018H
• ACALL DELAY
SETB TR0
• MOV P2, #02H wait: JNB TF0,wait
• ACALL DELAY CLR TR0
• MOV P2, #01H CLR TF0
DJNZ R0,BACK
• ACALL DELAY
RET
• SJMP MAIN END
Full Drive Mode:

• ORG 00H
• ACALL DELAY
• MOV • SJMP MAIN
TMOD,#01H
• MAIN:
• MOV P2, #0CH
• ACALL DELAY
• MOV P2, #06H
• ACALL DELAY

• MOV P2, #03H


• ACALL DELAY
Half Drive Mode
• ORG 00H • ACALL DELAY
• MOVTMOD,#0 • MOV P2, #02H
1H • ACALL DELAY
• MAIN: • MOV P2, #03H
• MOV P2, • ACALL DELAY
#08H • MOV P2, #01H
• ACALL DELAY
• ACALL DELAY
• MOV P2, #09H
• MOV P2, • ACALL DELAY
#0CH • SJMP MAIN
• ACALL DELAY

• MOV P2,
THANK YOU!!

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