BECE201L
Microprocessors and Microcontrollers
Module-5
I/O interfacing with Microcontroller 8051
Part-2
Module:5 I/O interfacing with Microcontroller 8051
LCD, LED, Keypad, Analog-to-Digital Convertors, Digital-to-
Analog Convertors, Sensor with Signal Conditioning Interface.
7 hours
Introduction
• To develop a complete embedded system using 8051, following devices/
components needs to be interfaced.
• Input Devices (Keypad)
• Sensors (Temperature sensor)
• Analog to Digital Converter (ADC)
• Digital to Analog Converter (DAC)
• Display systems (LCD/LED)
• Actuators
Introduction to ADC
• The physical quantities such as temperature, audio, Infrared, pressure,
humidity, and velocity,… are analog (continuous) in nature.
• In order to monitor these physical quantities sensors are widely used.
• Sensors converts physical quantities into electrical (voltage, current)
signals so that they can be given as input to microcontrollers.
• The output from the sensors are generally analog but microprocessors/
controllers use digital signals.
• So, an Analog to Digital Converter (ADC) is required to translate the
analog signals to digital numbers, so microcontroller can read and
process.
• ADCs are among the most widely used devices for data acquisition.
Introduction to ADC
• Example:
Introduction to ADC
• Two major factors decides the type of ADC for a particular applications.
• Resolution:
• The number of bits (n) used to digitize analog input samples.
• Decides the smallest change in voltage (Step size) that the ADC
can detect.
• High resolution means smaller step size.
• ADCs with n=8, 10, 12, 16 even 24-bits are available.
• Conversion time:
• The time taken to convert the analog input to a digital (binary)
number.
Introduction to ADC
• Depending on how the digital data is read out, there are two types of
ADCs available.
• Parallel ADC:
• 8 or more pins/ lines dedicated to bring binary data out from
ADC.
• Example:
• ADC0804, ADC0808/09, ADC0848.
• Serial ADC.
• Only one pin is available to bring binary data out from ADC.
• Example:
• MAX1112.
Introduction to ADC
• The process of Analog to Digital Conversion
• Continuous amplitude to Discrete
• Step size
• Continuous in time to Discrete in time
• Sample at uniform time spacing
Introduction to ADC
• The process of Analog to Digital Conversion
7
6
5
4
3
2
1
0
Introduction to ADC
• ADC Resolution Vs Step Size
1-bit ADC 3-bit ADC
2-bit ADC
Introduction to ADC
• ADC Resolution Vs Step Size
Introduction to ADC
• ADC Resolution Vs Step Size
𝑽𝒓𝒆𝒇
Step Size = ൗ𝟐𝒏
* By changing 𝑉𝑟𝑒𝑓 the step size can be controlled.
n-bit Number of steps Step size (mV)
8 256 5/256 = 19.53
10 1024 5/1024 = 4.88
12 4096 5/4096 = 1.2
16 65,536 5/65,536 = 0.076
Note: Vref = 5V
ADC0804 interfacing with 8051
• The ADC0804 IC is an 8-bit parallel ADC
in the family of the ADC0800 series from
National Semiconductor.
• It works with +5 volts and has a resolution
of 8 bits.
• Clock frequency 640 kHz.
• In the ADC0804, the conversion time varies
depending on the clocking signals applied
to the CLK IN pin, but not faster than
𝟏𝟏𝟎 𝝁𝒔.
ADC0804 interfacing with 8051
The power supply (Vcc):
• This is the +5 V power supply.
• Also used for reference voltage when the Vref/ 2 input (pin 9) is open (not
connected).
Analog ground & digital ground (D GND & A GND):
• These pins provide the ground for both the analog signal and the digital
signal.
• Analog ground is connected to the ground of the analog Vin.
• Digital ground is connected to the ground of the Vcc pin.
• The reason that we have two ground pins is to isolate the analog Vin signal
from transient voltages caused by digital switching of the output DO - D7.
ADC0804 interfacing with 8051
𝑽
Reference Voltage ( 𝒓𝒆𝒇ൗ𝟐):
• Pin 9 is an input 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 ( same as the 𝑉𝑐𝑐 pin).
𝑉𝑟𝑒𝑓
• If the analog input range needs to be 0 to 4 volts, ൗ2must be connected to
2 volts. 𝑽𝒓𝒆𝒇
ൗ (V) 𝑽𝒊𝒏 (V) Range Step size (mV)
𝟐
Not connected 0 to 5 5/256=19.53
2.0 0 to 4 4/256=15.62
1.5 0 to 3 3/256=11.71
1.28 0 to 2.56 2.56/256=10
1.0 0 to 2 2/256=7.81
0.5 0 to 1 1/256=3.90
ADC0804 interfacing with 8051
Analog Input (Vin (+) and Vin (-)):
• These are the differential analog inputs where Vin = Vin (+) – Vin (-).
• Often the Vin (-) pin is connected to ground and the Vin (+) pin is used as the
analog input to be converted to digital.
Chip Select (CS):
• Chip select is an active low input used to activate the ADC0804 chip.
• To access the ADC0804, this pin must be low.
ADC0804 interfacing with 8051
Write (WR-start conversion):
• This is an active low input used to inform the ADC0804 to start the
conversion process.
• If CS = 0 when WR makes a low-to-high transition, the ADC0804 starts
converting the analog input value of Vin to an 8-bit digital number.
Interrupt (INTR- actually end of conversion):
• An active low output pin.
• Normally high pin and when the conversion is finished, it goes low to inform
the CPU that the converted data is ready to be picked up.
• After INTR goes low, we make CS = 0 and send a high-to-low pulse to the
RD pin to get the data out of the ADC0804 chip.
ADC0804 interfacing with 8051
Digital Data output (D0 - D7)
• D0-D7 are the digital data output pins since ADC0804 is a parallel ADC
chip.
• 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,
𝑽𝒊𝒏
𝑫𝒐𝒖𝒕 =
𝑺𝒕𝒆𝒑 𝒔𝒊𝒛𝒆
Where, 𝐷𝑜𝑢𝑡 = 𝑑𝑖𝑔𝑖𝑡𝑎𝑙 𝑑𝑎𝑡𝑎 𝑜𝑢𝑡𝑝𝑢𝑡 (𝑖𝑛 𝑑𝑒𝑐𝑖𝑚𝑎𝑙)
𝑉𝑖𝑛 = 𝐴𝑛𝑎𝑙𝑜𝑔 𝑖𝑛𝑝𝑢𝑡 𝑣𝑜𝑙𝑡𝑎𝑔𝑒
(2×𝑉𝑟𝑒𝑓 /2)
𝑆𝑡𝑒𝑝 𝑠𝑖𝑧𝑒(𝑟𝑒𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛) = ൗ256
ADC0804 interfacing with 8051
Read (RD):
• An active low input signal used to read digital data from ADC chip.
• 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.
• When CS = 0, if a high-to-low pulse is applied to the RD pin, the 8-bit digital
output shows up at the D0 - 07 data pins.
• The RD pin is also referred to as output enable (OE).
ADC0804 interfacing with 8051
• The ADC804 can be interfaced with 8051 in two different clock signals.
• Self Clock (Internal Clock)
• To use the internal clock generator,
CLK IN and CLK R pins are
connected to a capacitor and a resistor.
• The clock frequency is determined by
1
𝑓= 1.1𝑅𝐶
• Typical values are
𝑅 = 10𝑘Ω and
𝐶 = 150 𝑝𝐹.
• We get f = 606 kHz and the conversion
time is 110 µs.
ADC0804 interfacing with 8051
• The ADC804 can be interfaced with 8051 in two different configurations.
• Clock from XTAL-2
• CLK IN pin is connected to an
external clock source i.e.
(XTAL2 pin of 8051).
• The clock from XTAL2 is too
high so, 2-5 D Flip-flops must
be used to achieve desired
clock.
*1D FF→ Divide by 2.
ADC0804 interfacing with 8051
The Steps 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 high, keep polling
until it goes low.
• If INTR is low, the conversion
is finished.
• After the INTR has become low, make CS = 0 and send a high-to-low pulse
to the RD pin to get the data out of the ADC804.
Example Program
Interface ADC0804 with 8051 microcontroller and read data by monitoring
INTR pin of ADC0804. Also convert the digital data into its ASCII
equivalent.
1/2
RD BIT P2.5 ; Define P2.5 as RD
WR BIT P2.6 ; Define P2.6 as WR
INTR BIT P2.7 ; Define p2.7 as INTR
MYDATA EQU P1 ; P1.0 to P1.7 is equated to D0-D7 of ADC
MOV MYDATA, #0FFH ; make P1 as input port
SETB INTR
Example Program
Interface ADC0804 with 8051 microcontroller and read data by monitoring
INTR pin of ADC0804. Also convert the digital data into its ASCII
equivalent.
2/2
BACK: CLR WR ;WR=0
SETB WR ;WR=l (L-to-H to start conversion)
HERE: JB INTR, HERE ;wait for end of conversion
CLR RD ;conversion finished, enable RD
MOV A, MYDATA ;read the data
ACALL CONVERSION ;hex-to-ASCII conversion
SETB RD ;make RD=l for next round
SJMP BACK
ADC0808/0809 chip with 8 analog channels
• Another useful ADC IC is ADC0808/
0809 from National Semiconductor.
• ADC 0808/ 0809 has 8 analog inputs
and allows to monitor up to 8 different
analog inputs with single chip.
• The 8 analog input channels are
multiplexed and selected according to
address pins A, B, and C.
ADC0808/0809 chip with 8 analog channels
• Another useful ADC IC is
ADC0808/ 0809 from National
Semiconductor.
• ADC 0808/ 0809 has 8 analog inputs
and allows to monitor up to 8
different analog inputs with single
chip.
• The 8 analog input channels arc
multiplexed and selected according
to address pins, A, B, and C.
ADC0808/0809 chip with 8 analog channels
• The 8 analog input channels are multiplexed and any one analog input is
selected according to state of address pins A, B, and C.
Channel C B A
IN0 0 0 0
IN1 0 0 1
IN2 0 1 0
IN3 0 1 1
IN4 1 0 0
IN5 1 0 1
IN6 1 1 0
IN7 1 1 1
ADC0808/0809 chip with 8 analog channels
• In the ADC0808/0809, 𝑽𝒓𝒆𝒇 (+) and 𝑽𝒓𝒆𝒇 (−) set the reference voltage.
5𝑉
• If 𝑽𝒓𝒆𝒇 − = 𝑮𝑵𝑫 and 𝑽𝒓𝒆𝒇 + = 𝟓𝑽, then the step size is = 19.53 𝑚𝑉.
256
• Therefore, to get a 𝟏𝟎 𝐦𝐕 step size we need to set 𝑽𝒓𝒆𝒇 + = 𝟐. 𝟓𝟔 𝑽 and
𝑽𝒓𝒆𝒇 − = 𝑮𝑵𝑫.
𝑽𝒓𝒆𝒇 (V) 𝑽𝒊𝒏 (V) Step size (mV)
Not connected 0 to 5 5/256=19.53
2.0 0 to 4 4/256=15.62
1.5 0 to 3 3/256=11.71
1.28 0 to 2.56 2.56/256=10
1.0 0 to 2 2/256=7.81
0.5 0 to 1 1/256=3.90
Interfacing ADC0808/0809 with 8051
Steps to program the ADC0808/0809:
Interfacing ADC0808/0809 with 8051
Steps to program the ADC0808/0809:
1. Select an analog channel by providing bits to A, B, and C addresses
2. Activate the ALE (address latch enable) pin. It needs an L-to-H pulse to latch
in the address.
3. Activate SC (start conversion) by an L-to-H pulse to initiate conversion.
4. 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.
5. Activate OE (output enable) to read data out of the ADC chip. An L-to-H
pulse to the OE pin will bring digital data out of the chip.
Interfacing ADC0808/0809 with 8051
Some points to remember with ADC0808/0809:
• If EOC is not used the converted digital data can be read after a brief time
delay. The delay size depends on the speed of the external clock connected to
the CLK pin.
• The EOC is the same as the INTR pin in other ADC chips.
• The OE is the same as the RD pin in other ADC chips.
• No self-clocking available in ADC0808/0809. The clock must be provided
from an external source to the CLK pin.
• Although the speed of conversion depends on the frequency of the clock
connected to the CLK pm, It cannot be faster than 𝟏𝟎𝟎 𝝁𝒔.
Interfacing ADC0808/0809 with 8051
Interfacing ADC0808/0809 with 8051
1/5
ALE BIT P2.4 ; Assign Control signals to Port pins
OE BIT P2.5
SC BIT P2. 6
EOC BIT P2. 7
ADDR_A BIT P2. 0
ADDR_ B BIT P2. 1
ADDR_ C BIT P2. 2
MYDATA EQU P1
Interfacing ADC0808/0809 with 8051
2/5
ORG 0H
MOV MYDATA, #0FFH ; make P1 an input
SETB EOC ;make EOC an input
CLR ALE ;clear ALE
CLR SC ;clear WR
CLR OE ;clear RD
Interfacing ADC0808/0809 with 8051
3/5
BACK: CLR ADDR_C ;C=0
CLR ADDR_B ;B=0
SETB ADDR_A ;A=1 (Select Channel 1)
ACALL DELAY ;make sure the address is stable
SETB ALE ;latch address
ACALL DELAY ;delay for fast DS89C4x0 Chip
SETB SC ;start conversion
ACALL DELAY
CLR ALE
CLR SC
Interfacing ADC0808/0809 with 8051
4/5
HERE: JB EOC, HERE ; waits for low pulse at EOC
HERE1: JNB EOC, HERE1 ; waits for low pulse at EOC to finish
SETB OE ;enable OE to extract Digital data
ACALL DELAY ;wait
MOV A,MYDATA ;read data
CLR OE ;clear RD for next time
ACALL CONVERSION ;hex to ASCII
ACALL DATA_DISPLAY ;display the data
SJMP BACK
Interfacing ADC0808/0809 with 8051
5/5
DELAY: MOV R3, #50
HERE2: MOV R4, #255
HERE3: DJNZ R4, HERE3
DJNZ R3, HERE2
RET
END
Interfacing ADC0808/0809 with 8051
• In recent years, for many applications where space is a critical issue,
using a large number of pins for data is not feasible.
• For this reason, serial devices such as the serial ADC are becoming
widely used.
• One of a popular and most widely used serial ADC chis is MAX1112
from Maxim Corporation.
MAX1112 interfacing with 8051
• The MAX 1112is an 8-bit serial ADC chip with
8 channels of analog input.
• Only one DOUT pin to bring out the digital data
after it has been converted.
• Compatible with a popular SPI and Microwire
serial standard.
• CH0- CH7 are 8 analog input channels.
• The COM pin is used as a ground reference for
all the channels.
MAX1112 interfacing with 8051
• In the single-ended mode, each of the
channels can be used for an analog
input.
• DIN pin is used to select desired
channel by sending control byte.
• In differential mode, we have 4 sets
of 2-channel differentials.
• CH0 and CH1 go together, and
• CH2 and CH3, and so on.
MAX1112 interfacing with 8051
CS:
• Chip select is an active low input used to select MAX 1112 chip.
• To send the control byte via the 𝑫𝑰𝑵 pin, CS must be low.
• When CS is high the 𝐷𝑂𝑈𝑇 is high impedance.
SCLK:
• Serial clock input.
• SCLK is used to bring data out and send in the control byte, one bit
at a time.
𝑫𝑶𝑼𝑻 :
• Serial data out.
• The digital data is clocked out one bit at a time on the H-to-L edge
(falling edge) of SCLK.
MAX1112 interfacing with 8051
𝑫𝑰𝑵 :
• Serial data in the control byte is clocked in one bit at a time on the L-to-
H edge (rising edge) of SCLK.
SSTRB:
• Serial strobe output.
• In internal clock mode this indicates end-of-conversion.
• It goes high when the conversion is complete.
𝑽𝑫𝑫 :
• 𝑉𝐷𝐷 is the +5 V power supply.
AGND, and DGND (analog ground and digital ground):
• Both are input pins provides ground for both the analog and the digital
signals.
MAX1112 interfacing with 8051
SHDN:
• Shutdown is an input and is normally not connected (or is connected to
𝑉𝐷𝐷 ).
• If low, the ADC is shut down to save power.
• This is shut down by hardware. The control byte causes shutdown by
software.
REFIN:
• Reference voltage input.
• This voltage dictates the step size.
REFOUT:
• Internal Reference Generator output.
• A 1μF bypass capacitor is placed between this pin and AGND.
MAX1112 interfacing with 8051
MAX 1112 control byte:
Start SEL2 SLE1 SEL0 UNI/ BIP SGL/DF PD0 PD0
• The MAX 1112 chip has 8 channels of analog inputs that arc selected
using a control byte.
• The control byte is fed serially one bit at a time (MSD first) via the 𝐷𝐼𝑁
pin with the help of SCLK.
• The MSB of the control byte is high to indicate the start of the control
byte.
Start :
• The MSB (D7) must be high to define the beginning of the control byte.
• It must be sent in first
MAX1112 interfacing with 8051
MAX 1112 control byte:
SEL2 SEL1 SEL0 Channel Selection
(Single Ended mode)
0 0 0 CH0
0 0 1 CH1
0 1 0 CH2
0 1 1 CH3
1 0 0 CH4
1 0 1 CH5
1 1 0 CH6
1 1 1 CH7
MAX1112 interfacing with 8051
MAX1112 control byte:
UNI/BIP
• 1 = unipolar: Digital data output is binary 00 - FFH.
• 0 = bipolar: Digital data output is in 2’s complement.
SGL/DIF
• 1 = single-ended: 8 channels of single-ended with COM as reference.
• 0 = differential: Two channels (e.g., CH0 - CH1) are differential.
PD1:
• 1 = fully operational.
• 0 = power-down: Power down to save power using software.
PD0
• 1 = external clock mode: The conversion speed is dictated by SCLK.
• 0 = internal clock mode: The conversion speed is dictated internally,
MAX1112 interfacing with 8051
REFIN voltage and step size:
• The step size for the MAX 1112 depends on the voltage connected REFIN
pin.
• In unipolar mode, with VDD = 5V, we get 4.096 V for full-scale if the
REFIN pin is connected to the AGND with a 1𝜇𝐹 capacitor.
• That gives us a 16-mV step size since 4.096 V/256 = 16mY.
• To get a 10-mV step size, we need to connect the REFIN pin to a 2.56 V
external voltage source, since 2.56 V/256 = 10 mV.
• According to the MAX 1112 data sheet, the external reference voltage
must be between (𝟏𝑽 𝒂𝒏𝒅 𝑽𝑫𝑫 ).
MAX1112 interfacing with 8051
MAX1112 interfacing with 8051
• The control byte is fed into the DIN pin one bit at a time using
SCLK.
• The DIN pin clocks in the control byte on the rising edge of SCLK.
MAX1112 interfacing with 8051
Start conversion and end of conversion:
• When the last bit of the control byte, PD0, is sent in, the conversion
starts, and SSTRB goes low.
• The end-of-conversion state is indicated by SSTRB going high, which
happens 𝟓𝟓 𝝁𝒔 after PD0 is clocked in.
• We can either wait 𝟓𝟓 𝝁𝒔, or monitor SSTRB before we get the digital
data out of the ADC chip.
MAX1112 interfacing with 8051
Reading out digital data:
• The 8-bit converted digital data is brought out of the MAX 1112 via the
DOUT pin using SCLK.
• Apply a negative-edge pulse to the SCLK pin, the 8-bit digital data is read
out one bit at a time with the MSB (07) coming out first.
• The SSTRB goes high to indicate that the conversion is finished.
• After SSTRB is high and the MSB appears at DOUT in the 2nd falling edge
of SCLK.
• To bring data out, CS must be low.
MAX1112 interfacing with 8051
1/4
; program to select channel and read ADC data.
CS BIT P2. 0 ; Assign control signals to Port Pins
SCLK BIT P2. 1
DIN BIT P2. 2
DOUT BIT P2. 3
ORG 000H
;Assembly code for sending in control byte in MAX1112
MAIN MOV A, #9EH ;channel 1 selection
MOV R3, #8 ;load count
CLR CS ; CS=0
CLR C
MAX1112 interfacing with 8051
2/4
H1: RLC A ;give bit to CY
MOV DIN, C ;send bit to DIN
CLR SCLK ;low SCLK for L-H pulse
ACALL DELAY ;delay
SETB SCLK ;latch data
ACALL DELAY ;delay
DJNZ R3, H1 ;repeat for all 8 bits
SETB CS ;deselect ADC, conversion starts
CLR SCLK ;SCLK=0 during conversion
SETB DOUT ;make it an input
MAX1112 interfacing with 8051
3/4
;Reading data out
CLR CS ; CS=0
SETB SCLK
ACALL DELAY ; Need some time
CLR SCLK ; first H-to-L
ACALL DLELAY ; read data out on 2nd H-to-L
CLR A
MOV R3, #8
MAX1112 interfacing with 8051
4/4
H2: SETB SCLK
ACALL DELAY ; need some time
CLR SCLK ; H-to-L pulse to get bit out
ACALL DELAY
MOV C, DOUT ; move bit to CY flag
RLC A ; bring in the bit to CY flag
DJNZ R3, H2 ; repeat for all 8 bits
SETB CS ; CS=1
MOV P1, A ; send converted data to P1
SJMP MAIN ; keep doing it
Digital-to-analog (DAC) converter
• The digital-to-analog converter (DAC) is a device widely used to
convert digital pulses to analog signals.
• The reverse operation of ADC.
Digital-to-analog (DAC) converter
• There are two types of DACs
• Weighted Resistor DAC
• R-2R Ladder DAC
• The vast majority of DACs use the R-2R ladder method since it can
achieve a much higher degree of precision.
• The first criterion in selecting a DAC is Resolution.
• Resolution is a function of the number of binary inputs.
• Commonly available resolutions are 8, 10, and 12 bits.
Digital-to-analog (DAC) converter
• The number of data bit inputs decides the resolution of the DAC since
the number of analog output levels is equal to 2𝑛 , where n is the number
of data bit inputs.
• An 8-input DAC such as the DAC0808 provides (28 = 256) discrete
voltage (or current) levels of output.
• Similarly, the 12-bit DAC provides 4096 discrete voltage levels.
• There are also 16-bit DACs, but they are more expensive.
MC1408 DAC (or DAC0808)
• The DAC 0808 DAC is a 16 pin IC converts the digital inputs in to
analog signal. The pin details are
Pin No. Name Description
1 NC No Connection
2 GND Ground
3 VEE Negative power Supply
4 IO Current (I) output
5-12 A1 (MSB)-A8 (LSB) Digital Input Bits
13 VCC Positive power supply
14 VREF+ Positive reference voltage
15 VREF- Negative reference voltage
16 Compensation Compensation capacitor
MC1408 DAC (or DAC0808)
• The DAC 0808 DAC converts the digital inputs in to equivalent current
𝑰𝒐𝒖𝒕 .
• The output current 𝑰𝒐𝒖𝒕 is a function of the binary inputs at the A0 - A7
pins of DAC and reference current 𝑰𝒓𝒆𝒇 .
𝐴7 𝐴6 𝐴5 𝐴4 𝐴3 𝐴2 𝐴1 𝐴0
𝐼𝑜𝑢𝑡 = 𝐼𝑟𝑒𝑓 + + + + + + + (1)
2 4 8 16 32 64 128 256
• Where A0 is the LSB, A7 is the MSB for the inputs, and
• 𝑰𝒓𝒆𝒇 is the reference current applied at pin 14.
• The reference current is generally, 2.0 mA.
MC1408 DAC (or DAC0808)
• The 𝑰𝒐𝒖𝒕 pin must be connected with a resistor to convert the current into
equivalent voltage.
• But in real life it may cause
inaccuracy since the input
resistance of the load will also
affect the output voltage.
• So practically Iref current input
is isolated by connecting it to
an Op-Amp with Rf = 5KΩ as
feedback resistor.
• The feedback resistor value can
be changed as per requirement.
MC1408 DAC (or DAC0808)
• The output voltage is
𝑣0 = 𝐼𝑜𝑢𝑡 × 𝑅𝑓 (2)
• The Maximum output current (Reference current) is
𝑉𝑟𝑒𝑓
𝐼𝑟𝑒𝑓 = ൗ𝑅14 (3)
• Suppose 𝑉𝑟𝑒𝑓 = 5 𝑉 and 𝑅14 = 2.5 𝑘Ω, then
5
𝐼𝑟𝑒𝑓 = = 2 𝑚𝐴 (4)
2.5𝑘
• Therefore, the maximum current is
𝐼0 𝑚𝑎𝑥 = 2𝑚 𝐴 (5)
• And the maximum output voltage is
𝑉0 𝑚𝑎𝑥 = 2𝑚 × 2.5𝑘 = 5𝑉
• For 𝑅𝑓 = 5𝑘Ω, then 𝑉0 𝑚𝑎𝑥 = 2𝑚 × 5𝑘 = 10𝑉 (6)
MC1408 DAC (or DAC0808)
• If binary input (A1 A2 A3 A4 A5 A6 A7 A8) = 11111111, then
Io = 5/2.5K * (1/2 + 1/4 + 1/8 + 1/16 + 1/32 + 1/64 + 1/128 + 1/256)
Io = 5/2.5K * (255/256) ~ 2 mA
• If binary input (A1 A2 A3 A4 A5 A6 A7 A8) = 10000000, then
Io = 5/2.5K * (1/2 + 0/4 + 0/8 + 0/16 + 0/32 + 0/64 + 0/128 + 0/256)
Io = 5/2.5K * (1/2) ~ 1 mA
• If binary input (A1 A2 A3 A4 A5 A6 A7 A8) = 00000000, then
Io = 5/2.5K * (0/2 + 0/4 + 0/8 + 0/16 + 0/32 + 0/64 + 0/128 + 0/256)
Io = 5/2.5K * (0) ~ 0mA
MC1408 DAC (or DAC0808)
• The conversion table of ADC is
Binary input Output Io (mA) Output Vo
Rf=2.5 kΩ
00H 0 0V
01H 0.0078 19.5 mV
03H 0.02343 58.5 mV
7FH 1 2.5 V
FFH 2 5V
Example problem-1
Generate a stair-step ramp signal using DAC 0808 by giving digital data
from port 0 of 8051.
Example problem-1
Generate a stair-step ramp signal using DAC 0808 by giving digital data
from port 1 of 8051.
AGAIN: CLR A
MOV P0, A ;send data to DAC
INC A ;count from 0 to FFH
ACALL DELAY ;let DAC recover
SJMP AGAIN
DELAY: MOV R7, #0FFH ; delay generation
L1: DJNZ R7, L1
RET
Example problem-2
Generate a square wave signal using DAC 0808 by giving digital data from
port 0 of 8051.
AGAIN: MOV P0, #0FFH ;send data to DAC
ACALL DELAY ;let DAC to repeat ‘5V’
MOV P0, #00H ;send data to DAC
ACALL DELAY ;let DAC to repeat ‘0V’
SJMP AGAIN
DELAY: MOV R7, #0FFH ; delay generation
L1: DJNZ R7, L1
RET
Example problem-3
Generate the stairs wave form as shown in figure using DAC 0808 by giving
digital data from port 1 of 8051.
Example problem-3
AGAIN: MOV P1, #00H ;send data to DAC
ACALL DELAY ;let DAC to repeat ‘0V’
MOV P1, #7FH ;send data to DAC
ACALL DELAY ;let DAC to repeat ‘2.5V’
MOV P1, #0FFH ;send data to DAC
ACALL DELAY ;let DAC to repeat ‘5V’
ACALL DELAY ;let DAC to repeat ‘5V’
MOV P1, #7FH ;send data to DAC
ACALL DELAY ;let DAC to repeat ‘2.5V’
SJMP AGAIN
Example problem-3
DELAY: MOV R7, #0FFH ; delay generation
L1: DJNZ R7, L1
RET
Generating Sine wave using DAC
• The equation of sine wave is
𝑽𝒐𝒖𝒕 = 𝑨 𝐬𝐢𝐧 𝜽 (1)
• The sine function varies from -1 to
+1.
• And A is the Amplitude/magnitude
of the sine wave.
• With DAC we can generate only
positive side only (0 to 5V or 10V).
• Therefore, DAC with full scale
𝑽𝒐𝒖𝒕 = 𝟓𝑽 + (𝟓 × 𝐬𝐢𝐧 𝜽) (2)
output of 10V with +5 V Offset can
be used.
Generating Sine wave using DAC
• To generate sine wave using DAC, a look-up table to represent the
magnitude of the sine value for angles between 0° to 360° must be
created.
• Increment the angle by 30° and calculate the HEX values required for
DAC input.
• In the table only integer values are applicable for DAC input.
𝑽𝒐𝒖𝒕 = 𝟓𝑽 + (𝟓 × 𝐬𝐢𝐧 𝜽) (2)
Generating Sine wave using DAC
Angle(θ) sinθ Vout (V) Values sent to DAC
Decimal Hex
0 0 5 128 80
30 0.5 7.5 192 C0
60 0.866 9.33 238 EE
90 1.0 10 255 FF
120 0.866 9.33 238 EE
150 0.5 7.5 192 C0
180 0 5 128 80
210 -0.5 2.5 64 40
240 -0.866 0.669 17 11
270 -1.0 0 0 0
300 -0.866 0.669 17 11
330 -0.5 2.5 64 40
360 0 5 128 80
Generating Sine wave using DAC
• The output from the port of 8051 and DAC looks like
Generating Sine wave using DAC
• In an 8-bit DAC like 0808, if the full-scale output voltage 𝑉𝑜𝑢𝑡 = 10 𝑉
then the steps per voltage is
256Τ = 25.6 𝑠𝑡𝑒𝑝𝑠/𝑣𝑜𝑙𝑡𝑠 (1)
10
• So, multiplying 𝑉𝑜𝑢𝑡 with 25.6 gives the DAC decimal value.
• Using the lookup table , the DAC continuously (in an infinite loop) to
produce a crude sine wave.
• A low pass filter (LPF) may be used to smooth the waveform.
Generating Sine wave using DAC
Generating Sine wave using DAC
AGAIN: MOV DPTR, #TABLE ;load address of LUT
MOV R2, #COUNT ; give No. of values in LUT
BACK: CLR A ; clear accumulator
MOVC A, @A+DPTR ; copy values from LUT
MOV P1, A ; give a copy to Port 1
INC DPTR ; increment DPTR
DJNZ R2, BACK ; check for zero in counter
SJMP AGAIN ; keep doing
ORG 300H
TABLE DB 128, 192, 238, 255, 238, 192, 128, 64, 17, 0, 17, 64, 128.
Example problem-4
Write an 8051 ALP to generate Full wave rectifier output waveform using
DAC0808.
Example problem-4
AGAIN: MOV DPTR, #TABLE ;load address of LUT
MOV R2, #COUNT ; give No. of values in LUT
BACK: CLR A ; clear accumulator
MOVC A, @A+DPTR ; copy values from LUT
MOV P1, A ; give a copy to Port 1
INC DPTR ; increment DPTR
DJNZ R2, BACK ; check for zero in counter
SJMP AGAIN ; keep doing
ORG 300H
TABLE DB 128, 192, 238, 255, 238, 192.
Example problem-5
Write an 8051 ALP to generate half wave rectifier output waveform using
DAC0808.
Example problem-5
AGAIN: MOV DPTR, #TABLE ;load address of LUT
MOV R2, #COUNT ; give No. of values in LUT
BACK: CLR A ; clear accumulator
MOVC A, @A+DPTR ; copy values from LUT
MOV P1, A ; give a copy to Port 1
INC DPTR ; increment DPTR
DJNZ R2, BACK ; check for zero in counter
ACALL DELAY
SJMP AGAIN ; keep doing
Example problem-5
DELAY: MOV R5, #0FFH
L2: DJNZ R5, L2
RET
ORG 300H
TABLE DB 128, 192, 238, 255, 238, 192..
Example problem-6
Write an 8051 ALP to generate Ramp/ Sawtooth waveform using DAC0808.
AGAIN: CLR A ; clear accumulator
BACK: MOV P1, A ; give a copy to Port 1
INC A ; increment DPTR
CJNE A, #0FFH, BACK ; check for max. value
SJMP AGAIN ; keep doing
Example problem-7
Write an 8051 ALP to generate triangular waveform using DAC0808.
Example problem-7
Write an 8051 ALP to generate triangular waveform using DAC0808.
AGAIN: CLR A ; clear accumulator
BACK1: MOV P1, A ; give a copy to Port 1
INC A ; increment Accumulator
CJNE A, #0FFH, BACK1 ; check for max. value
BACK2: MOV P1, A ; give a copy to Port 1
DEC A ; decrement Accumulator
CJNE A, #00H, BACK2 ; check for min. value
SJMP AGAIN ; keep doing
Sensor Interfacing and Signal Conditioning
• Transducers convert physical data such as
• Temperature, Light intensity,
• Water level, pH level,
• Moisture, Humidity and
• Speed into electrical signals.
• Depending on the transducer, the output produced is in the form of
• Voltage,
• Current,
• Charge,
• Resistance, or
• Capacitance.
Sensor Interfacing and Signal Conditioning
For example:
• Temperature is converted in to electrical
signals using a transducer called a Temperature (°𝐶) Resistance (𝑘Ω)
thermistor. 0 29.49
• A thermistor responds to temperature 25 10.0
change by changing resistance, but its 50 3.893
response is not linear. 75 1.7
• More complex to interface with software- 100 0.817
based systems due to non-linearity.
• So, linear transducers became popular.
Sensor Interfacing and Signal Conditioning
LM34 and LM35 temperature sensors:
• Most widely used linear temperature sensors include the
LM34 and LM35 series from National Semiconductor
Corp.
• The sensors of the LM34 series are precision integrated-
circuit temperature sensors whose output voltage is
linearly proportional to the Fahrenheit temperature.
• No external calibration is required since it is internally
calibrated.
• It outputs 10 mV for each degree of Fahrenheit
temperature.
Sensor Interfacing and Signal Conditioning
LM34 series temperature sensor selection guide:
Part scale Temperature Range Accuracy Output
LM34A -50 F to +300 F +2.0 F 10mV/F
LM34 -50 F to +300 F +3.0 F 10mV/F
LM34CA -40 F to +230 F +2.0 F 10mV/F
LM34C -40 F to +230 F +3.0 F 10mV/F
LM34D -32 F to +212 F +4.0 F 10mV/F
Sensor Interfacing and Signal Conditioning
LM35 temperature sensors:
• The sensors of the LM35 series are precision integrated-
circuit temperature sensors whose output voltage is
linearly proportional to the Celsius temperature.
• No external calibration is required since it is internally
calibrated.
• It outputs 10 mV for each degree of Celsius temperature.
Sensor Interfacing and Signal Conditioning
LM35 series temperature sensor selection guide:
Part scale Temperature Range Accuracy Output
LM35A -55 °𝐶 to +150 °𝐶 +1.0 °𝐶 10mV/°𝐶
LM35 -55 °𝐶 to +150 °𝐶 +1.5 °𝐶 10mV/°𝐶
LM35CA -40 °𝐶 to +110 °𝐶 +1.0 °𝐶 10mV/°𝐶
LM35C -40 °𝐶 to +110 °𝐶 +1.5 °𝐶 10mV/°𝐶
LM35D 0 °𝐶 to +100 °𝐶 +2.0 °𝐶 10mV/°𝐶
Signal Conditioning
• The most common transducers produce an output in the
form of voltage, current, temperature, charge,
capacitance, and resistance.
• These signals must be converted in to voltage as the
input to an ADC is voltage.
• The output of ADC is given to 8051 for further
programming.
Signal Conditioning
• These conversion (modification) is commonly 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 use in an ADC.
Signal Conditioning
Connecting LM35 to an ADC0804:
• The ADC0804 has 8-bit resolution with a maximum of 256 (𝟐𝟖 ) steps.
• The LM35 (or LM34) produces 𝟏𝟎 𝒎𝑽 for every degree of temperature
change.
• To produce 10mV for each degree rise in temperature, the 𝑉𝑖𝑛 of the
ADC0804 must be conditioned to produce a 𝑽𝒐𝒖𝒕 of 𝟐𝟓𝟔𝟎 𝒎𝑽 2.56𝑉 as
full-scale output.
• Therefore, a 𝑽𝒓𝒆𝒇 = 𝟐. 𝟓𝟔 𝑽 is required to produce full scale output
of 2.56𝑉.
• Above conditioning makes 𝑉𝑜𝑢𝑡 of the ADC0808 correspond directly to
the temperature as monitored by the LM35.
Signal Conditioning
Connecting LM35 to an ADC0804:
• 10mV for each degree rise in temperature.
Temperature (°𝐶) 𝑉𝑖𝑛 𝑚𝑉 𝑉𝑜𝑢𝑡 (𝐷7 − 𝐷0 )
0 0 0000 0000
1 10 0000 0001
2 20 0000 0010
3 30 0000 0011
10 100 0000 1010
30 300 0001 1110
LM35 Sensor Interfacing and Signal Conditioning
LM35 Sensor Interfacing and Signal Conditioning
• In the interfacing of LM35 to 8051 using ADC0804 uses LM336-2.5
zener diode to fix the voltage across the 10 𝑘𝛺 pot at 2.5 volts.
• The use of the LM336 -2.5 avoids any fluctuations in the power
supply.
LM35 Sensor Interfacing and Signal Conditioning
;Assembly code to read temperature, convert it, 1/4
;and put it on P0 with some delay
RD BIT P2.5 ; Read
WR BIT P2.6 ; WR (Start conversion)
INTR BIT P2.7 ; end of conversion
MYDATA EQU P1 ; Pl.0-P1.7;D0-D7 of the ADC0804
MOV MYDATA, #0FFH ; make P1 as input
SETB INTR
LM35 Sensor Interfacing and Signal Conditioning
BACK: CLR WR ; WR=0 2/4
SETB WR ; WR=1 (L-to-H to start conversion)
HERE: JB INTR, HERE ;wait for end of conversion
CLR RD ;conversion finished, enable RD
MOV A, MYDATA ;read the data from ADC0804
ACALL CONVERSION ;hex-to-ASCII conversion
ACALL DATA_DISPLAY ;display the data
SETB RD ;make RD=1 for next round
SJMP BACK
LM35 Sensor Interfacing and Signal Conditioning
CONVERSION: 3/4
MOV B, #10
DIV AB
MOV R7, B ;least significant byte
MOV B, #10
DIV AB
MOV R6, B
MOV R5, A ;most significant byte
RET
LM35 Sensor Interfacing and Signal Conditioning
DATA_DISPLAY: 4/4
MOV P0, R7
ACALL DELAY
MOV P0, R6
ACALL DELAY
MOV P0, R5
ACALL DELAY
RET
DELAY: MOV R7, #0FFH ; delay generation
L1: DJNZ R7, L1
RET
Summary
• I/O Interfacing of 8051
• Analog to Digital Converter (ADC)
• ADC0804
• ADC0808/09
• MAX1112
• Digital to Analog Converter (DAC)
• MC1408 (DAC0808)
• Waveform generation
• Sensor Interfacing and Signal conditioning
• LM 34/ LM35 Temperature sensor interfacing with 805.1