report on ultrasonic distance meter
DESCRIPTION
this is afinl report for the engineering guys for threre report refernceTRANSCRIPT
VIVEKANAND EDUCATION SOCIETY’S POLYTECHNIC
CHEMBUR, MUMBAI- 400071
PROJECT REPORT
ON
MICROCONTROLLER BASED ULTRASONIC DISTANCE METER
SUBMITTED BY
RAHUL DIVE
SANA DONGARE
MAHESH JADHAV
PRIYANKA KADAM.
UNDER THE GUIDANCE OF
MRS. ALKA PRAYAGKAR
IN PARTIAL FULFILLMENT OF THE REQUIREMENT OF THE DIPLOMA
IN
INDUSTRIAL ELECTRONICS
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
ACADEMIC YEAR 2012- 2013
1
VIVEKANAND EDUCATION SOCIETY’S
POLYTECHNIC
SINDHI SOCIETY, CHEMBUR, MUMBAI- 400071
CERTIFICATE
This is to certify that Mr ______________________________________________
Has satisfactorily carried out project work entitled “
“In partial fulfilment of the diploma in INDUSTRIAL ELECTRONICS of Maharashtra State Board of Technical Education Academic Year 2012- 2013
Principal Head of Department
Project Guide Examiner
2
ACKNOWLEDGEMENT
It is indeed a matter of great pleasure and proud privilege to be able to
present this project on “MICROCONTROLLER BASED ULTRASONIC
DISTANCE METER “.
The completion of the project work is a millstone in student’s life and its
execution is inevitable in the hands of guide . We are highly indebted the
project guides Mrs. Alka Prayagkar for his invaluable guidance and
appreciation.
We would like to tender our sincere thanks to all the staff members for
their co-operation. We would also like to express our deep regards and
gratitude to the principal Prof.V.B.Joshi .
Really it is highly impossible to repay the debt of all the people who have
directly or indirectly helped us for performing the project.
3
PREFACE
We take an opportunity to present this project report on
“MICROCONTROLLER BASED ULTRASONIC DISTANCEMETER”
and put before readers some useful information regarding our project.
We have made sincere attempts and taken every care to present this matter
in precise and compact form , the language being as simple as possible .
We are sure that the information contained in this volume would certainly
prove useful for better insight in the scope and dimension of this project in
its true perspective .
The task of completion of the project though being difficult was made quite
simple, interesting and successful due to involvement and dedication of
our group members .
ABSTRACT
4
The microcontroller based Ultrasonic distance meter or Ultrasonic proximity meter is a
non contact and non loading displacement measuring device. This device can be used to
even large displacement with pin point accuracy.
The heart of this distance meter is the microcontroller AT89C2051. This system
potentially has very large applications not only in various industries, the luxury
automobile sector but also in the armed force where accuracy and durability is of primary
importance.
5
TABLE OF CONTENTS
Abstract
List of figures
1: Introduction
2: Ultrasonic Principles
3: Basic Block Diagram
4: Circuit Diagram & Description
5: PCB Layout
6: Various Components involved in the circuit
7: Flow chart
8: Assembly Language Program
9: Applications of ultrasonic distance meter
10: Conclusion and future scope
11: Reference
6
CHAPTER-1
INTRODUCTION
There are several ways to measure distance. Ultrasonic distance meter is one such non
contact method, it measures distance without any mechanical coupling with the object
and is hence non loading as well.
The heart of the circuit is the microcontroller AT89C2051. The microcontroller based
Ultrasonic distance meter consists of 6 major components other than the microcontroller
itself, the 40Khz ultrasonic transmitter, 40Khz Ultrasonic receiver , CD4049 Fairchild
Hex inverting buffer, LM324 Low power quad operational-amplifier, ULN2003 current
buffer and four LTS542 common anode seven segment display.
The microcontroller is used to generate 40 kHz sound pulses. These sound pulses are
used to excite the ultrasonic transmitter thereby transmitting these waves, and expect an
echo from the object whose distance is to be measured.
These waves travels to the object in the air and is reflected back when they fall on the
object, this echo signal is picked up by another ultrasonic transducer unit, the Receiver,
also a 40Khz pre-tuned unit. These signals received are weak, they are further amplified
several times in the receiver circuit before being read by the micro controller and
microcontroller finds the time taken in microseconds for the to-and-fro travel of the
sound waves. Using the velocity of 333 m/sec, the speed of sound at 25 degree Celsius
ambient temperature, the micro controller does the calculations and finally displays the
distance of the object from the device on the four seven segment display.
7
ULTRASONIC PRINCIPLES
Ultrasonic is the study and application of high-frequency sound waves, usually in excess
of 20 KHz (20,000 cycles per second). Ultrasonic generators use piezo-electric materials
such as zinc or lead zirconium tartrates or quartz crystal. The material thickness decides
the resonant frequency when mounted and excited by electrodes attached on either side of
it.
The medical scanners used for abdomen or heart ultrasound are designed at 2.5 MHz
Modern ultrasonic generators can produce frequencies as high as several gigahertz
( several billion cycles per second) by transforming alternating electric currents into
mechanical oscillations, and scientists have produced ultrasound with frequencies up to
about 10Ghz. There maybe an upper limit to the frequency of usable ultrasound, but it is
not yet known.
Higher frequencies have shorter wavelengths, which allow them to reflect from objects
more readily and to provide better information about those objects. However extremely
high frequencies are difficult to generate and measure. Detection and measurement of
ultrasonic waves is accomplished mainly through the use of piezoelectric receivers or by
optical means. The latter is possible because ultrasonic waves are rendered visible by the
diffraction of light.
Ultrasound is far above the human auditory range, which is only about 20Hz to 18 KHz.
However, some mammals can hear well above this. For example, bats and whales use a
phenomenon called echo location for easy navigation that can reach frequencies in excess
of 100 KHz.
With an ultrasonic transducer, the waves propagate out from the transducer face with a
circular wave front, these waves travel through the medium until they encounter any
obstacles in its path, owing to their shorter wavelength, they are readily reflected back by
these obstacles , these reflected waves are picked up by the receiver circuit, these signals
are amplified several times . Weak echoes also occur due to the signals being received
8
directly through the side lobes. These maybe ignored as the real information regarding
the proximity and nature of the obstacle.
9
CHAPTER-2
BLOCK DIAGRAM
10
BLOCK DIAGRAM DISCRIPTION
11
CHAPTER-3
3.1 CIRCUIT DIAGRAM
12
3.2 CIRCUIT DESCRIPTION
The figure shows the circuit of the micro-controller based ultrasonic distance meter. The
40Khz pulse bursts from the microcontroller are amplified by transistor T5. Inverting
buffer CD4049 drives the ultrasonic sensor used as the transmitter. Three inverters
(N1,N2,N3) are connected in parallel to increase the transmitted power. This inverted
output is fed to another set of three inverters (N4,N5,N6). Outputs of both sets of parallel
inverters are applied as a push-pull drive to the ultrasonic transmitter.
The positive going pulse is applied to one of the terminals of the ultrasonic sensor and the
same pulse after 180-degree phase shift is applied to another terminal. Thus the
transmitted power is increased for increased range.
The echo signal received by the receiver sensor after reflection is very weak. It is
amplified by quad operational amplifier LM324. The first stage (A1) is a buffer with
unity gain. The received signal is directly fed to the to the non-inverting input (pin3) of
A1 and coupled to the second stage by a 3.3nF capacitor. The second stage of the
inverting amplifier uses a 2-mega-ohm resistor for feedback. The third stage is a
precision rectifier amplifier with a gain of 10.
The rectifier functions, unlike a simple diode, even for a signal voltage of less than 0.6V.
The output is filtered to accept 40Khz frequencies and fed to pin12 of microcontroller
AT89C2051, which is an analog comparator. Pin13 is the other pin of the comparator
used for level adjustment using preset VR1.
The ultrasonic transducer outputs a beam of sound waves, which has more energy on the
main lobe and less energy (60dB below the main lobe) on the side lobes. Even this low
side-lobe signals are picked up by the ultrasonic receiver unit. So the transmitter and
receiver units are spaced 5cm apart.
pins P1.7 through P1.2 connected to input pins 1 through 7 of IC2(IC ULN2003)
respectively. These pins are pulled up with a 10-kilo-ohm resistor network. They drive all
the segments of the 7-segment display with the help of the and port-3 pin P3.7 are
13
Microcontroller AT89C2051 is at the heart of the circuit. Port-1 inverting buffer (ULN
2003).
Port-3 pins P3.0 through P3.3 of the microcontroller are connected to the base of
transistor T1 through T4 to provide the supply to the four 7-segment displays. Pin P3.0 of
microcontroller IC1 goes low to drive transistor T1 into saturation, which provides
supply to the common-anode pin of the first 7-segment display. Similarly, Transistor T2
through T4 provides anode currents to other three 7-segment displays.
Microcontroller IC1 provides the segment data and display-enable signal simultaneously
in time-division multiplexed mode for displaying a particular number on the 7-segment
display unit.
Segment data and display enable pulse for the display are refreshed every 5ms. Thus the
display appears to be continuous, even though the individual LEDs used in it light up one
by one.
Using switch S1 you can manually reset the microcontroller. While the power-on reset
signal for the microcontroller is derived from the combination of capacitor C4 and
resistor R8. A 12Mhz crystal is used to generate the basic clock frequency for the
microcontroller. Resistor R16 connected to pin 5 of 7-segment 2 enables the decimal
point.
The comparator is inbuilt in the microcontroller. The echo signal will make port-3 pin
P3.6 low when it goes above the level set on pin13. This status is sensed by the
microcontroller as programmed.
When port-3 pin P3.6 goes high, we know that the signal has arrived; the timer is read
and the 16-bit number is divided by twice the velocity of sound and then converted into
decimal format as a 4-digit number.
14
3.3 POWER SUPPLY CIRCUIT
The 230V AC main is stepped down by the transformer to deliver the secondary
power of 15V-0-15V, 500mA. The transformer output is rectified by a full wave rectifier
comprising of four diodes (IN4001),filtered by a capacitors C8 and C9and then regulated
by ICs 7815(IC5), 7915(IC6),7805(IC7). Regulators 7815, 7915 and 7805 provide +15V,
-15V and +5V regulated supply respectively. The capacitors C10, C11, C12 bypasses the
ripples present in the regulated supply.
15
3.4 COMPONENT LIST
SEMICONDUCTORS:
1. IC1 - AT89C2051 microcontroller2. IC2 - ULN2003 current buffer3. IC3 - CD4049 hex inverting buffer4. IC4 - LM324 quad operational amplifier5. IC5 - 7815, 15V regulator6. IC6 - 7915, -15V regulator7. IC7 - 7805, 5V regulator8. T1-T4 - BC557 pnp transistor9. T5 - 2N2222 npn transistor10. D1, D2 - 1N4148 switching diode11. D3-D6 - 1N4007 rectifier diode12. DIS1-DIS4 - LTS 542 common-anode seven segment display
RESISTORS (all ¼-watt, ±5% carbon):
1. R1,R2-2-mega-ohm
2. R1, R2 - 2-mega-ohm
3. R3 - 82-kilo-ohm4. R4, R7-R10 - 10-kilo-ohm5. R5 - 33-kilo-ohm6. R6 - 100-kilo-ohm7. R11 - 1-kilo-ohm8. R12-R15 - 1.2-kilo-ohm9. R16 - 220-ohm10. RNW1 - 10-kilo-ohm resistor network11. VR1 - 1-kilo-ohm preset
CAPACITORS:
1. C8, C9 - 1000μF, 50V electrolytic
2. C1, C2 - 3.3nF ceramic disk3. C7, C10-C12 - 0.1μF ceramic disk4. C3 - 2.2nF ceramic disk5. C4 - 10μF, 16V electrolytic6. C5, C6 - 22pF ceramic disk
16
MISCLLANEOUS:
1. X1- 230V AC primary to secondary transformer2. XTAL - 12MHz crystal3. S1 - Push-to-on switch4. S2 - On/off switch5. TX1 - 40kHz ultrasonic transmitter6. RX1 - 40kHz ultrasonic receiver
17
CHAPTER-4
COMPONENT DISCRIPTION
4.1 SEMICONDUCTORS
4.1.1 AT89C2051 MICROCONTROLLER:
Fig.4.1.1: AT89C2051 Microcontroller
The AT89C2051 is a low-voltage, high-performance CMOS 8-bit microcomputer with
2K Bytes of Flash programmable and erasable read only memory (PEROM). The device
is manufactured using Atmel’s high density nonvolatile memory technology and is
compatible with the industry standard MCS-51™ instruction set. By combining a
versatile 8-bit CPU with Flash on a monolithic chip, the Atmel AT89C2051 is a powerful
microcomputer which provides a highly flexible and cost effective solution to many
embedded control applications.
18
Features :
1. Compatible with MCS-51 Products
2. 2K Bytes of Reprogrammable Flash Memory
3. 2.7 to 6V Operating Range
4. Fully Static Operation: 0 Hz to 24 MHz
5. Two-level Program Memory Lock
6. 128 x 8-bit Internal RAM
7. 15 Programmable I/O Lines
8. Two 16-bit Timer/Counters
9. Six Interrupt Sources
10. Programmable Serial UART Channel
11. Direct LED Drive Outputs
12. On-chip Analog Comparator
13. Low-power Idle and Power-down Modes
14. 20-pin DIP
Pin Diagram – AT89C2051 :
Fig 4.1.2:Pin Diagram – AT89C2051
19
Pin Description :
Pin Number Description
1RESET – Reset
2P3.0 – Port 3 – RXD
3P3.1 – Port 3 – TXD
4XTAL2 – Crystal
5 XTAL1 – Crystal
6P3.2 – Port 3 – INT0
7P3.3 – Port 3 – INT1
8P3.4 – Port 3 – TO
9P3.5 – Port 3 – T1
10GND – Ground
11 P3.7 – Port 3
12P1.0 – Port 1 – AIN0
13 P1.1 – Port 1 – A1N1
20
14P1.2 – Port 1
15P1.3 – Port 1
16P1.4 – Port 1
17P1.5 – Port 1
18P1.6 – Port 1
19 P1.7 – Port 1
20Vcc – Positive Power Supply
Fig.4.1.3 Pin description
4.2 IC7 – 7805 5V regulator:
7805 is a voltage regulator integrated circuit. It is a member of 78xx series of
fixed linear voltage regulator Ics. The voltage source in a circuit may have
fluctuations and would not give the fixed voltage output. The voltage regulator IC
maintains the output voltage at a constant value. The xx in 78xx indicates the
fixed output voltage it is designed to provide. 7805 provides +5V regulated power
supply. Capacitors of suitable values can be connected at input and output pins
depending upon the respective voltage levels.
21
Pin Diagram:
Figure 4.2.1: Pin Diagram of IC 7805
Pin Description:
Pin No Function Name
1 . Input voltage (5V-18V) Input
2 . Ground (0V) Ground
3 . Regulated output; 5V (4.8V-5.2V) Output
Table 4.2.2: Pin Description of IC 7805
22
The 7805 voltage regulators employ built-in current limiting, thermal shutdown,
and safe-operating area protection which makes them virtually immune to damage
from output overloads. 7805 is a three-terminal positive voltage regulator.
With adequate heatsinking, it can deliver in excess of 0.5A output current.
Typical applications would include local (on-card) regulators which can eliminate
the noise and degraded performance associated with single-point regulation.
7805 regulator comes from the 78xx family of self-contained fixed linear voltage
regulator integrated circuits. The 78xx family is a very popular choice for many
electronic circuits which require a regulated power supply, due to their ease of use
and relative cheapness. When specifying individual Ics within this family, the xx
is replaced with a two-digit number, which indicates the output voltage the
particular device is designed to provide (for example, the 7805 voltage regulator
has a 5 volt output, while the 7812 produces 12 volts).
The 78xx line are positive voltage regulators, meaning that they are designed to
produce a voltage that is positive relative to a common ground. There is a related
line of 79xx devices which are complementary negative voltage regulators. 78xx
and 79xx Ics can be used in combination to provide both positive and negative
supply voltages in the same circuit, if necessary.
7805 Ics have three terminals and are most commonly found in the TO220 form
factor, although smaller surface-mount and larger TO3 packages are also
available from some manufacturers. These devices typically support an input
voltage which can be anywhere from a couple of volts over the intended output
voltage, up to a maximum of 35 or 40 volts, and can typically provide up to
around 1 or 1.5 amps of current (though smaller or larger packages may have a
lower or higher current rating).
The 7805 series has several key advantages over many other voltage regulator
circuits which have resulted in its popularity:
23
7805 series Ics do not require any additional components to provide a constant,
regulated source of power, making them easy to use, as well as economical, and
also efficient uses of circuit board real estate. By contrast, most other voltage
regulators require several additional components to set the output voltage level, or
to assist in the regulation process. Some other designs (such as a switching power
supply) can require not only a large number of components but also substantial
engineering expertise to implement correctly as well.
7805 series Ics have built-in protection against a circuit drawing too much power.
They also have protection against overheating and short-circuits, making them
quite robust in most applications. In some cases, the current-limiting features of
the 7805 devices can provide protection not only for the 7805 itself, but also for
other parts of the circuit it is used in, preventing other components from being
damaged as well.
7805 Voltage Regulator Pinout :
Figure 4.2.3: 7805 Voltage Regulator Pin out
24
7805 Regulator Circuit:
Figure 4.2.4: 7805 Regulator Circuit
4.3 CD4049 HEX INVERTING BUFFER:
The CD4049 hex buffer is a monolithic complementary MOS (CMOS) integrated circuit,
manufactured by Fairchild semiconductor, constructed with N channel enhancement
mode transistors. This device feature logic level conversion using only one supply
voltage (VDD). The input signal high level (VIH) can exceed the VDD supply voltage
when the devices are used for logic level conversions. The device is intended for use as
hex buffers, CMOS to DTL/ TTL converters, or as CMOS current drivers, and at VDD =
5.0V, they can drive directly two DTL/TTL loads over the full operating temperature
range.
25
4.4 LM324 QUAD OPERATIONAL AMPLIFIER:
The LM124 series consists of four independent, high gain, internal frequency
compensated operational amplifiers which designed specifically to operate a single power
supply over a wide range of voltages. Operation from split power supplies is also possible
and the low power supply current is independent of the of the power supply voltage.
Application areas include transducer amplifiers,DC gain blocks and all the conventional
op amp circuits which now can be more easily implemented in single power supply
systems. For example, the LM124 series can be directly operated off of the standard 5V
power supply voltage which is used in digital systems and will easily provide the required
interface electronics without requiring the additional ± 15V power supplies.
4.5 ULN2003 CURRENT BUFFER:
Ideally suited for interfacing between low-level logic circuitry and multiple peripheral
power loads, the Series ULN20xxA/L high-voltage, high-current Darlington arrays
feature continuous load current ratings to 500 mA for each of the seven drivers. At an
appropriate duty cycle depending on ambient temperature and number of drivers turned
ON simultaneously, typical power loads totaling over 230 W (350 mA x 7, 95 V) can be
controlled.
Typical loads include relays, solenoids, stepping motors, magnetic print hammers,
multiplexed LED and incandescent displays, and heaters. All devices feature open-
collector outputs with integral clamp diodes.
26
4.6 D1 - 1N4007 rectifier diode
Fig4.6.1 :1N4007 Diode
The 1N4007 has a blocking voltage of 1000V and is typically supplied in an axial-leaded
DO-41 package. The 1N4007 is a 1 Amp (1A) general purpose rectifier diode commonly
used in power applications.
Currently the 1N4007 is sourced from manufacturers such as Comchip
Technology Corporation, DAICO Industries Inc., Diodes Incorporated, EIC
Semiconductor, Fairchild Semiconductor, Micro Commercial Components
(MCC), Microsemi Corporation, NTE Electronics, ON Semiconductor, SPC
Technology, and Vishay Semiconductors.
Related parts, primarily varying in blocking voltage include: 1N4001, 1N4002,
1N4003, 1N4004, 1N4005 and 1N4006.
27
1N4007 Features :
1. Current Rating: 1A
2. Blocking Voltage: 1000V
3. Packages: DO-41 (Axial Leaded), DO-20 (Axial Leaded)
1N4007 Applications :
1. General Purpose
2. AC Adaptors
3. Household Appliances
1N4007 Circuit Diagram :
Figure 4.9: 1N4007 Circuit Diagram
28
4.2 CAPACITORS
4.2.1 C8,C9 - 1000μF, 50V electrolytic
Figure 4.11 : 1000μF, 50V electrolytic capacitor
Specifications of 1000μF, 50V electrolytic capacitor
Category Capacitors
Family Aluminum
Series FC
Capacitance 1000µF
Voltage Rating 25V
Tolerance ±20%
29
Lifetime @ Temp. 5000 Hrs @ 105°C
Operating Temperature -55°C ~ 105°C
Features General Purpose
Ripple Current 1.655A
ESR (Equivalent Series Resistance) -
Impedance 38 mOhm
Mounting Type Through Hole
Package / Case Radial, Can
Size / Dimension 0.492" Dia (12.50mm)
Height - Seated (Max) 0.787" (20.00mm)
Lead Spacing 0.197" (5.00mm)
Surface Mount Land Size -
Packaging Bulk
Catalog Page 1689 (US2011 Interactive)
1689 (US2011 PDF)
Other Names EEUFC1E102
P10278
4.2.2 C7,C10-C12 - 0.1μF ceramic
30
Fig 4.2.1: C3 – 0.1Μf ceramic
Specifications Of C3 – 0.1Μf ceramic
CAPACITOR CERAMIC 0.1UF, 50V, Y5V, RAD
Capacitance
Capacitance Tolerance
Voltage Rating
Capacitor Mounting
Capacitor Terminals
Lead Spacing
RoHS Compliant
0.1µF
± 20%
50V
Through Hole
Radial Leaded
2.54mm
Yes
4.3 MISCELLANEOUS
31
4.3.1 S2 - SPST ‘on’/‘off’ switch:
Specifications:
1. Supply Power: +5v @ 100mA / -5V @ 60Ma
2. Logic Input High (2.5~5V, 1mA max) : On
3. Logic Input Low (0~0.6V, 3mA max) : Off
Electronics
specification
and
abbreviation
Expansion
of
abbreviatio
n
British
mains
wiring
name
America
n
electrica
l
wiring
name
Description Symbol
SPST
Single
pole, single
throw
One-
way
Two-
way
A simple on-off
switch: The two
terminals are either
connected together or
disconnected from
each other. An
example is a light
switch.
CHAPTER-5
32
SOFTWARE DEVELOPMENT
5.1 SOFTWARE
5.2 MICROCONTROLLER PROGRAMMING
33
ORG 0H
AJMP 30H
ORG 0BH ;TIMER 0 INTERRUPT VECTOR
; AJMP TIMER0ISR ;Timer 0 Interrupt
service routine address
ORG 30H
MOV SP,#60H ;set stack pointer
MOV P3,#0FFH ;set all port 3 bits high
to enable inputs also
MOV P1,#03 ;set port 1 to all zeros expect bits 0,1
MOV TMOD,#01100001B ;TIMER 1 - MODE 2
COUNTER,TIMR-0 TO MODE 1
BEG: MOV TH0,#0H ;TIMER REG.0 IS SET TO
0, GIVES 64ms
MOV TL0,#0 ; timer low reg. is also so
;TOTAL CYCLE TIME IS 64.6ms ,350m/s
gives 0.35mx65=22.5m
; up and down 10 metres say! .35 m/ms,
.35 mm/us, 1mm per 3 micros
; up and down .35/2 mm/us = 1/6 mm/us
; VELOCITY OF SOUND IN AIR IS 350 M/S
; AFTER 100 TIMES, WE HAVE TO STOP
TRANSMITTING FOR A TIME OF ABOUT .1 S;
SO WE STOP FOR THIS AMOUNT OF TIME
and expect an echo.
34
mov r2,#25 ; 25 pulses 26 us =.53 ms
(343m/s*.5ms=17cm)
pulse: setb p3.4 ;generates 40KHz
mov r1,#5
djnz r1,$
clr p3.4
mov r1,#5
djnz r1,$ ;wait for 13 us
djnz r2, pulse ;20pulses
setb tr0 ;start timer
mov r2,#10
djnz r2,$ ;wait 20 us
check_echo:
jnb p3.6,checktimeout
MOV 40h,TL0 ; read timer count
MOV 41h,TH0
mov r0,40h
mov r1,41h
mov r3,#0
mov r2,#6
call UDIV16 ;divide by 6
mov 40h,r0
mov 41h,r1
mov 50h,#25
disp: call disp1 ; show the value on
35
LED
djnz 50h,disp ; so many times for a
visible time limit
jmp beg
checktimeout: mov a,th0
cjne a,#0c0h,check_echo ;upto 4 metres
jmp beg
;subroutine UDIV16
;16 bit/16bit unsigned divide
;input r1,r0 =dividend X
;input r3,r2 =divisor Y
;output r1,r0 =quottient q of x/y
;output r3,r2 = remainder
; alters acc,r4-47,flags,dptr
UDIV16: mov r7,#0 ;clear partial remainder
mov r6,#0 ;
mov B,#16 ;set loop count
div_loop: clr C ;clear carry flag
mov a,r0 ; shift the highest bit of
dividend into
rlc a
mov r0,a
mov a,r1
rlc a
mov r1,a
36
mov a,r6 ;... the lowest bit of partial
remainder
rlc a
mov r6,a
mov a,r7
rlc a
mov r7,a
mov a,r6
clr C
subb a,r2
mov dpl,a
mov a,r7
subb a,r3
mov dph,a
cpl C
jnc div_1 ;update partial reaminder
if borrow
mov r7,dph
mov r6,dpl ; update parital reminder
div_1: mov a,r4
rlc a
mov r4,a
mov a,r5
rlc a
mov r5,a
37
djnz B,div_loop
mov a,r5
mov r1,a ; put qt. in r0,r1
mov a,r4
mov r0,a
mov a,r7 ;get rem. saved before the
mov r3,a ;last subtraction.
mov a,r6
mov r2,a
ret
;16 Bit Hex to BCD Conversion for 8051
Microcontroller
; This routine is for 16 bit Hex to BCD
conversion;
;Accepts a 16 bit binary number in
R1,R2 and returns 5 digit BCD in
;R7,R6,R5,R4,R3(upto 64K )
Hex2BCD: ;r1=high byte ;r7 most significant
digit
;R2 = LSByte
MOV R3,#00D
MOV R4,#00D
MOV R5,#00D
MOV R6,#00D
MOV R7,#00D
38
MOV B,#10D
MOV A,R2
DIV AB
MOV R3,B ;
MOV B,#10 ; R7,R6,R5,R4,R3
DIV AB
MOV R4,B
MOV R5,A
CJNE R1,#0H,HIGH_BYTE ; CHECK FOR HIGH
BYTE
SJMP ENDD
HIGH_BYTE: MOV A,#6
ADD A,R3
MOV B,#10
DIV AB
MOV R3,B
ADD A,#5
ADD A,R4
MOV B,#10
DIV AB
MOV R4,B
ADD A,#2
ADD A,R5
MOV B,#10
DIV AB
39
MOV R5,B
CJNE R6,#00D,ADD_IT
SJMP CONTINUE
ADD_IT: ADD A,R6
CONTINUE: MOV R6,A
DJNZ R1,HIGH_BYTE
MOV B, #10D
MOV A,R6
DIV AB
MOV R6,B
MOV R7,A
ENDD: ret
DISP1:
REFRESH: ; content of 18 to 1B memory
locations are output on LEDs
; only numbers 0 to 9 and A to F are
valid data in these locations
mov r1,41h
mov r2,40h
CALL HEX2BCD
MOV 18H,r3 ; least significant digit
MOV 19H,r4 ; next significant digit
MOV 1AH,r5
MOV 1BH,R6 ; most significant digit
(max:9999)
40
refresh1: MOV R0,#1bh ; 1b,1a,19,18,
holds values for 4 digits
MOV R4,#8 ; pin p3.3_ 0 made low one by
one starts wth 18
mov r7,#2 ; decimal pt.on 3rd digit
from left (2 nd fromright)
PQ2: CALL SEGDISP
deC R0
mov a,r4
rrc a
mov r4,a
jnc pQ2
PV3:
RET
SEGDISP:
mov dptr,#ledcode
MOV A,@R0
ANL A,#0FH
MOVC A,@A+dptr
segcode:
MOV R5,A
ORL A,#03H ; WE WANT TO USE PORT 1 BITS
0 AND 1 FOR INPUT ANLOG
; so retain them high
S3: MOV P1,A ; SEGMENT_PORT
41
MOV A,R5 ;we use p3.7 for the segment
‘a’ of display
RRC A ;so get that bit D0into carry
; cpl c
; mov p3.5,c ; dec pt is D0 bit that is
wired to p3.5
rrc a
mov p3.7,c ;segment ‘a;
S1: MOV A,R4 ; get digit code from r4
00001000
cpl a ;11110111
rrc a ;11111011-1
mov p3.0,c ; output to drive transsitors
for digit lighting
rrc a ;11111101-1
mov p3.1,c
rrc a ;11111110-1
mov p3.2,c
rrc a ;1111111-0 yes low makes leftmost
digit show msdigit
mov p3.3,c
S5:
S4: ACALL DELAY1 ; let it burn
for some time
MOV A,#0ffH ; extinguish
42
the digit after that time
MOV P3,A ; to prevent shadow
s6: RET
ledcode:
DB 7EH,0CH,0B6H,9EH,0CCH,0DAH,0FAH
DB 0EH,0FEH,0CEH,0EEH,0F8H,72H,0BCH,0
F6H,0E2H
;these are code for
the numbers 0 to 9 and A to F
DELAY1: MOV R1,#0ffH
N: NOP
DJNZ R1,N
RET
END
43
FLOWCHART
44
CHAPTER-6
PCB LAYOUT
6.1 Etching Process
PCB is printed circuit board which is of insulating base with layer of thin copper-foil
.
The etching process was carried out in this manner :
The PCB is cleaned with the thinner , so that the dust on the PCB is
removed and we get a shiny surface .
Then we inserted our PCB in the DIPCOAT that is negative photoresistive
material and expose the PCB for 5 to 10 seconds so that the negative
photoresistive material should dry .
Fig.6.1: Dipcoat
Then the photoresistive material ( liquid ) should be made hard on the PCB
for which the PCB is kept in the oven ( protocure ) for four minutes .
45
After the liquid is made hard on the PCB it is kept in the PCB exposure
for two minutes. .In the PCB exposure the circuit is kept with its layout .
The ultraviolet rays are passed through the PCB.
Fig.6.2 : PCB Exposure
Then we have to expose our PCB to the nail polish remover solution which
is also called as developer liquid .As a result of this an impression of
tracks is formed on the PCB .
Put the PCB in a oven ( protocure ) to make the impression hard . The PCB
is kept in oven for four minutes .
After removing the PCB from the oven , the tracks on the PCB will be
developed .After this the PCB is dipped into the PROTO- ETCH for five
minutes . The solution used in the PROTO-ETCH is ferric chloride , due this
the tracks now are fully developed on the PCB .
Then the PCB is washed in water by hand and cleaned by the cloth .Thus
the etching process is completed to mount the components on the PCB we
need to drill the PCB according to the layout . we did the drilling in our
IPR lab under the guidance of the lab incharge.
46
6.2 Component Layout
6.2.1 Positive Layout :
6.2.2 Negative Layout :
47
6.2.3 Component Placement :
48
6.3 Soldering
For soldering of any joints first the terminal to be soldered are cleaned to
remove oxide film or dirt on it. If required flux is applied on the points to be
soldered.
Now the joint to be soldered is heated with the help of soldering iron heat
applied should be such that when solder wire is touched to joint , it must melt
quickly.
The joint and the soldering iron is held such that molten solder should flow
smoothly over the joint .
When joint is completely covered with molten solder , the soldering iron is
removed .
The joint is allowed to cool, without any movement .
The bright shining solder indicates good soldering .
In case of dry solder joint, a air gap remains in between the solder
material and the joint. it means that soldering is improper .this is removed
and soldering is done.
Thus in this way all the components are soldered on PCB .
49
CHAPTER - 7
CALCULATIONS AND TESTING
7.1 Calculations
50
7.2 Testing
We need following Equipment’s for testing the Circuit-
Oscilloscope
An oscilloscope (also known as a scope, CRO, DSO or, an O-scope) is a type of electronic
test instrument that allows observation of constantly varying signal voltages.
Oscilloscopes are commonly used to observe the exact wave shape of an electrical
signal. In addition to the amplitude of the signal, an oscilloscope can show distortion,
the time between two events (such as pulse width, period, or rise time) and relative
timing of two related signals.
Digital Multi Meter (DMM)
Figure 7.3 : Digital Multi Meter
A multimeter is also known as a VOM (Volt-Ohm meter), is
an electronic measuring instrument that combines several measurement functions
in one unit. A typical multimeter may include features such as the ability to
measure voltage , current and resistance.
51
52
CHAPTER-8
APPLICATIONS OF THE ULTRASONIC
DISTANCEMETER:
a) Ultrasonic distance meters are being increasingly used in various industries to measure
critical parameters like fluid height, thickness of materials…etc with very high accuracy.
b) Various luxury cars are equipped with state-of-the-art ultrasonic distance meters as
part of its parking assist system.
c) A technology pretty similar to this, Patented by Mercedes and Co. is being used in
their next generation luxury cars in what they call the ACCIDENT PREVENTION
SYSTEM.
d) Ultrasonic distance meters can be potentially used in rifles and war planes for target
assessment by the armed force. It is already a part of several military surveillance
equipments.
e) The same hardware system, with slight change in the microcontroller program can be
made to detect moving objects and find their range and speed, which maybe used in
speed guns to measure the speed of vehicles.
53
CONCLUSION AND FUTURE SCOPE:
The unit can successfully used to measure distance with a very high degree of accuracy.
The range of this ultrasonic distance meter can be increased further than 2.5m by using a
higher pulse excitation voltage or a better transducer.
The same unit can be made to detect movement of objects such as cars racing on the
street and find their range and speed.
It can also be used with suitable additional software as a burglar alarm unit for homes and
office.
54
REFERENCES
Books:
1. Principles of Electronics by V.K.Meheta.
2. Electronic Instrumentation by H.S. Kalsi.
3. 8051 Microcontroller and Embedded System by Mazidi and Mazidi.
4. A textbook of Applied Electronics by R.S.Sedha.
Websites:
1. www.geocities.com
2. www.yahoo.com
3. http://olimp.infomir.kiev.ua/docs/PDF/AT89C2051
4. http://www.efy.com
5. www.8051projects.net
6. www.wikipedia.com
7. www.electronicsforu.com
8. www.ieee.org
9. www.crazyengineers.com
10. www.electronics4everyday.com
Software Used :
1. Eagle Software - For PCB
2. ASEM-51.exe - Assembler
3. Keil – Execution.
55
56