Upload
others
View
9
Download
0
Embed Size (px)
Citation preview
1
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY
HYDERABAD, A.P
A FINAL PROJECT REPORT
ON
“MYOELECTRIC CONTROLLED PROSTHETIC HAND”
In partial fulfillment for the degree of
BACHELOR OF TECHNOLOGY
IN
ELECRICAL AND ELECTRONIC ENGINEERING
BY
NARESH . V. 06M31A0230
BHASKAR. L. 06M31A0208
NISHITHA COLLEGE OF ENGINEERING AND
TECHNOLOGY
LEMOOR. (VI), KANDUKUR(MAN), R.R. (DIST)
2
ABSTRACT
Our mini project was inductance meter using 89c2051 microcontroller. As an
expansion and knowledge improvement we have opted for LCF meter as our
final year project. Which is not only challenging but also useful device. To
be different our choice was LCF meter (inductance , capacitance and
frequency meter), instead of LCR meter
3
1.0 Introduction
2.0 Block diagram
2.1 Block diagram explanation
2.2 Block diagram of frequency counter
3.0 Implementation
3.1 Microcontroller
3.2 Amplifier
3.3 LCD display
4.0 Schematic Diagram.
4.2 microcontroller sghematic diagram
4.1 Functional Description
4.3 Theory of operation
5.0 Results and discussion
6.0 Summary and conclusion
Future Scope
Annexure - 1
1. List of figures
2. List of tables
Annexure -2
1. Microcontroller code
2. Capacitence meter code
Bibilography
4
CHAPTER – 1
1. INTRODUCTION
Capacitance meter:
Capacitance meter can be very helpful in identifying old components where its mark has been
erased or became unreadable. Such instrument can be quite expensive, but fortunately we can
build it easily with much lower cost. The capacitance meter described here can measure any
capacitor between 1pF and 10uF. Here is the schematic diagram of the circuit:You can just use a
connector for the voltmeter, and the circuit becomes a capacitance meter adapter for your
general purpose voltmeter. Just plug the input of your voltmeter to this capacitance meter circuit
and now your voltmeter becomes capacitance meter.
You can use an analog voltmeter or digital voltmeter. If you use a digital voltmeter,
make sure your digital voltmeter is a dual/single slope type reading, since it has an inherent
averaging function. If your digital voltmeter is a fast sampling type, then you need to insert a
resitor-capacitor filter between this capacitance meter circuit and the voltmeter. A 1k resitor and
a 10uF electrolytic capacitor sould be enough for the filter. Analog voltmeter doesn‟t need any
filter since its mechanical inertia acts like a low-pass filter in nature. More information can be
found at
This simple controller based unit was designed to measure and display the values of inductors
and capacitors.As a by-product of the technique used.it can also display the frequency of an
external 0V/ +5V signal source The ranges are approximately:
Capacitance : 1pF to 6500uF
Inductance : 1uH to 10H
Frequency : 0.05Hz to 5MHz
Inductance meter:
The algorithm works with the device is as follows:
1. After the power, if the buttons SA1, SA2 are pressed, then the indicator will show "L" or "C",
5
thus hinting at what button must be overcome.
2. When squeezed the knob, the instrument calibration mode, as evidenced by the inscription
"WAIT", a couple of seconds, alternating on "OK". During this time, the relay, including a
reference capacitor in the general contour of the L1 and C1. The microcontroller reads the
frequency with condenser and without him, which then e yshem will be used to calculate the
exact values of L1 and C1. Measuring terminals at this time disconnected from the circuit and do
not affect the measurement.
3. By clicking on the appropriate radio button is selected or the measurement of capacitance or
inductance. Accordingly, the indicator displays "L =", or "C =". In the first case, the measured
capacitance connected in parallel with C1, the second - as measured inductance connected in
series L1. Microcontroller measures the frequency and computes the desired value. The limit of
measurement is set automatically, and after the indicated values of the dimension: "pF", "nF", "
uH "," mH ".
Frequency counter:
Digital frequency counter is being used for wide range of applications. Digital frequency counter
is extensively uses digital circuits and hence fairly good knowledge of digital circuits and of
digital integrated circuits is required to understand the operation of the frequency counter.
However application of micro controllers have greatly simplified hardware requirement for
frequency counter. The following figure shows the conventional frequency counter design.
6
2. BLOCK DIAGRAM
89S52/
ATMEGA16
RCF
selection
switch
16X2 LCD DISPALY
Op-Amp
oscillator
Frequency
counter
Transformer
Power
supply
Regulator
Filter
7
Fig: Block Diagram inductor capacitor and frequency counter meter
2.1 Block diagram explanation:
Power supply:
The electrical power output is rated at 230v Ac. Which is not suitable for driving any
electronic devices, which operate at lower voltages 12V, 5V and 3V etc. hence 230V AC is
converted to 12V ac using step-down transformer. The o/p of the step down transformer is
rectified using bridge rectifier for max efficiency
Bridge Rectifier:
A bridge rectifier makes use of four diodes in a bridge arrangement to achieve full-wave
rectification. This is a widely used configuration, both with individual diodes wired as shown
and with single component bridges where the diode bridge is wired internally.
Fig 49: Bridge Recifier
Diodes 1N4007 are used as rectifiers. which are rated at 1Amp.
The output of rectifier is pulsating DC which is filtered using a filter capacitor to
smoothen out the ripples.
RC Filter
8
the diode bridge is wired internally. A bridge rectifier makes use of four diodes in a
bridge arrangement to achieve full-wave rectification. This is a widely used configuration, both
with individual diodes wired as shown and with single component bridges where
Fig 50: Current Flow in the Bridge Rectifier
Due to variations at the input the output may also vary hence we need a regulator maintain
constant output voltage and better line regulation and load regulation irrespective of variations at
the input.
The regulator used is 7805 which is a positive voltage regulator. The first two digits “78”
indicates fixed positive regulator and last two digits indicate output voltage in our case “05”
stands for 5V constant output.
Simple 5V power supply for digital circuits
Summary of circuit features and Brief description of operation:
1) Gives out well regulated +5V output, output current capability of 100 mA
2) Circuit protection: Built-in overheating protection shuts down output when regulator IC gets
too hot
3) Circuit complexity: Very simple and easy to build
4) Circuit performance: Very stable +5V output voltage, reliable operation
5) Availability of components: Easy to get, uses only very common basic components
6) Applications: Part of electronics devices, small laboratory power supply
9
7) Power supply voltage: Unreglated DC 8-18V power supply
2.2 Block diagram of digital frequency meter & Explanation
The circuit is built around a member of the atmel family of microcontrollers. In this project we
hope to give some insight into the methodology of software design for microcontrollers, and in
particular an insight into programming the microcontroller. The challenge was to achieve a
solution with the minimum of hardware by moving the functionality into software. Basing the
circuit on a microcontroller, rather than opting for a more conventional electronic design, gives a
greater degree of flexibility. Software is more adaptable than hardware, it is much easier to
change a line or two in the source code than to add another track to a pcb.
A microcontroller is robust, simple to interface to the outside world, and relatively simple to
program.
Individual instructions are represented by mnemonics which are easier to remember than the
binary codes that the processor actually understands. A mnemonic gives an indication of what an
instruction does. For example the instruction reti returns from a subroutine. A software tool
called an assembler converts the mnemonics (source code) into binary (object code).
The microcontroller I/O pin is connected to an external probe for the meter via some circuitry to
condition the input signal. The port pin can trigger on a rising or a falling edge, in this design we
have conventionally selected triggering on rising edges. There is also a prescaler associated with
the timer which can prescale the input to the counter from 1:2 to 1:256.
10
The desired accuracy of ± 1Hz rules out using an RC oscillator to drive the microcontroller. A
crystal or ceramic resonator must be used. The frequency meter must measure up to an 1Khz
input signal so the processor needs to be fast.
How does one measure the frequency of a signal ? Simply by counting the total number of
pulses over a fixed period of time, typically 1 second. This will always give a reading accurate to
± 1Hz. For high frequencies (above 10kHz) the meter can be made more responsive by timing
over a shorter period, say 1/8 s. This reduces the accuracy to ± 8Hz but because only 4
significant digits are displayed anyway that doesn‟t matter.
One of the design goals was to dispense with range switches or the equivalent. Consequently the
software must be adaptive to whatever input signal frequency it is fed with.The first problem to
be solved was how to display such a range of frequencies using just four digits (i.e. without
being able to display the units, whether Hz, kHz or MHz). The solution was to always display the
signal frequency in kHz with the position of the decimal point effectively indicating the units.
Table 1 gives the displayed readings for the range of frequencies. A more sophisticated (and
expensive) approach would be to use an alphanumeric LCD display which could display the
units as well as the digits.
11
3.0 IMPLIMENTETION
The design is based upon the concept that osillators can be constructed from CMOS NAND
gates or inverters.and that their oscillation frequency depends on the valuesof inductance.
capacitance and resistance in their feedback paths. Using a suitable microconteroller. Such as
one from the PIC 16F62x or PIC 16F87x
families. software can read the frequency of an oscillator and calculate the value of the ot- her
components are known.In this design. A PIC16F628 is used and the results are output to an
alphanumeric liquid crystal display (I.c.d.). One technique for using an inductor in a CMOS
oscillator circuit is that shown in Fig.1.Here the oscillation frequency is determined by the
formula:
F = _______1_______
2 π √ ( L x C )
where:
F = frequency
C = C1 x C2
C1 + C2
L = inductance
π = 22/7
12
Using this formula. If any two values are known. The third can be readily calculated For
instance . if C and F are known. Than L can be calculated using the formula:
L=(1†(2Πf)^2÷ C
Similarly using the capacitance –resistance oscillator configuration ,.the output Frequency can
be calculated for known values of R and C. several formulae exist for this calculation and the one
used in this application is:
F = ____1____
2x R x C
from which the value for C can be calculated if R and F are known:
C = 1___
Π x R x F
inductance measurment
Inductors are passive devices used in electronic circuits to store energy in the form of a
magnetic field. They are the compliment of capacitors, which store energy in the form of an
electric field. An ideal inductor is the equivalent of a short circuit (0 ohms) for direct currents
(DC), and presents an opposing force (reactance) to alternating currents (AC) that depends on the
frequency of the current. The reactance (opposition to current flow) of an inductor is
proportional to the frequency of the current flowing through it. Inductors are sometimes referred
to as "coils" because most inductors are physically constructed of coiled sections of wire.
The property of inductance that opposes current flow is exploited for the purpose of preventing
signals with a higher frequency component from passing while allowing signals of lower
frequency components to pass. This is why inductors are sometimes referred to as "chokes,"
since they effectively choke off higher frequencies. A common application of a choke is in a
13
radio amplifier biasing circuit where the collector of a transistor needs to be supplied with a DC
voltage without allowing the RF (radio frequency) signal from conducting back into the DC
supply.
Most of the formulas for the inductance of a coil are valid for the current sheet
approximation, where the c urrent flows in an indefinitely thin surface around the coil
diameter. This is the same as assuming the coil wound with an indefinitely thin tape with
negligible separation between turns. If the separation between turns is not small, a correction
factor should be applied. Moreover, at high frequencies the current crowds towards the
inside of the coil so the effective radius where the current flows become smaller. Sometimes
it is suggested to use the internal radius of the coil instead of the wire mean radius in the
calculations, in order to compensate for this effect. However the difference between the low- and
high-frequency inductances is usually not large [1].
To compute accurately the inductance of any kind of coil (or also of more complicated
conductiong structures) one has to use an electromagnetic simulator.
Regarding current sheet inductance formulas for single-layer coils, one of the most widely
known is the one by Wheeler [2], which states (after converting to metric units):
L = (d2n
2) / (l + 0.45d)
where
„d‟ is the coil diameter in meters,
„n‟ the number of turns and
„l‟ the coil length in meters.
The above formula is accurate within 1 % for l>0.4d ; for shorter coils one can use the
well- known Nagaoka formula [3] (which has the inconvenience of requiring a list of
tabulated values for different diameter / length ratios) or other asymptotic approximations
[4].
Some useful formulas, applicable for any diameter to length ratio, are presented in [4]
and [5]; the following form implements the latter, for which the maximum relative error
14
is stated to be less than 3 ppm.
The Q value is computed here using the formula of [6]; take the resulting value with
care, since the limits of validity are not clear to me.
INPUT DATA
Coil diameter, d : 0.33m
Coil length, l : 0.24m
Number of turns, n :55
Frequency, MHz : 0.137 mh
(used only for computing Q)
CALCULATED VALUES
Inductance value L :896 µH
Inductor Q : 575
15
Frequency measurment
For cyclical processes , such as rotation, oscillations , or waves frequency is
defined as a number of cycles per unit time. In physics and engineering
disciplines , such as optics , acoustics , and radio , frequency is usually denoted by
a Latin letter f or by a Greek letter ν (nu).
In SI units , the unit of frequency is hertz (Hz), named after the German physicist
Heinrich Hertz. 1 Hz means that an event repeats once per second. A previous name
for this unit was cycles per second.A traditional unit of measure used with rotating
mechanical devices is revolutions per minute, abbreviated RPM. 60 RPM equals one
hertz.[1]
The period, usually denoted by T, is the length of time taken by one cycle, and is the
reciprocal of the frequency f:
The SI unit for period is the second.
M easurement
Calculating the frequency of a particular event is accomplished by counting the number
of times that event occurs within a specific time intervall, then dividing the count by the
length of the time interval. For example , if 71 events occur within 15 seconds, the
frequency is:
If the number of counts is not very large , it is more accurate to measure the time
interval for a predetermined number of occurrences, rather than the number of occurrences
within a specified time.[2]
The latter method introduces a random e rror into the count of
between zero and one count, so on average half a count. This is called gating error and
causes an average error in the calculated frequency of Δf = 1/(2 Tm), or a fractional error
of Δf / f = 1/(2 f Tm) where Tm is the timing interval and f is the measured frequency. This
error decreases with frequency, so it is a problem at low frequencies where the number of
counts N is small.
16
An older method of measuring the frequency of rotating or vibrating objects is to use a
stroboscope. This is an intense repetitively flashing light (strobe light) whose frequency can be
adjusted with a calibrated timing circuit. The strobe light is pointed at the rotating object and the
frequency adjusted up and down. When the frequency of the strobe equals the frequency of the
rotating or vibrating object, the object completes one cycle of oscillation and returns to its
original position between the flashes of light, so when illuminated by the strobe the object
appears stationary. Then the frequency can be read from the calibrated readout on the
stroboscope.
schematic diagram of microcontroller:
Fig 1.1: Schematic of Micro controller interface
17
Fig 1.2: Analog front end oscillator schematic
Fig 1.3: Frequency counter interface sc
18
3.3 LIQUID CRYSTEL DISPLAY:
A liquid crystal display (LCD) is a thin, flat display device made up of any number of color
or monochrome pixels arrayed in front of a light source or reflector. It is often utilized in
battery-powered electronic devices because it uses very small amounts of electric power.
In recent years the LCD is finding widespread use replacing LED‟s (seven-segment
LED‟s or other multi segment LED‟s). This is due to the following reasons:
1. The declining prices of LCD‟s.
2. The ability to display numbers, characters, and graphics. This is in contrast to LED‟s, which
are limited to numbers and a few characters.
3. Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of the task
of refreshing the LCD. In contrast, the LED must be refreshed by the CPU to keep displaying
the data.
4. Ease of programming for characters and graphics.
19
Fig 3.3: A general purpose alphanumeric LCD, with two lines of 16 characters
An alphanumeric 2 line 16 character LCD display is used for user interface and
debugging purposes.
It can be operated in 8bit mode or 4bit mode. Since the processor resources are a
premium and we need to interface several devices we have implemented a multiplexed LC and
Keypad interface using least number of ports.
LCD displays are very versatile and require low power to operate.
Attractive backlight enhances the poor light visibility.
Fig 3.4 Schematic of LCD connector
20
Schematic Diagram.
21
4.0 SCHEMATIC DIAGRAM
4.1 Schematic diagram of LCF meter:
Capacitance meter can be very helpful in identifying old components where its mark has been
erased or became unreadable. Such instrument can be quite expensive, but fortunately we can
build it easily with much lower cost. The capacitance meter described here can measure any
capacitor between 1pF and 10uF. Here is the schematic diagram of the circuit:
You can just use a connector for the voltmeter, and the circuit becomes a capacitance meter
adapter for your general purpose voltmeter. Just plug the input of your voltmeter to this
capacitance meter circuit and now your voltmeter becomes capacitance meter. You can use an
analog voltmeter or digital voltmeter. If you use a digital voltmeter, make sure your digital
voltmeter is a dual/single slope type reading, since it has an inherent averaging function. If your
digital voltmeter is a fast sampling type, then you need to insert a resitor-capacitor filter between
this capacitance meter circuit and the voltmeter. A 1k resitor and a 10uF electrolytic capacitor
sould be enough for the filter. Analog voltmeter doesn‟t need any filter since its mechanical
inertia acts like a low-pass filter in nature. More information can be found at
[Source: talkingelectronics.com]
22
Inductance meter:
The algorithm works with the device is as follows:
1. After the power, if the buttons SA1, SA2 are pressed, then the indicator will show "L" or "C",
thus hinting at what button must be overcome.
2. When squeezed the knob, the instrument calibration mode, as evidenced by the inscription
"WAIT", a couple of seconds, alternating on "OK". During this time, the relay, including a
reference capacitor in the general contour of the L1 and C1. The microcontroller reads the
frequency with condenser and without him, which then e yshem will be used to calculate the
exact values of L1 and C1. Measuring terminals at this time disconnected from the circuit and do
not affect the measurement.
3. By clicking on the appropriate radio button is selected or the measurement of capacitance or
inductance. Accordingly, the indicator displays "L =", or "C =". In the first case, the measured
capacitance connected in parallel with C1, the second - as measured inductance connected in
series L1. Microcontroller measures the frequency and computes the desired value. The limit of
measurement is set automatically, and after the indicated values of the dimension: "pF", "nF", "
uH "," mH ".
Frequency counter:
Digital frequency counter is being used for wide range of applications. Digital frequency counter
is extensively uses digital circuits and hence fairly good knowledge of digital circuits and of
digital integrated circuits is required to understand the operation of the frequency counter.
However application of micro controllers have greatly simplified hardware requirement for
frequency counter. The following figure shows the conventional frequency counter design.
23
4.2 THEORY OF OPERATION
The frequency counter has to count the number of cycles per second of an incoming signal.
Hence we need a device to count. In electronics circuits, counter ICs are available for counting.
These IC's can count the input pulses. The count is given as coded output from the IC (in binary
form or BCD form). The count must be converted into decimal digit to be understood by human
beings. More number of IC's can be cascaded to increase the number of digits. The number of
digits required for the counter to display the count value depends on the application and the
accuracy needed. In our design we use a single 4 bit BCD high-speed CMOS counter chips. One
chip is used for one digits and we use 7 similar ICs to get seven digit counter. Also we use
CMOS decoder IC to decode the BCD out put of the counter to drive 7 segment displays.
Since the counter can count only digital pulses, we need to convert the incoming signal wave to
digital pulse or we should obtain one pulse for every input wave. Hence we need a special circuit
to shape the input wave into a square wave of same frequency and amplitude confined to the
TTL signal levels. A signal conditioning section is needed for this purpose.
The input Signal-conditioning section consists of the following stages.
1. Amplifier or attenuation stage
2. TTL level converter stage
Besides the above initial stages, some times a few more additional stages such as input protection
stages, filter stages, etc are can be found in some designs. The input whose frequency is to
measured is given to the input stage consisting of the above and the out put of this stage is the
square pulses. Now the square pulses are given to the counter to count the number of pulses for a
fixed duration. If the duration is 1 seconds, then the counter displays a value that equals to the
number of cycles per second, now if we want to measure a frequency of say 20MHz, the counter
should display 20000000. this means the counter should have 8 digits to display. Now the
resolution of the counter ( minimum change of frequency that can be displayed ) is 1Hz. If we do
not require that much of resolution, we can reduce the number of digits. For example, if we are
counting the input cycles for a duration of 0.1 seconds, the display shows 2000000. Now if we
put a decimal points after two digits from the left of the display, the frequency can be read in
MHz, in both cases, the resolution for the later being 10Hz. The time for which the counter is
counting is called as gating time and if the gating is say 1 milli second, we get a display with
resolution of 1kHz. A frequency counter must always count the input frequency and display
frequency. This means there should be an arrangement to count the input for a fixed time, display
the reading. While displaying the reading, the counter should clear again to read input again.
Then only we get a continuous reading that displays the correct frequency at all times. A control
circuit is needed to achieve this. The function of the control circuit to generate the following
signals.
1. Clear the counter for refreshing
2. Provide a precision gating signal to allow the input pulses to the counter circuit
3. Latch the count value to decode and display
4. Repeat the above steps continuously to get a continuous reading
24
The control circuit must operate with precision timing. This is achieved by deriving all timing
signals from a crystal oscillator or time base circuit. The accuracy of the counter solely depends
on the stability and accuracy of the time base circuit.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
We present a design for a simple, low-cost digital frequency meter with the following features:
operating range from about 1hz to 15Hz to 8MHz (sufficiently high to make the meter
useful for troubleshooting digital circuits, microcontrollers etc.)
internal accuracy ± 1Hz
4 digits of displayed accuracy (enough accuracy for most situations)
adaptive (no range switch)
input conditioning amplifier sensitive to 50mV
input protection
crystal controlled (therefore no need for calibration)
powered by a single 9V alkaline battery
How does LC Meter Work?
To be able to determine the value of an unknown inductor / capacitor we can use the
frequency formula given below.
Note that there are three variables that we can work with; f, L and C (f represents a
frequency, L inductance and C capacitance). If we know the values of the two variables we
may calculate the value of the third variable.
Lets say we want to determine the value of an unknown inductor with X inductance. We plug
X inductance into the formula and we also use value of a known capacitor. Using this data we
can calculate the frequency. Once we know the frequency we can use the power of the
algebra and rewrite the above formula to solve for L (inductance). This time we will use the
calculated frequency and a value of a known capacitor to calculate the inductance.
25
Isn't this amazing? We just calculated the value of unknown inductor, and we may use the
same technique to solve for the unknown capacitance and even frequency.
Applying the Theory to LC Meter's Hardware
Now let's use the above theory and apply it to electronics. The LC Meter uses a popular
LM311 IC that that functions as a frequency generator and this is exactly what we need. If we
want to calculate the value of an unknown inductor we use a known Ccal 1000pF capacitor
and the value of an unknown inductor. LM311 will generate a frequency that we can measure
with a frequency meter. Once we have this information we can use the frequency formula to
calculate the inductance.
The same thing can be done for calculating the value of a unknown capacitor. This time we
don't know the value a capacitor so instead we use the value of a known inductor to calculate
the frequency. Once we have that information we apply the formula to determine the
capacitance.
All this sounds great, however if we want to determine the value of a lot of inductors /
capacitors then this may become a very time consuming process. Sure, we can write a
computer program to do all these calculations, but what if we don't have an access to a
computer or a frequency meter?
That's were PIC16F84A microchip comes handy. PIC16F84A is like a small computer that
can execute HEX programs that are written using an assembly language. PIC16F84A is a
very flexible microchip because it has PINs which can be configured as inputs and outputs.
Besides that, PIC16F84A IC requires very minimal number of external components like
4MHz crystal / resonator and few resistors depending on what project we are building. Before
we can use PIC16F84A microchip we have to program it with a HEX code which has to be
sent from the computer.
In the next step we use the frequency generated by LM311 IC and pass it on to PIC16F84A's
PIN 17. We designate this PIN as an input, as well as all other PINs that are directly
connected to switches and jumpers. User can use these inputs to tell the microchip to execute
specified set of instructions or perform calculations.
Once the microchip will calculate the unknown inductance or capacitance it will use PINs
that are designated as outputs and pass the results on to the 16 character LCD display.
26
LC-meter with the 89C2051
LC-meter is a device for measuring capacitance and inductance .it works based on the principle
of LC oscillator frequency measurement and subsequent calculations, which provides single-chip
microcomputer used in our project.
Here in after described measurement device is designed to jejbylo possible to construct as simple
as possible and with minimal financial náklady. Proto this article will not deal with excessive
detail, but focused on a simple description of the construction equipment. Software is also
explained in detail.
LC meter function
Measurement capabilities range from 0.01pF, the maximum capacity of the until-oscillating
oscillator (2 m M tested), only the bipolar capacity, means that do not measure electrolytes.
Measure inductance range from 1NH, the maximum-inductance is not known (about 100mH but
certainly even more).
Calibration
To ensure the accuracy of any need jedenkondenzátor, which has a capacity as closely as
possible 1005pF, or any other, precisely measured, the value entered in the program for
microcomputers (now there just 1005pF). Microcomputer after pressing the S2 values
všechostatních components calculated.
Display Range
Value calculations are performed in floating desetinnéčárce, the calculated value is displayed
with 14 bit precision. Desetinnáčárka is the third, second, or first digit from the right. It ranges
vyplývajítyto displayed:
Inductance Capacity
0.000 to 16.383 m H 0.00 to 163.83 pF
16.38 -163.83 m H 163.8 to 1638.3 pF
163.8 to 1638.3 m H 1.638 to 16.383 nF
1.638 to 16.383 mH 16.38 to 163.83 nF
16.38 to 163.83 mH 163.8 to 1638.3 nF
27
163.8 to 1638.3 mH 1.638 to 16.383 m F
1.638 to 16.383 H 16.38 to 163.83 m F
16.38 to 163.83 H 163.8 to 1638.3 m F
etc.. etc..
The range selection is of course old microprocessor control program.
Screen
To view the result is a smart LCD16x2 characters. The first line shows the resulting value of the
measured components, the second line is displayed the current frequency LC oscillator.
Example:
Cx = 1004.9 pF
302,052 Hz
Speed Measurement
Velocity measurement is a reasonable compromise between rychlostízobrazení and accuracy.
The principle of frequency measurement is čítánífrekvence the counter and the contents of the
counters are periodically read and reset. A compromise was set to 4 measurements per second,
it's frequency is measured with an accuracy of 4 Hz.
Description of involvement
The device is powered from a 9V battery (terminals X2), stabilization 5V small stabilization in
the housing TO92 (IC3). Microcomputer is reset zabezpečenelektrolytem C8 - 1 m F.
11.059MHz crystal is used, which, however, limits the maximum frekvencioscilátoru to 460kHz.
It is possible, after adjusting the preferences in the timing programupoužít 24MHz crystal, which
will choose a higher frequency of LC oscillator adosáhnout greater precision in the smallest
ranges. 11.059MHz crystal suits, because to achieve the accuracy seems to be sufficient. LC
oscillator is tvořennapěťovým comparator with positive feedback. When measuring capacity and
C1 jsouL1 parallel oscillator oscillates with a maximum frequency. After připojeníměřené
capacity is appropriately lower frequencies. When measuring the inductance jeměřená
inductance connected in series with inductor L1, the resulting inductance jetedy total measured
inductance and inductance L1. When calibration is run parallel connected capacitor C2 C1,
whose capacity is accurately known. In the diagrams, written value 1nF, the program is blocked,
however, accurate measurement of the value-in this case 1005pF. Capacitors C3 and C4 are
28
tantalum. LCD display requires four data wires, the display contrast can be set by varying the
contrast resistor connected to the pin3 of the LCD display. Microcomputer is original from
Atmel, a type of AT89S52.
Control
Switching on the device with the lock button S1. Zdežádné not automatically shut down,
therefore we can not use the device again vypnout.9V battery will not give anyone free. If you
want to measure the capacity stisknemetlačítko S3 (which is dependent on inductance
measurement for S4). After pressing the S2 tlačítkapro calibration device is calibrated and ready.
If we measure the inductance, we can calibrate the S3 and S4 is off, or hold down the S4, but we
měřícísvorky shorted. Thus it is appropriate to eliminate inductance measuring lines.
Calculations
During calibration, the microcomputer performs the following operations:
Saves frequency measured before pressing S2tato frequency is called F1.
The actual frequency of the F2 and stored frequency F1vypočítá capacity of capacitor
C1
Calculated inductance L1
When measuring the inductance of the microcomputer performs
tentovýpočet
When measuring the capacity of the microcomputer performs this
calculation
Construction
29
Parts List
Designation Value
R1, R2, R3 100 k
R4 47
R5 1,
P1 5 to resistive trimmer (PT6VK005)
C1 1 nF capacitor foil
C2 1 nF capacitor foil (preferably as nejpřesněji1005 pF can pass)
C3, C4 10 F/10Vtantalový
C5, C10, C11 100 nF ceramic (blocking power)
C6, C7 22 pF ceramic
C8 1 Felektrolytický (to reset when turned on)
C9 47 F/10Velektrolytický
X1 11.059 MHz crystal
L1 150 H
IC1 LM311N voltage comparator
IC2 AT89C2051 microcontroller
IC3 78L05 5V stabilizer
A1 LCD 16x2 characters
20 pin of IC2 plinth (not necessarily)
S1 ISOSTAT 1 packet with lock (1 NO contact)
S2 ISOSTAT 1 packet with a latch (2 normally open contacts)
S3, S4 ISOSTAT 1 packet - catcher - one handles the other.
X3, X4 Measuring terminals
U-KM33B - cabinet
Clip for 9V battery
4 pieces of placeholders (or just two)
30
Capacitance meter
AT89C2051 based Capacitance meter
AT89C2051 is the simplified chip of AT89C51, which has only 2 ports. Although AT89c2051 is
same as AT89C51 it has an on-chip voltage comparator. With this comparator we can make
more additional functions such us analog to digital conversion and so on. In this article an digital
capacitance meter has been designed with the AT89C2051 microcontroller. It can measure
capacitance of values less than 2Microfarads. The value is displayed over the 7segment display.
Circuit Diagram
Capacitance meter code
#include <reg51.h>
unsigned char j,n,t,DispBuf[4];
unsigned int cap;
unsigned char code
BitTab[4]={0xbf,0xdf,0xef,0xf7};
unsigned char code
31
DispTab[11]={0xfe,0x70,0xed,0xf9,0x73,0xdb,0xdf,0xf0,0xff,0xfb,0x40};
sbit P1_2=P1^2;
sbit P3_6=P3^6;
main()
{ TMOD=0x11;
TH1=0xec;
TL1=0x78;
IE=0X88;
TR1=1;
for(;;)
;
}
Timer1() interrupt 3
{ TH1=0xec;
TL1=0x78;
t=BitTab[j];
P1=P1|0x78;
P1=P1&t;
t=DispBuf[j];
t=DispTab[t];
P3=t;
j++;
if(j==4)
j=0;
n++;
if(n==48)
{
n=0;
TH0=0;
32
TL0=0;
P1_2=1;
TR0=1;
for(;P3_6==0;)
;
TR0=0;
P1_2=0;
cap=TL0|(TH0<<8);
cap=cap-3;
if(cap>=2000)
{
DispBuf[3]=10;
DispBuf[2]=10;
DispBuf[1]=10;
DispBuf[0]=1;
}
if(cap<2000)
{
DispBuf[3]=cap%10;
cap=cap/10;
DispBuf[2]=cap%10;
cap=cap/10;
DispBuf[1]=cap%10;
DispBuf[0]=cap/10;
}
}
}
Home made square-wave generator and frequency meter
33
The frequency counter can measure square wave
This project can generate a square wave and also measure it. Two microcontrollers are used in
this circuit, one to generate square wave and other to measure and display the frequency of the
square wave. AT89C2051 is used to generate square wave and AT89S52 is used to measure the
frequency and display it over a 8 digit seven segment display.
The code is written in Keil C. Both microcontroller runs with 11.05mhz crystal.
Circuit Diagram
34
C code for square wave generator
#include <reg51.h>
sbit P1_0 = P1^0;
#define HIGH_BIT 0xFD
#define LOW_BIT 0xC0
void Timer0() interrupt 1
{
unsigned char i = 5;
TH0 = HIGH_BIT;
TL0 = LOW_BIT + 4 + 2;
P1_0 = 0;
while (i--); // 10 cycles = 10.85 ns
P1_0 = 1;
}
void main()
{
TMOD = 0x01;
// 11.0592 Mhz 10 ms
TH0 = HIGH_BIT;
TL0 = LOW_BIT;
EA=1;
ET0=1;
TR0=1;
for (;;) ;
}
C code for Frequency counter
#include <reg51.h>
unsigned long count = 0;
unsigned long show_count = 0;
unsigned char digest[11] =
{0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x83,0xF8,0x80,0x98,0xC6};
unsigned char scancode[8] = {0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80};
sbit P1_0 = P1^0;
#define HIGH_BIT 0xFB
#define LOW_BIT 0x80
void Disp(int id)
{
P2 = 0;
P2 = scancode[id];
P0 = 0xff;
switch (id)
{
35
case 0: P0 = digest[(show_count / 10000000) % 10]; break;
case 1: P0 = digest[(show_count / 1000000) % 10]; break;
case 2: P0 = digest[(show_count / 100000) % 10]; break;
case 3: P0 = digest[(show_count / 10000) % 10]; break;
case 4: P0 = digest[(show_count / 1000) % 10]; break;
case 5: P0 = digest[(show_count / 100) % 10]; break;
case 6: P0 = digest[(show_count /10) % 10]; break;
case 7: P0 = digest[show_count % 10]; break;
}
}
void Timer0() interrupt 1
{
static unsigned int scount = 0;
static unsigned char rcount = 0;
TH0 = HIGH_BIT;
TL0 = LOW_BIT + 34;
scount++;
if (scount == 800) //1 second
{
scount = 0;
show_count = count;
count = 0;
}else if (scount % 2 == 0)
{
rcount++;
if (rcount == 8) rcount = 0;
Disp(rcount);
}
count += (TH1 << 8) | TL1;
TH1 = TL1 = 0;
}
void main()
{
TMOD = 0x51;
// 11.0592 Mhz 1.152 ms
TH0 = HIGH_BIT;
TL0 = LOW_BIT;
//initalize output counter
TH1 = 0;
TL1 = 0;
EA=1;
ET0=1;
TR0=1;
TR1=1;
for (;;);
}
36
Capacitors
Capacitors store electric charge. They are used with resistors in timing circuits because it takes
time for a capacitor to fill with charge. They are used to smooth varying DC supplies by acting
as a reservoir of charge. They are also used in filter circuits because capacitors easily pass AC
(changing) signals but they block DC (constant) signals.
Capacitance
This is a measure of a capacitor's ability to store charge. A large capacitance means that more
charge can be stored. Capacitance is measured in farads, symbol F. However 1F is very large, so
prefixes are used to show the smaller values.
Three prefixes (multipliers) are used, µ (micro), n (nano) and p (pico):
µ means 10-6
(millionth), so 1000000µF = 1F
n means 10-9
(thousand-millionth), so 1000nF = 1µF
p means 10-12
(million-millionth), so 1000pF = 1nF
Capacitor values can be very difficult to find because there are many types of capacitor with
different labelling systems!
There are many types of capacitor but they can be split into two groups, polarised
and unpolarised. Each group has its own circuit symbol.
1) Polarised capacitors (large values, 1µF +)
Examples: Circuit symbol
2) Electrolytic Capacitors:
their leads will be marked + or -. They are not damaged by heat when soldering.
37
There are two designs of electrolytic capacitors; axial where the leads are attached to each end
(220µF in picture) and radial where both leads are at the same end (10µF in picture). Radial
capacitors Electrolytic capacitors are polarised and they must be connected the correct way
round, at least one of tend to be a little smaller and they stand upright on the circuit board.
It is easy to find the value of electrolytic capacitors because they are clearly printed with their
capacitance and voltage rating. The voltage rating can be quite low (6V for example) and it
should always be checked when selecting an electrolytic capacitor. If the project parts list does
not specify a voltage, choose a capacitor with a rating which is greater than the project's power
supply voltage. 25V is a sensible minimum for most battery circuits.
3) Tantalum Bead Capacitors
Tantalum bead capacitors are polarised and have low voltage ratings like electrolytic capacitors.
They are expensive but very small, so they are used where a large capacitance is needed in a
small size.
Modern tantalum bead capacitors are printed with their capacitance, voltage and polarity in full.
However older ones use a colour-code system which has two stripes (for the two digits) and a
spot of colour for the number of zeros to give the value in µF. The standard colour code is used,
but for the spot, grey is used to mean × 0.01 and white means × 0.1 so that values of less than
10µF can be shown. A third colour stripe near the leads shows the voltage (yellow 6.3V, black
10V, green 16V, blue 20V, grey 25V, white 30V, pink 35V). The positive (+) lead is to the right
when the spot is facing you: 'when the spot is in sight, the positive is to the
right'.
For example: blue, grey, black spot means 68µF
For example: blue, grey, white spot means 6.8µF
For example: blue, grey, grey spot means 0.68µF
4) unpolarised capacitors (small values, up to 1µF)
Examples: Circuit symbol:
Small value capacitors are unpolarised and may be connected either way round. They are not
damaged by heat when soldering, except for one unusual type (polystyrene). They have high
voltage ratings of at least 50V, usually 250V or so. It can be difficult to find the values of these
small capacitors because there are many types of them and several different labelling systems!
38
Many small value capacitors have their value printed but without a multiplier, so
you need to use experience to work out what the multiplier should be!
For example 0.1 means 0.1µF = 100nF.
Sometimes the multiplier is used in place of the decimal point:
For example: 4n7 means 4.7nF.
Capacitor Number Code
A number code is often used on small capacitors where printing is difficult:
the 1st number is the 1st digit,
the 2nd number is the 2nd digit,
the 3rd number is the number of zeros to give the capacitance in pF.
Ignore any letters - they just indicate tolerance and voltage rating.
For example: 102 means 1000pF = 1nF (not 102pF!)
For example: 472J means 4700pF = 4.7nF (J means 5% tolerance).
Colour Code
Colour Number
Black 0
Brown 1
Red 2
Orange 3
Yellow 4
Green 5
Blue 6
Violet 7
39
Capacitor Colour Code
A colour code was used on polyester capacitors for many years. It is now
obsolete, but of course there are many still around. The colours should be read
like the resistor code, the top three colour bands giving the value in pF. Ignore
the 4th band (tolerance) and 5th band (voltage rating).
For example:
brown, black, orange means 10000pF = 10nF = 0.01µF.
Note that there are no gaps between the colour bands, so 2 identical bands
actually appear as a wide band.
For example:
wide red, yellow means 220nF = 0.22µF.
5) Polystyrene Capacitors
This type is rarely used now. Their value (in pF) is normally printed
without units. Polystyrene capacitors can be damaged by heat when
soldering (it melts the polystyrene!) so you should use a heat sink (such as a crocodile clip). Clip
the heat sink to the lead between the capacitor and the joint.
Real capacitor values (the E3 and E6 series)
You may have noticed that capacitors are not available with every possible value, for example
22µF and 47µF are readily available, but 25µF and 50µF are not!
Why is this? Imagine that you decided to make capacitors every 10µF giving 10, 20, 30, 40, 50
and so on. That seems fine, but what happens when you reach 1000? It would be pointless to
make 1000, 1010, 1020, 1030 and so on because for these values 10 is a very small difference,
too small to be noticeable in most circuits and capacitors cannot be made with that accuracy.
To produce a sensible range of capacitor values you need to increase the size of the 'step' as the
value increases. The standard capacitor values are based on this idea and they form a series
which follows the same pattern for every multiple of ten.
The E3 series (3 values for each multiple of ten)
10, 22, 47, ... then it continues 100, 220, 470, 1000, 2200, 4700, 10000 etc.
Notice how the step size increases as the value increases (values roughly double each time).
Grey 8
White 9
40
The E6 series (6 values for each multiple of ten)
10, 15, 22, 33, 47, 68, ... then it continues 100, 150, 220, 330, 470, 680, 1000 etc.
Notice how this is the E3 series with an extra value in the gaps.
The E3 series is the one most frequently used for capacitors because many types cannot be made
with very accurate values.
6) Variable capacitors
Variable capacitors are mostly used in radio tuning circuits and
they are sometimes called 'tuning capacitors'. They have very
small capacitance values, typically between 100pF and 500pF
(100pF = 0.0001µF). The type illustrated usually has trimmers
built in (for making small adjustments - see below) as well as
the main variable capacitor.
Many variable capacitors have very short spindles which are
not suitable for the standard knobs used for variable resistors
and rotary switches. It would be wise to check that a suitable
knob is available before ordering a variable capacitor.
Variable capacitors are not normally used in timing circuits
because their capacitance is too small to be practical and the
range of values available is very limited. Instead timing circuits
use a fixed capacitor and a variable resistor if it is necessary to
vary the time period.
Variable Capacitor Symbol
Variable Capacitor
Photograph © Rapid Electronics
41
7) Trimmer capacitors
Trimmer capacitors (trimmers) are miniature
variable capacitors. They are designed to be
mounted directly onto the circuit board and
adjusted only when the circuit is built.
A small screwdriver or similar tool is required
to adjust trimmers. The process of adjusting
them requires patience because the presence of
your hand and the tool will slightly change the
capacitance of the circuit in the region of the
trimmer!
Trimmer capacitors are only available with
very small capacitances, normally less than
100pF. It is impossible to reduce their
capacitance to zero, so they are usually
specified by their mini
Micro controller code:
;**************************************************************************
$mod52
;project : freq count2.asm
;processor : 89S52 @11.0592Mhz
;hardware ;
;software : v1.0
;START DATE : 100419 10pm
;end_date :
;source : freq count1.asm
;remarks :
;**************************************************************************
;ports allocation
bzr equ p1.0 ; active high
diag equ p1.1
;ZCROSS equ p1.2
LCD_DATA equ p2 ; P2.4 to p2.7 as LCD data bits DB4 to DB7
BKLIT equ p2.0 ; LCD Backlight
LCD_DB7 equ p2.1 ; data bit 7, low nibble of port 2 is used for
data
LCD_DB6 equ p2.2 ; data bit 6
LCD_DB5 equ p2.3 ; data bit 5
LCD_DB4 equ p2.4 ; data bit 4
LCD_EN equ p2.5 ; lcd enable line
LCD_RS equ p2.6 ; LCD Register select
IrInput equ p3.2
Trimmer Capacitor Symbol
TrimmerCapacitor
Photograph
42
;**************************************************************************
;FLAGS
;**************************************************************************
UpdateLCD equ 0H
FBIT1 bit 01
;**************************************************************************
;internal variables
;**************************************************************************
V1 data 21h
V2 data 22h
V3 data 23h
V4 data 24h
Var1 data 27h
Var2 data 28h
Var3 data 29h
var4 equ r2
temp equ r3
temp1 equ r4
delay equ r5
tick equ r6
Freq equ r7
;4Byte hex 2 Dec conv variables
XX0 equ 30H
XX1 equ 31H
XX2 equ 32H
XX3 equ 33H
YY0 equ 34H
YY1 equ 35H
YY2 equ 36H
YY3 equ 37H
YY4 equ 38H
ZZ0 equ 39H
ZZ1 equ 3AH
ZZ2 equ 3BH
ZZ3 equ 3CH
ZZ4 equ 3DH
BITS equ 3EH
;**************************************************************************
;constants
;**************************************************************************
stack equ 60h
cx1 equ 06h
cx2 equ 45h
cx3 equ 19h
cx4 equ 99h
cx5 equ 99h
cx6 equ 99h
lx1 equ 05h
lx2 equ 18h
lx3 equ 04h
lx4 equ 39h
lx5 equ 99h
lx6 equ 99h
Config equ 28h ; 4 bit data, 2 lines, 5 by 7 character matrix
43
entryMode equ 06h ; increment cursor, do not shift display
offCur equ 0Ch ; cursor control instructions start here
lineCur equ 0Eh
blinkCur equ 0Dh
combnCur equ 0Fh
homeCur equ 02h
shLfCur equ 10h
shRtCur equ 14h
clrDsp equ 01h ; display control instructions start here
offDsp equ 0Ah
onDsp equ 0Eh
shLfDsp equ 18h
shRtDsp equ 1Ch
;**************************************************************************
;vector table
;**************************************************************************
org 0000h
ljmp LPOWER_ON ;Power ON Interrupt Vector
org 0003h ;external INT-0
reti
org 000bh
Ajmp TIMER0_ISR ;Timer 0 overflow Interrupt Vector
org 0013h ;external INT-1
reti
org 001bh ;Timer 1 overflow Interrupt Vector
Ajmp TIMER1_ISR ;Timer 0 overflow Interrupt Vector
org 0023h ;serial interrupt
reti
;**************************************************************************
org 0100h
;**************************************************************************
mov dptr,#prj
call disp_mess1
mov dptr,#by
call disp_mess2
call dly1S
call dly1S
call dly1S
call dly1S
call dly1S
;**************************************************************************
Lmainlp: ;main routine starts here
;**************************************************************************
clr UpdateLCD
mov dptr,#m_1
call disp_mess1
main: mov a,#86H
acall wrLCDcom4
mov TH0, #3CH
44
mov TL0, #0BAH
mov tick, #20
mov Freq, #0
mov TH1, #0
mov TL1, #0
setb TR0
setb TR1
abc: cpl p1.2
jnb UpdateLCD,abc
clr UpdateLCD
mov XX2,Freq
mov XX1,TH1
mov XX0,TL1
acall X2D
mov a,ZZ3
acall disp_num
mov a,ZZ2
acall disp_num
mov a,ZZ1
acall disp_num
mov a,ZZ0
acall disp_num
;;;;;;;;;;;;; Display component values ;;;;;;;;;;;;;;;;;;;
call clr_mess2
mov a,ZZ2
?cx1: cjne a,#cx1,?cx2
mov dptr,#mcx1
call disp_mess2
?cx2: cjne a,#cx2,?cx3
mov dptr,#mcx2
call disp_mess2
?cx3: cjne a,#cx3,?cx4
mov dptr,#mcx3
call disp_mess2
?cx4: cjne a,#cx4,?cx5
mov dptr,#mcx4
call disp_mess2
?cx5: cjne a,#cx5,?cx6
mov dptr,#mcx5
call disp_mess2
?cx6: cjne a,#cx6,?lx1
mov dptr,#mcx6
call disp_mess2
?lx1: cjne a,#lx1,?lx2
mov dptr,#mlx1
call disp_mess2
?lx2: cjne a,#lx2,?lx3
mov dptr,#mlx2
call disp_mess2
?lx3: cjne a,#lx3,?lx4
mov dptr,#mlx3
45
call disp_mess2
?lx4: cjne a,#lx4,?lx5
mov dptr,#mlx4
call disp_mess2
?lx5: cjne a,#lx5,?lx6
mov dptr,#mlx5
call disp_mess2
?lx6: cjne a,#lx6,?end
mov dptr,#mlx6
call disp_mess2
?end:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ajmp main
;**************************************************************************
disp_num:
mov DPTR,#hex_table
mov temp1,a
anl a,#0F0H
swap a
movc a,@a+DPTR
acall disp_digit
mov a,temp1
anl a,#0FH
movc a,@a+dptr
acall disp_digit
ret
;**************************************************************************
X2D: CALL CLEARYZ ;;Clear All YY and ZZ bytes
MOV YY0,#1 ;;DECIMAL ADDER = 1
; ;;
MOV R0,#XX3 ;;LOCATE HOW MANY BYTES WITH DATA
MOV B,#4 ;;POSSIBLE 8 BYTES W/DATA ON XX
BITS1: MOV A,@R0 ;;GET BYTE FROM INPUT REGISTER
CJNE A,#0,BITS2 ;;JUMP IF FOUND THE FIRST NON ZERO
DEC R0 ;;GO TO LOWER BYTE
DJNZ B,BITS1 ;;ONE BYTE DONE, GO AGAIN
;;
BITS2: MOV A,#8 ;;8 BITS PER BYTE, B CONTAINS BYTE #
MUL AB ;;A = QUANTITY OF BITS W/DATA
MOV BITS,A ;;SAVE
CJNE A,#0,X2DMAIN2 ;;B = NUMBER OF DIGITS W/DATA
RET ;;RETURN IF ONLY ZEROS AT XX
;;
X2DMAIN1: CALL X2DSHIFTD ;;SHIFT DECIMAL RESULT
X2DMAIN2: CALL X2DSHIFTH ;;SHIFT HEXA
JNC X2DMAIN3 ;;IF NOT CARRY, JUST SKIP IT
CALL X2DADD ;;ADD NEW RESULT
X2DMAIN3: DJNZ BITS,X2DMAIN1 ;;ONE BIT DONE, GO AGAIN
RET ;;GENERAL EXIT FROM THIS ROUTINE
;;ZZ0 - ZZ7 CONTAINS DECIMAL RESULT
;;
X2DSHIFTD: MOV R0,#YY0 ;;YY * 2 (DECIMAL)
MOV B,#4 ;;NUMBER OF BYTES
CLR C ;;NEED CARRY ZERO
X2DSHIFTD1: MOV A,@R0 ;;IGNORE LAST CARRY
ADDC A,@R0 ;;ADD BYTE TO ITSELF
46
DA A ;;DECIMAL ADJUST
MOV @R0,A ;;PUT IT BACK
INC R0 ;;GO TO UPPER BYTE
DJNZ B,X2DSHIFTD1 ;;DO IT 8 BYTES
RET ;;RETURN
;;
X2DSHIFTH: MOV R0,#XX3 ;;SHIFT XX7 --> XX0 RIGHT 1 BIT
MOV B,#4 ;;NUMBER OF BYTES
SHIFTR0B: CLR C ;;NEED CARRY ZERO
SHIFTR0B1: MOV A,@R0 ;;GET BYTE
RRC A ;;ROTATE RIGHT THROUGH CARRY BIT
MOV @R0,A ;;SAVE IT BACK
DEC R0 ;;GO TO LOWER BYTE
DJNZ B,SHIFTR0B1 ;;DO IT AGAIN "B" TIMES
RET ;;RETURN
;;
X2DADD: MOV R0,#ZZ0 ;; GET RESULT ZZ 8 BYTES REGISTER
MOV B,#4 ;; 8 BYTES
MOV R1,#YY0 ;; GET YY OPERATOR
CLR C ;; NEED CARRY OFF
X2DADD1: MOV A,@R0 ;; ZZ = ZZ + YY (8BYTES) W/DAA
ADDC A,@R1 ;; ADD BYTE TO BYTE 8 TIMES
DA A ;; DECIMAL ADJUST
MOV @R0,A ;; PUT IT BACK
INC R0 ;; BUMP POINTER NEXT BYTE
INC R1 ;; BUMP POINTER NEXT BYTE
DJNZ B,X2DADD1 ;; ONE BYTE DONE, GO AGAIN
MOV A,ZZ3 ;; LAST CARRY TO 9TH BYTE OF ZZ
ADDC A,#0 ;; JUST CARRY TO ZZ8
MOV ZZ3,A ;;
RET ;; RETURN
CLEARYZ:
mov r1,#9
clr A
mov r0,#YY0
CLEARYZ_1:
mov @r0,A
inc r0
djnz r1, CLEARYZ_1
ret
hex_table:
db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
;**************************************************************************
; Time0 isr get IRaddr,IRdata, ;225us
;**************************************************************************
TIMER0_ISR:
djnz tick, TMR0_ISR_GO
clr TR1
clr TF1
clr TR0
clr TF0
setb UpdateLCD
cpl diag
reti
TMR0_ISR_GO:
47
mov TH0, #3CH
mov TL0, #0BAH
RETI
;----------------------------------------------------------------------------
---------
; Time1 isr get IRaddr,IRdata, ;225us
;----------------------------------------------------------------------------
---------
TIMER1_ISR:
inc Freq
RETI
;**************************************************************************
;delay routines
;**************************************************************************
Dly1: MOV R7,#31h
DJNZ R7,$
DJNZ ACC,Dly1
RET
dly25ms:
MOV VAR2,#45
MOV VAR1,#207
D25ms:DJNZ VAR1,D25ms
DJNZ VAR2,D25ms
RET
dly50ms:
call dly25ms
call dly25ms
ret
dly100ms:
MOV VAR2,#180
MOV VAR1,#72
D100ms:
DJNZ VAR1,D100ms
DJNZ VAR2,D100ms
RET
dly200ms:
call dly100ms
call dly100ms
ret
dly500ms:
MOV VAR3,#4
MOV VAR2,#132
MOV VAR1,#116
D5ms: DJNZ VAR1,D5ms
DJNZ VAR2,D5ms
DJNZ VAR3,D5ms
RET
dly1s:MOV VAR3,#8
MOV VAR2,#8
MOV VAR1,#236
TT1: DJNZ VAR1,TT1
DJNZ VAR2,TT1
DJNZ VAR3,TT1
RET
48
;**************************************************************************
messages:
;**************************************************************************
; org 0BDDH 1234567812345678
m_1: db 'FREQ: Hz',0
mcx1: db 'CX: 0.1 uF ',0
mcx2: db 'CX: 1.0 nF ',0
mcx3: db 'CX: 10 nF ',0
mcx4: db 'CX: ',0
mcx5: db 'CX: ',0
mcx6: db 'CX: ',0
mlx1: db 'LX: 1.0 UH ',0
mlx2: db 'LX: 1.0 mH ',0
mlx3: db 'LX: 15 mH ',0
mlx4: db 'LX: 100 uH ',0
mlx5: db 'LX: ',0
mlx6: db 'LX: ',0
prj: db 'LCF METER PRJ BY',0
by: db 'NARESH & BHASKAR',0
;**************************************************************************
;LCD ROUTINES END HERE
;**************************************************************************
end
Capacitance meter code
#include <reg51.h>
unsigned char j,n,t,DispBuf[4];
unsigned int cap;
unsigned char code
BitTab[4]={0xbf,0xdf,0xef,0xf7};
unsigned char code
DispTab[11]={0xfe,0x70,0xed,0xf9,0x73,0xdb,0xdf,0xf0,0xff,0xfb,0x40};
sbit P1_2=P1^2;
sbit P3_6=P3^6;
main()
{ TMOD=0x11;
TH1=0xec;
TL1=0x78;
IE=0X88;
TR1=1;
for(;;)
;
49
}
Timer1() interrupt 3
{ TH1=0xec;
TL1=0x78;
t=BitTab[j];
P1=P1|0x78;
P1=P1&t;
t=DispBuf[j];
t=DispTab[t];
P3=t;
j++;
if(j==4)
j=0;
n++;
if(n==48)
{
n=0;
TH0=0;
TL0=0;
P1_2=1;
TR0=1;
for(;P3_6==0;)
;
TR0=0;
P1_2=0;
cap=TL0|(TH0<<8);
cap=cap-3;
if(cap>=2000)
{
50
DispBuf[3]=10;
DispBuf[2]=10;
DispBuf[1]=10;
DispBuf[0]=1;
}
if(cap<2000)
{
DispBuf[3]=cap%10;
cap=cap/10;
DispBuf[2]=cap%10;
cap=cap/10;
DispBuf[1]=cap%10;
DispBuf[0]=cap/10;
}
}
}
51