Unit 2 IO and Memory Interfacing - cs3691

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

8051 Interfacing

LCD AND KEYBOARD


INTERFACING
LCD Operation
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
 Relieving the CPU of the task of refreshing the
LCD
◦ Ease of programming for characters and
graphics
LCD PIN Descriptions
The function of each pin is given in the previous slide
Vcc, Vss, VEE
While Vcc and Vss provide +5v and ground respectively, VEE is used for controlling LCD
contrast
RS, register select
Two very important registers inside the LCD. The RS pin is used for their selection as follows
IF RS=0, the instruction command code register is selected, allowing the user to send a
command such as clear display, cursor at home etc
IF RS=1, the data register is selected, allowing the user to send data to be displayed on the
LCD.
R/W, read/write
R/W input allows the user to write information to the LCD or read information from it.
R/W=1, when reading; R/W=0 when writing.
E, enable
The enable pin is used by the LCD to latch information presented to the data pins.
LCD PIN Descriptions
The function of each pin is given in the previous slide
D0 – D7
The 8-bit data pins, D0-D7 are used to send information to the LCD or read the contents of the
LCD’s internal registers.
To display letters and numbers, send ASCII codes for the letters A-Z, a-z and numbers 0-9 to
these pins while making RS=1.
There are also instruction command codes that can be sent to the LCD to clear the display or
force the cursor to the home position or blink the cursor.
RS=0, to check the busy flag bit to see if LCD is ready to receive information.
The busy flag is D7 and can be read when R/W =1 and RS=0, as follows:
IF R/W=1, RS=0. When D7 = 1(busy flag=1), the LCD is busy taking care of internal
operations and will not accept any new information.
When D7=0, the LCD is ready to receive new information.
(It is recommended to check the busy flag before writing any data to the LCD)
LCD Read/Write
To read the command register we make R/W=1 and RS=0 and a Low to High Pulse for the E
pin will provide us the command register.
After reading the command register, if bit D7 (the busy flag) is high, the LCD is busy and no
information (command or data) should be issued to it.
Only when D7=0 can we send data or commands to the LCD. Notice in this method that no
time delays are used since we are checking the busy flag before issuing commands or data to
the LCD.
Contrast the Read and Write timing
Note that the E line is negative-edge triggered for the write while it is positive-edge triggered
for the read.
LCD Data Sheet
One can put data at any location in the
LCD
◦ The following shows address locations and
how they are accessed
 AAAAAAA=000_0000 to 010_0111 for line1
 AAAAAAA=100_0000 to 110_0111 for line2
 The upper address range can go as high as 0100111 for the
40-character-wide LCD
 Corresponds to locations 0 to 39
Keyboard Interfacing
Keyboards are organized in a matrix of
rows and columns
◦ The CPU accesses both rows and columns
through ports
 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 microcontroller takes
care of hardware and software interfacing
Keyboard Interfacing (cont.)
A 4x4 matrix connected to two ports
◦ The rows are connected to an output port
◦ The columns are connected to an input port
 If no key has been pressed, reading the input port
will yield 1s for all columns
 Since they are all connected to high (Vcc)
 If all the rows are grounded and a key is pressed,
one of the columns will have 0
 Since the key pressed provides the path to ground

◦ It is the function of the microcontroller to scan


the keyboard continuously to detect and
identify the key pressed
Grounding Rows and Reading
Columns
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
 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
Grounding Rows and Reading
Columns (cont.)
After detecting a key press, the
microcontroller will go through the
process of identifying the key
◦ 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
 The process is moved to the next row

◦ It grounds the next row, reads the columns,


and checks for any zero
Grounding Rows and Reading
Columns (cont.)
◦ This process continues until the row is
identified
After identification of the row in which
the key has been pressed
◦ Find out which column the pressed key
belongs to
Grounding Rows and Reading
Columns (cont.)
Detection and identification of key
activation goes through the following:
◦ To make sure that the preceding key has been
released, 0s are output to all rows at once, and
the columns are read and checked repeatedly
until all the columns are high
 When all columns are found to be high, the program
