Dept. of Electronics & Telecommunication engg.
Microcontrollers
Unit-3
Interfacing of DAC with 8051:
Digital-to-analog conversion is a process in which signals having a few (usually two)
defined levels or states are converted into signals having a theoretically infinite number of
states. A common example is the processing, of computer data into audio-frequency (AF) tones
that can be transmitted over a twisted pair by a modem of computer data telephone line. The
circuit that performs this function is a digital-to-analog converter (DAC).
The digital to analog converter is a device widely used to convert digital pulses to analog
signals. The two methods of creating DAC are binary weighted and R-2R ladder. DAC 0808 uses
the R-2R method since it can achieve a high degree of precision. The first criterion for judging a
DAC is its resolution, which is the 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 inputs. DAC 0808
provides 256 discrete voltage or current levels of output. In DAC 0808, the digital inputs are
converted into current Iout and by connecting a resistor to Iout pin, we convert the result to
voltage.
The total current provided by IOUT pin is a function of binary numbers at the D0-D7
pins inputs to DAC 0808 and reference current (Iref) is as follows:
Iout=Iref ( + + + + + + + )
Where D0 is the LSB, D7 is the MSB for the inputs and Iref is the input current that must be
applied.
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad
Dept. of Electronics & Telecommunication engg. Microcontrollers
Program to generate Triangular Wave
ORG 0000H
MOV A, #00H
RISE: MOV P1, A
INC A
CJNE A, #0FFH, RISE
FALL: MOV P1, A
DEC A
CJNE A, #00H, FALL
SJMP RISE
END
Program to generate Sine Wave:
Angle in Degrees Sin(Ɵ) Count= Count×256/5
(Ɵ) 2.5+(2.5×sinƟ)
0 0 2.5 128
30 0.500 3.75 192
60 0.866 4.66 239
90 0.999 4.99 256
120 0.865 4.66 239
150 0.499 3.74 192
180 0.001 2.49 128
210 0.501 1.24 64
240 0.866 0.33 17
270 0.999 0.002 0
300 -0.864 0.337 17
330 0.497 1.255 64
360 0.0025 2.506 128
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad
Dept. of Electronics & Telecommunication engg. Microcontrollers
ORG 0000H
MOV R0, #30H ;Starting Address
; Store the Calculated Values on address from
30H
MOV @R0, #128
INC R0
MOV @R0, #192
INC R0
MOV @R0, #239
INC R0
MOV @R0, #256
INC R0
MOV @R0, #239
INC R0
MOV @R0, #192
INC R0
MOV @R0, #128
INC R0
MOV @R0, #64
INC R0
MOV @R0, #17
INC R0
MOV @R0, #0
INC R0
MOV @R0, #17
INC R0
MOV @R0, #64
MOV R0, #30H
HERE: MOV P1,@R0
INC RO
CJNE R0, #3CH, HERE
MOV R0,#30H
SJMP HERE
END
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad
Dept. of Electronics & Telecommunication engg. Microcontrollers
Interfacing of Temp. sensor LM35 and LCD with 8051
via ADC 0808.
We are using 8051 microcontroller which comes with 4 KB internal Flash
memory. The microcontroller has 4 I/O Ports.
Also, we are using LM35 Temperature sensor with 10 mA/0C output. Let the
signal conditioning Instrumentation Amplifies be used so as to amplify 0-5 V for
this range.
ADC 0808 is used to convert the analog voltage (measured temp.) to the
corresponding digital value. The Reference voltage V+ is kept at 5V. negative
reference is kept at 0V(ground). This would give us digital value of temp. to be
00H(for 0 0C) to 64H(for 100 0C) the circuit is fined tuned to achieve this
calibration.
The ADC is connected to Port 1 of 8051 and P3.1, P3.2, P3.3 being channel
selection pins A,B, and C Respectively. Also, P3.4, P3.5, P3.6 and P3.7 being used
as ALE, SOC, EOC and OE pins of ADC.
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad
Dept. of Electronics & Telecommunication engg. Microcontrollers
A LCD is connected to show the temperature output on display. The LCD is
interfaced to Port 0 (LCD Data) and P2.0, P2.1, P2.2 for RS, R/W and EN
Respectively.
The Stepwise operation logic is:
1. Initialize Stack
2. Initialize LCD Display
3. Start ADC Conversion
4. If EOC=0 then wait else proceed
5. Receive ADC Temperature Data
6. Convert the Data into it’s AASCII Equivalent
7. Send Data to LCD For Display
8. Go to step 3 and repeat
9. End
Program:
SEL_A EQU P3.1
SEL_B EQU P3.2
SEL_C EQU P3.3
ALE EQU P3.4
START EQU P3.5
EOC EQU P3.6
OE EQU P3.7
ADC_DATA EQU P1
RS EQU P2.0
RW EQU P2.1
EN EQU P2.2
ORG 0000H
MOV A, #02H
ACALL CMD
MOV A, #38H
ACALL CMD
MOV A,#0EH
ACALL CMD
MOV A,#01H
ACALL CMD
MOV A,#06H
ACALL CMD
MOV A,#80H
ACALL CMD
MOV ADC_DATA, #0FFH ;DATA PORT TO INPUT
SETB EOC ;EOC AS INPUT
CLR ALE
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad
Dept. of Electronics & Telecommunication engg. Microcontrollers
CLR OE
CLR START ;REST OF OUTPUT SIGNALS
MAIN:
MOV A,#80H
ACALL CMD
SETB SEL_A
CLR SEL_B
CLR SEL_C ;SELECT ANALOG CHANNEL 1
SETB ALE ;LATCH CHANNEL SELECT
SETB START ;START CONVERSION
CLR ALE
CLR START
HERE: JB EOC, HERE ;WAIT FOR END OFCONVERSION
HERE1:JNB EOC, HERE1
SETB OE ;ASSERT READ SIGNAL
MOV A, ADC_DATA ; READ DATA IN ACCUMULATOR
CLR OE ;START OVER FOR NEXT CONVERSION
MOV B,#256
DIV A,B
MOV B,#50
MUL AB
MOV B,#10
MUL AB
MOV R1,A
ANL A,#11110000B
SWAP A
MOV B,#30H
ADD A,B
ACALL DISP
MOV A,R1
ANL A,#00001111B
MOV B,#30H
ADD A,B
ACALL DISP
MOV A,#83H
ACALL CMD
MOV A,#"C"
ACALL DISP
SJMP MAIN
CMD:
ACALL INIT
MOV P0,A
CLR RS
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad
Dept. of Electronics & Telecommunication engg. Microcontrollers
CLR RW
SETB EN
CALL DELAY
CLR EN
RET
DISP:
ACALL INIT
MOV P0,A
SETB RS
CLR RW
SETB EN
ACALL DELAY
CLR EN
RET
;POLLING FUNCTION
INIT:
CLR EN
CLR RS
MOV P1, #0FFH
SETB RW
L1: SETB EN
JB P1.7, L1
CLR EN
DELAY: MOV R3, #10
L1: MOV R4, #250
L2: DJNZ R4, L2
DJNZ R3, L1
RET
END
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad
Dept. of Electronics & Telecommunication engg. Microcontrollers
Interfacing of Stepper-Motor:
A stepper motor is a brushless and synchronous motor which divides the
complete rotation into number of steps. Each stepper motor will have some fixed
step angle and motor rotates at this angle.
The main principle of this circuit is to rotate the stepper motor step wise at a
particular step angle. The ULN2003 IC is used to drive the stepper motor as the
controller cannot provide current required by the motor.
The circuit consists of AT8051 microcontroller, ULN2003A, Motor.
The ULN2003A is a current driver IC. It is used to drive the current of the
stepper motor as it requires more than 60mA of current. It is an array of
Darlington pairs. It consists of seven pairs of Darlington arrays with common
emitter. The IC consists of 16 pins in which 7 are input pins, 7 are output pins
and remaining are VCC and Ground. The first four input pins are connected to the
microcontroller. In the same way, four output pins are connected to the stepper
motor.
Stepper motor has 56 pins. In these six pins, 1 pin in connected to the supply of
12V and the remaining are connected to the output of the stepper motor. Stepper
rotates at a given step angle. Each step in rotation is a fraction of full cycle. This
depends on the mechanical parts and the driving method
There are different methods to drive a stepper motor. Some of these are
explained below.
Full Step Drive: In this method two coils are energized at a time. Thus, here two
opposite coils are excited at a time.
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad
Dept. of Electronics & Telecommunication engg. Microcontrollers
Half Step Drive: In this method coils are energized alternatively. Thus it rotates
with half step angle. In this method, two coils can be energized at a time or single
coil can be energized.
Stepper Motor Controller Circuit Advantages:
It consumes less power.
It requires low operating voltage
Stepper Motor Control Applications:
This circuit can be used in the robotic applications.
This can also be used in mechatronics applications.
The stepper motors can be used in disk drives, matrix printers, etc.
Example:
Write a Program to rotate a motor 117o in clockwise direction. The motor has step
angle of 1.80
Solution:
• 1 step = 1.80
• Steps= 1170
• X= =65
• 65 steps are to be given to stepper motor.
Step Coil1 Coil2 Coil3 Coil4 Hex
1 I I 0 0 0CH
2 0 I I 0 06H
3 0 0 I I 03H
4 I 0 0 I 09H
Program:
ORG 0000H
MOV R0, #30H ;Starting Address
; Store the Calculated Values on address from 30H
MOV @R0, #0CH
INC R0
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad
Dept. of Electronics & Telecommunication engg. Microcontrollers
MOV @R0, #06H
INC R0
MOV @R0, #03H
INC R0
MOV @R0, #09H
MOV R0, #30H
MOV R1,#65
HERE: MOV P1,@R0
INC RO
DJNZ R1, NXT
SJMP LAST
NXT: CJNE R0, #33H, HERE
MOV R0,#30H
SJMP HERE
LAST:
END
Interfacing of Motion Detectors with 8051:
Motion Detector Sensors:
Passive Infrared (PIR)
MircoWave (MW)
Area Reflective Type(IR)
Ultrasonic
Vibration
Passive InfraRed(PIR) sensors are widely used for motion detection for intruder
alarm systems.
The PIR sensors measure the infrared energy radiated by the object that is
placed infront of it.
PIR sensors are made up of pyro-electric material that generates energy when it
is exposed to radiation. Gallium Nitride is the commonly used pyro-electric
material. The energy is converted to equivalent output voltage.
The output of PIR sensor will be high when it detects motion and low when there
is no motion.
Fig. below shows interfacing of PIR sensor to 8051. If the output of PIR sensor is
high i.e. motion is detected the LED connected to P2.3 will witch ON. If no
motion is detected the output of PIR sensor will be low and LED will switch OFF.
The transistor Q is used for switching LED. The 100 ohm resistor limits the base
current.
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad
Dept. of Electronics & Telecommunication engg. Microcontrollers
Program:
PIR EQU P2.4
LED EQU P2.3
ORG 0000H
L1: JNB PIR, L1
SETB LED
L2: JB PIR, L2
CLR LED
SJMP L1
END
Interfacing Relay with 8051:
A relay is an electrical switch that opens and closes under the control of another
electrical circuit. In the original form, the switch is operated by an electromagnet
to open or close one or many sets of contacts.
It consists of a coil of wire surrounding a soft iron core, an iron yoke, which
provides a low reluctance path for magnetic flux, a movable iron armature, and
set or sets of contacts.
The armature is hinged to the yoke and mechanically linked to a moving contact
or contacts. It is held in place by a spring so that when the relay is de-energized
there is an air gap in the magnetic circuit. In this condition, one of the two sets of
contacts in the relay is closed, and the other set is open.
When an electric current is passed through the coil, the resulting magnetic field
attracts the armature, and the consequent movement of the movable contact
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad
Dept. of Electronics & Telecommunication engg. Microcontrollers
breaks a connection with a fixed contact and makes connection with the other
contact.
Fig shows the symbol of the relay and interfacing of the relay with 8051. Simply
making pin ‘1’ or ‘0’ will switch ON/OFF the relay.
Interfacing Opto-isolator with 8051:
An Opto-isolator is a device that uses a short optical transmission path to
transfer a signal between elements of a circuit, typically a transmitter and a
receiver, while keeping them electrically isolated since the signal goes from an
electrical signal to an optical signal back to an electrical signal, electrical contact
along the path is broken.
The solid state relay has an opto-isolator at its input as shown in fig.
The LED at the input triggers the transistor, optically and hence no electrical
path exists between the LED and transistor.
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad
Dept. of Electronics & Telecommunication engg. Microcontrollers
Data Acquisition System:
Data acquisition is the process of sampling signals that measure real world
physical conditions and converting the resulting samples into digital numeric values
that can be manipulated by a computer. Data acquisition systems, abbreviated by the
acronyms DAS or DAQ, typically convert analog waveforms into digital values for
processing.
The components of data acquisition systems include:
Sensors, to convert physical parameters to electrical signals.
Signal conditioning circuitry, to convert sensor signals into a form that can be
converted to digital values.
Analog-to-digital converters, to convert conditioned sensor signals to digital values.
1. Transducer/Sensor:-
A transducer is used to convert the physical parameters corning from the field into
electrical signals or it is used to measure directly the electrical quantities such as
resistance, voltage, frequency, etc.
Sensor Phenomenon
Thermocouple, RTD, Thermistor Temperature
Photo Sensor Light
Microphone Sound
Strain Gage, Piezoelectric Transducer Force and Pressure
Potentiometer, LVDT, Optical Encoder Position and Displacement
Accelerometer Acceleration
pH Electrode pH
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad
Dept. of Electronics & Telecommunication engg. Microcontrollers
2. Signal Conditioner:-
Usually the output signals of the transducer will be of very low level (weak) signals
which cannot be used for further processing. In order to make the signals strong enough
to drive the other elements signal conditioners are used such as amplifiers, modifiers,
filters etc.
3. A/D Converter:-
The analog-to-digital (A/D) converter is generally used to convert the analog
data into digital form. The digital data is used for the purpose of easy processing,
transmission, digital display and storage.
Processing involves various operations on data such as comparison, mathematical
manipulations, data is collected, converted into useful form and utilized for various
purposes like for control operation and display etc.
The transmission of data in digital form is possible over short distances as well as long
distances of and has advantages over transmission in analog form. The data can be
stored permanently or temporarily and can be displayed on a CRT or digital panel.
Objectives of DAS:
1. It must acquire essential data at correct speed and correct time.
2. The data acquired must be efficiently used so that the operator knows the state
of the system.
3. In order to maintain an online optimum and safe operation of the system, the
system must be continuously monitored.
4. The data acquisition system must be able to collect, summarise and store the
data for the diagnosis of operation and record purpose.
5. An effective human system needs to be provided by the data acquisition system.
It must be able to identify the problem areas, thereby minimizing the unit
availability.
6. It must be reliable
7. It must be flexible.
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad
Dept. of Electronics & Telecommunication engg. Microcontrollers
Frequency Counter Design:
What is frequency? It is the number of cycles per second made by the signal. This
is the core principle used in every frequency measuring projects and we did the same.
The 8051 microcontroller comes equipped with two inbuilt timers- timer 0 and timer 1,
both of which are configured to be used for different purpose.
The first timer 0 is employed to sample the input signal and is fixed at a single
second delay. Talking about the other one; timer 1, it represents a counter that keeps
record of number of cycles covered in a single second delay. Considering the case of
overflow, another register is assigned to handle that situation. The overflow register is
also termed as high byte of frequency since it holds higher value of frequency.
Pin P3.5/T1 (pin 9) which is timer 1 external input pin of microcontroller,
fetches input signal as it is applied at that port. The port 1 of microcontroller is used to
interface LCD in 4-bit mode for this project. Here we have used 2-line LCD. However,
this project can also be used along with a single line LCD with proper configuration.
On the course of programming, timer 0 is initialized in 16-bit mode with 50 mS delay
value.
A tick value of 20 is programmed to be equal to total delay of 1s (50 x 20 = 1000
mS). Timer 1 in counter mode is programmed in 16-bit mode. During first 1 second
delay, sample of input signal is extracted and timer 1 calculates the number of cycles
and hence the frequency of input signal is determined and high byte of frequency if
recorded. Frequency is stored as TH1:TL1. In total 3 bytes value is obtained which is
then converted into a decimal equivalent represented in hex. This result is displayed on
LCD and same process repeats again and again unless the signal is sampled completely
and frequency is calculated.
SNJB’s Late Sau K. B. Jain College of engineering, Chandwad