waits for a short amount of time before it goes to the
next stage of waiting for a key to be pressed
Grounding Rows and Reading
Columns (cont.)
◦ To see if any key is pressed, the columns are
scanned over and over in an infinite loop until
one of them has a 0 on it
 Remember that the output latches connected to rows
still have their initial zeros (provided in stage 1),
making them grounded
 After the key press detection, it waits 20 ms for the
bounce and then scans the columns again
 It ensures that the first key press detection was not an
erroneous one due a spike noise
 If after the 20-ms delay the key is still pressed, it goes back
into the loop to detect a real key press
Grounding Rows and Reading
Columns (cont.)
◦ To detect which row key press belongs to, it
grounds one row at a time, reading the
columns each time
 If it finds that all columns are high, this means that
the key press cannot belong to that row
 It grounds the next row and continues until it finds the row
the key press belongs to
 Upon finding the row that the key press belongs to,
it sets up the starting address for the look-up table
holding the scan codes (or ASCII) for that row
Grounding Rows and Reading
Columns (cont.)
◦ To identify the key press, it rotates the column
bits, one bit at a time, into the carry flag and
checks to see if it is low
 Upon finding the zero, it pulls out the ASCII code
for that key from the look-up table
 Otherwise, it increments the pointer to point to the
next element of the look-up table
8051 Interfacing

ADC, DAC, AND SENSOR


INTERFACING
PARALLEL AND SERIAL ADC
 ADC devices
 Analog-to-digital converters arc among the
most widely used devices for data acquisition.
 Examples in real world : Temperature, pressure
(wind or liquid), humidity, and velocity
(Produces an o/p voltage or current)
 Physical quantity is converted to electrical
(voltage, current) signals using a device called
a transducer (Sensors)
 Therefore, we need an ADC to translate the
analog signals to digital numbers so that the
microcontroller can read and process them.
PARALLEL AND SERIAL ADC
 ADC devices
 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.
 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.
PARALLEL AND SERIAL ADC
 ADC devices
 The ADC chips are either parallel or serial.
 In parallel ADC, we have 8 or more pins dedicated to
bringing out the binary data, but in serial ADC we
have only one pin for data out.
 The ADC0804 IC is an 8-bit parallel ADC which
works with +5 volts and has a resolution of 8 bits.
 ADC0808 has only one analog input but ADC0808
has 8 analog input which allows to monitor up to 8
different analog inputs using only a single chip. Has
an 8-bit data output just like the ADC804.
PARALLEL AND SERIAL ADC
 ADC 0808
 Vref(+) and Vref(-) set the
reference voltage. If Vref(-)=Gnd
and Vref(+)=5V, the step size is 5
V/256 = 19.53 mV.
 Therefore, to get a 10 mV step size
we need to set Vref(+)=2.56 V and
Vref (-) = Gnd.
 A, B and C addresses to select
INO - IN7, and activate ALE to latch
in the address.
 SC is for start conversion
 EOC is for end-of-conversion
 OE is for output enable (READ).
Steps to program ADC0808
 Select an analog channel by providing
bits to A, B, and C addresses
 Activate the ALE (address latch
enable) pin. It needs an L-to-H pulse
to latch in the address.
 Activate se (start conversion) by an L-
to-H pulse to initiate conversion
 Monitor EOC (end of conversion) to
see whether conversion is finished. H-
to-L output indicates that the data is
converted and is ready to be picked
up.
 Activate OE (output enable) to read
data out of the ADC chip. An Lto-H
pulse to the OE pin will bring digital
data out of the chip
Selecting a channel and Read Timing for ADC0808
8051 connection to ADC0808
Programming ADC0808
Serial ADC chips
 The ADC chips (ADC0848/0808/ 0809/0804) are all of the
parallel type.
 The DO. D7 data pins provide an 8-bit parallel data path
between the ADC chip and the CPU. In the case of the 16-bit
parallel ADC chip, 16 pins are needed for the data path.
 If space is a critical issue, using such a large number of pins
for data is not feasible,
 For this reason, serial devices such as the serial ADC arc
becoming widely used.
 Example MAX1112 serial ADC chip
◦ MAX1112 is an 8-bit serial ADC chip with 8 channels of analog input.
◦ It has a single DOUT pin to bring out the digital data after it has been
converted.
◦ It is compatible with a popular SPI and Microwave serial standard.
DAC Interfacing
 The digital-to-analog converter (DAC) is a device widely
used to convert digital to analog signals.
 Uses R/2R method since it can achieve higher degree of
precision.
 Resolution : function of the number of binary inputs. The
common ones are 8,10,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.
 8-bit DAC such as DAC0808 provides 256 discrete
voltage(or current) levels of output.
 12 bit DAC provides 4096 discrete voltage levels.
 16 bit DAC also exists, but more expensive.
MC1408 DAC (or DAC0808)
 The digital inputs are converted to current
(Iout), and by connecting a resistor to the lout
pin, result converted to voltage.
 The total current provided by the lout pin is a
function of the binary numbers at the D0 -
D7(In pin diagram A1-A8) 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
MC1408 DAC (or DAC0808)

 Example:
MC1408 DAC (or DAC0808)
Converting lout to voltage in DAC0808
 Ideally, the output pin Iout is connected to a resistor and the
current is converted to voltage and monitor the output on the
scope.
 This causes inaccuracy in real life because the input resistor of
the load where it is connected will also affect the output
voltage.
 For this reason, the Iref current output is isolated by connecting
it to an op-amp such as 741 with Rf5k ohms for the feedback
resistor.
Example – Stair Step Ramp
 In order to generate a stair-step ramp, set up the circuit and
connect the output to an oscilloscope. Then write a program to
send data to the DAC to generate a stair step ramp.
 Solution:
CLR A
MOV P1, A ;send data to DAC
INC A ;count from 0 to FFH
ACALL DELAY ;let DAC recover
SJMP AGAIN
AGAIN:
Sensor Interfacing
Temperature Sensors:
 Transducers convert physical data such as temperature, light
intensity, flow and speed to electrical signals.
 Depending on the transducer, the output produced is in the
form of voltage, current, resistance or capacitance.
 For example, temperature is converted to electrical signals
using a transducer called a thermistor .
 But the response from a thermistor is nonlinear.
 Because of the complexity associated with writing software
for nonlinear devices, linear temperature sensor like LM34,
LM35 series are widely used.
Sensor Interfacing : LM34 / LM35
Temperature Sensors:
 The sensors of the LM34 series are precision integrated-
circuit temperature sensors whose output voltage is linearly
proportional to the Fahrenheit temperature.
 The LM34 requires no external calibration since it is
internally calibrated.
 It outputs 10 mV for each degree of Fahrenheit temperature.
 The LM series sensors are precision intergrated circuit
temperature sensors whose output voltage is linearly
proportional to the Celsius (centigrade)
 The LM35 requires no external calibration since it is
internally calibrated.
 It outputs 10 mV for each degree of Centigrade temperature
Temperature Sensors: LM34 / LM35
Signal conditioning and interfacing the LM35 to the
8051
 Transducers produce an output in the form of voltage ,
current, charge, capacitance and resistance.
 These signals need to converted to voltage in order to
send to a ADC.
 This conversion is called Signal Conditioning
 Signal conditioning can be a current-to-voltage
conversion or
a signal amplification.
 For example, the thermistor changes resistance with
temperature. The change of resistance must be
translated into voltages in order to be of any use to an
ADC.
Temperature Sensors: LM34 / LM35
Connection of Temperature Sensor to the ADC.
 LM336 -2.5 zener diode is to fix the volage across the 10k
POT(Potentiometer) at 2.5V.
 LM336-2.5 overcomes the fluctuation in power supply
Temperature Sensors: LM34 / LM35
STEPPER MOTOR
Step angle:
Step angle is defined as the minimum
degree of rotation with a single step.
No of steps per revolution = 360° / step
angle
Steps per second = (rpm x steps per
revolution) / 60
Example: step angle = 2°
No of steps per revolution = 180
Example 1: Write an ALP to rotate the
stepper motor clockwise / anticlockwise
continuously with full step sequence.
Program:
MOV A,#66H
BACK: MOV P1,A
RR A
ACALL DELAY
SJMP BACK
DELAY: MOV R1,#100
UP1: MOV R2,#50
UP: DJNZ
R2,UP DJNZ
R1,UP1
RET
A15

You might also like