Professional Documents
Culture Documents
1
COMPONENTS USED
AT89C2051
8-bit Microcontroller with 2K Bytes Flash
Features
Description
2
two-level interrupt architecture, a full duplex serial port, a precision analog
comparator, on-chip oscillator and clock circuitry. In addition, the AT89C2051 is
designed with static logic for operation down to zero frequency and supports two
software selectable power saving modes. The Idle Mode stops the CPU while
allowing the RAM, timer/counters, serial port and interrupt system to continue
functioning. The power-down mode saves the RAM contents but freezes the
oscillator disabling all other chip functions until the next hardware reset.
3
4
Pin Description
VCC
Supply voltage.
GND
Ground.
Port 1
Port 1 is an 8-bit bi-irectional I/O port. Port pins P1.2 to P1.7 provide
internal pullups. P1.0 and P1.1 require external pullups. P1.0 and P1.1 also serve as
the positive input(AIN0) and the negative input (AIN1), respectively, of the on-
chip precision analog comparator. The Port 1 output buffers can sink 20 mA and
can drive LED displays directly.
When 1s are written to Port 1 pins, they can be used as inputs. When pins
P1.2 to P1.7 are used as inputs and are externally pulled low, they will source
current (IIL) because of the internal pullups. Port 1 also receives code data during
Flash programming and verification.
Port 3
Port 3 pins P3.0 to P3.5, P3.7 are seven bi-irectional I/O pins with internal
pullups. P3.6 is hard-wired as an input to the output of the on-chip comparator and
is not accessible as a general purpose I/O pin. The Port 3 output buffers can sink 20
mA. When 1s are written to Port 3 pins they are pulled high by the internal pullups
and can be used as inputs. As inputs, Port 3 pins that are externally being
pulled low will source current (IIL) because of the pullups.
5
Port 3 also receives some control signals for Flash programming and verification.
RST
Reset input. All I/O pins are reset to 1s as soon as RST goes high. Holding
the RST pin high for two machine cycles while the oscillator is running resets the
device.
XTAL1
Input to the inverting oscillator amplifier and input to the internal clock
operating circuit.
XTAL2
Oscillator Characteristics
XTAL1 and XTAL2 are the input and output, respectively, of an inverting
amplifier which can be configured for use as an on-chip oscillator, as shown in
Figure 1. Either a quartz crystal or ceramic resonator may be used. To drive the
device from an external clock source, XTAL2 should be left unconnected while
XTAL1 is driven as shown in Figure 2. There are no requirements on the duty
cycle of the external clock signal, since the input to the internal clocking circuitry
is through a divide-by-two flip-flop, but minimum and maximum voltage high and
low time specifications must be observed.
6
Special Function Registers
A map of the on-chip memory area called the Special Function Register
(SFR) space is shown in the table below. Note that not all of the addresses are
occupied, and unoccupied addresses may not be implemented on the chip. Read
accesses to these addresses will in general return random data, and write accesses
will have an indeterminate effect.
User software should not write 1s to these unlisted locations, since they may
be used in future products to invoke new features. In that case, the reset or inactive
values of the new bits will always be 0.
7
8
Programming Algorithm: To program the AT89C2051,the following sequence
is recommended.
1. Power-up sequence: Apply power between VCC and GND pins Set RST and
XTAL1 to GND
3. Apply the appropriate combination of “H” or “L” logic levels to pins P3.3, P3.4,
P3.5, P3.7 to select one of the programming operations shown in the PEROM
Programming Modes table. To Program and Verify the Array:
6. Pulse P3.2 once to program a byte in the PEROM array or the lock bits. The
byte-write cycle is self-timed and typically takes 1.2 ms.
7. To verify the programmed data, lower RST from 12V to logic “H” level and set
pins P3.3 to P3.7 to the appropiate levels. Output data can be read at the port P1
pins.
8. To program a byte at the next address location, pulse XTAL1 pin once to
advance the internal address counter. Apply new data to the port P1 pins.
9. Repeat steps 5 through 8, changing data and advancing the address counter for
the entire 2K bytes array or until the end of the object file is reached.
9
LIQUID CRYSTAL DISPLAYS (LCD)
It has just a 12 m thin layer of liquid between two or more sheets of glass
cum polarizer filters. One glass plate has the 7 segment electrodes etched on it and
a conductive coating of tin oxide or Tin cum Indium oxide. The other plate has the
common electrode. The conductive coat is treated further for good surface contact
to liquid. The cell when assembled appears as clear glass: the segments are not
visible.
When a voltage is applied between the plates, the molecules move with the
dipoles aligned in the cell axis. Thus those regions under the segments, which have
the electric field, have a contrasty appearance when viewed in light, while other
unexcite segments are invisible.
The voltage needed is preferable 2-20 V A.C. The cathode (or front plane)
voltage input to the LCD goes through an ‘analog switch’ that is on at any time so
that a.c. voltage is applied to the appropriate segment. The anode (back plane)
receives the a.c. supply. The display driving switches are from a set of MOSFET
10
switches, which also form part of Integrated circuit. For eg. C 1200 clock LSI I.C.
chip from Computer Syst. Inc, USA, is a digital clock chip with the LCD display
driver. Turn on time for the LCD displays vary form 0.2-100 millisecs, depending
on voltage applied. Turn of time is 30-100ms. So these displays are not suitable for
very fast changing numbers. The power consumption is 1to 10 micro watt/cm2. The
voltage threshold for watch type LCD display is 1 to 2V. The operating a.c.
frequency is 50-100 KHz.
In another method dc pulses of identical amplitude are used: One pulse to
the back electrode and another to the display segment via and exclusive OR gate.
In the OFF state, the pulses are in-phase; in the ON-state, they are out of phase.
The frequency is 30-32 Hz. The power consumption for a LCD watch is roughly
45 W, which is 1/1000th of that for LED displays.
A sample photo of the LCD module is shown in Fig. 1. These modules are
available in 14- and 16-pin configurations. The 16-pin module has a back light
option. Popular brands are Lampex and Hantronix. Note the pin numbers before
soldering to the circuit.
In this project, the LCD module used is Lampex LM16200 with 16 alphanumeric
characters and two lines with back light option. Pin details of this module are given
in Table I. A functional diagram of the module is shown in fig. 2.
11
TABLE I
Pin details of LM16200
Pin No. Description Pin No. Description
1 Gnd 5 R/W
2 Vcc 6 E
3 Vo 7 to 14 DB0 to DB7
4 RS 15 & 16 LED BL A & K
12
Fig. 2 : Functional diagram of the LCD module
However, you may use any branded or unbranded 2-line, 16-character LCD
module for this project. The 10k potentiometer, which controls the contrast of the
LCD module, works best when its wiper contact is nearer to ground potential.
13
THE ADAPTING 3-TERMINAL VOLTAGE
REGULATORS FOR CONSTANT HIGH
VOLTAGE POWER SUPPLIES
One can get a constant high-voltage power supply using inexpensive 3-terminal
voltage regulators through some simple techniques described below. Depending
upon the current requirement, a reasonable load regulation can be achieved. Line
regulation in all cases is equal to that of the voltage regulator used.
Though high voltage can be obtained with suitable voltage boost circuitry
using ICs like LM 723, some advantages of the circuits presented below are:
simplicity, low cost, and practically reasonable regulation characteristics. For
currents of the order of 1A or less, only one zener and some resistors and
capacitors are needed. For higher currents, one pass transistor such as ECP055 is
needed.
Before developing the final circuits, let us first understand the 3-terminal type constant voltage regulators.
Let us see the schematic in Fig. where 78XX is a 3-terminal voltage regulator.
Schematic for obtaining low-voltage regulated output using 3-terminal voltage regulators.
Rectified
and filtered
unregulated voltage is applied at VIN and a constant voltage appears between pins
2 and 2 of the voltage regulator. *The distribution of two currents in the circuit
(IBIAS and ILOAD) is as shown.
14
It is highly recommended to use the two capacitors as shown. Electrically
regulator will be at a distance from the rectifier supply. Thus, a tantalum grade
capacitor of 5mf and rated voltage is good.
Electrolytic capacitor is not suitable for it is poor in response to load transients,
which have high frequency components. At the output side a 0.22mf disc ceramic
capacitor is useful to eliminate spurious oscillations, which the regulator might
break into because of its internal high gain circuitry.
Now let us see that what can be done to get a higher but constant output
voltage. If to the circuit of Fig. resistor RY and zener Vz are added as shown in
Fig., the output voltage is now given by
VOUT=VR+VZ + IBIAS RX
VOZ=VR + IBIAS Rx
Here the pin 2 of the regulator is raised above ground by Vz + IBIAS Rx.
Thus, any combination of zener with a proper selection of RY can be used.
IBIAS=5mA
VZ=39V (standard from ECIL)
15
For a standard 400mW zener of ECIL make, IZ MAX=10 mA. Thus, if we
let pass 5mA through RY to make a 55-volt supply.
55 - 39
RY = ---------------=3.2k»3.3k
5 x 10-3
55 - 39 - 15 1
RX = ---------------------= ---------- = 200 ohm
IBIAS 5 x 10-3
It should be noted here that the maximum input voltage allowed for 78XX
regulators is 35V between pins 1 and 2. We see that the actual voltage betweens
pin 1 and 2 of the regulator in this circuit is
VIN - VZ - IBIAS RX
It is therefore necessary that VIN be so chosen that voltage between pins 1
and 2 of the IC does not exceed the maximum rating. Also, a high input-output
differential voltage VIN-VOUT means more power dissipation in the series-pass
element, the regulator. Thus, with proper selection of the input transformer voltage
and capacitor, this should be minimized.
16
VIN MIN = 45 + 7 - 5 = 47 VOLTS
Thus, from no-load to full-load condition, the unregulated input voltage-
including peak ripple-should be within these limits. This gives a margin of 75-47,
i.e. 28 volt. Hence, the designer can work out the maximum transformer voltage
from the no-load input voltage chosen on the upper side.
The capacitor's value can be determined from the full load unregulated
voltage chosen. Roughly, per 100mA current, 100mf capacitor gives 1-volt peak-
to-peak ripple. Hence, capacitor's value can be determined for the desired current.
This circuit will have an excellent load and line regulation. For shot-circuit
protection, it is recommended to use a fast-blow fuse of suitable value. Although
the regulator has inherent short-circuit protection, the maximum current differs
from device to device. Adequate heat sink should be used with the regulator.
Schematic for constant high-voltage power supplies providing currents in excess of one ampere
Now if currents in excess of 1A are needed, the circuit shown in fig. is useful. This
circuit is similar to that in Fig. except that a pass transistor ECP055 is added
17
besides a 0.5-ohm or more resistor. This transistor bypasses the excessive current.
By selecting proper Rz the ratio of two currents passing through the regulator and
transistor can be altered.
This circuit will show load and live regulation within 1% and will function
properly for VIN-VOUT as low as 4 volt. For short-circuit protection, a fast blow
fuse is recommended as this circuit does not have inherent short-circuit protection.
Adequate heat sink is to be used for the pass transistors. For negative voltages,
use 79XX series regulators and ECN055 as the pass transistor. Some advantages of
the circuits described above are: the lowest cost among comparable performance
circuits, ability to work at low input-output differential, and flexibility in design for
various applications.
So audio enthusiasts, if you are troubled by hum emanating from your power
amplifier, try this inexpensive alternative for power supply.
The 555 integrated circuit is an extremely versatile timer that can be used in
many different applications. This IC is a monolithic timing circuit that is a highly
18
stable controller capable of producing accurate time delays or oscillations.
Additional terminals are producing are provided for triggering or resetting if
desires. In the time delay mode of resistance and a capacitor. For a stable operation
as an oscillator, the free running frequency and the duty cycle are both accurately
controlled with two external resistors and one capacitor. The circuit may be
triggered and reset on falling waveforms, and the output structure can source or
sink up to 200ma or drive TTL Circuits.
The 555 timer offers timing from microseconds through hours and operates
in both astable and monostable modes. It has an adjustable duty cycle, and the
output can drive TTL devices. Its output can operate in normally on and normally
off modes and the IC offers a frequency stability of 0.005% per degrees centigrade.
Applications for the 555 chip include precision timing, pulse generation,
pulse width modulation, pulse position modulation, sequential timing, and missing
pulse detection.
19
555-INTEGRATED CIRCUIT
IC 555-ASTABLE OPERATIONS: -
f= 1.46
(Ra + 2Rb) C
21
IC 555-MONOSTABLE OPERATIONS: -
t = Ra C
When the voltage across the capacitor equals 2/3 Vcc. The comparator resets
the flip-flop, which, in turn, discharges the capacitor rapidly and drives the output
to its low state. Figure shows the actual waveforms generated in this mode of
operation.
The circuit triggers on a negative going input signal when the level reaches
1/3 Vcc. Once triggered, the circuit will remain in this state until the set time is
22
elapsed, even if it is triggered again during this interval. The time that the output is
in the high state is given by: t= 1.1 Ra C
Applying a negative pulse to the reset terminal (pin 4) during the timing
cycle discharges the external capacitor and causes the cycle to start over again. The
timing cycle will now commence on the positive edge of the reset pulse. During
the time the reset pulse is applied, the output is driven to its low state.
TRANSISTOR
23
three terminals, one is the collector, one is the base and other is the emitter, (each
lead must be connected in the circuit correctly and only then the transistor will
function). Electrons are emitted via one terminal and collected on another terminal,
while the third terminal acts as a control element. Each transistor has a number
marked on its body. Every number has its own specifications.
There are mainly two types of transistor (i) NPN & (ii) PNP
NPN Transistors:
PNP Transistor:
It also does exactly same thing as above except that it has a negative voltage
on its collector and a positive voltage on its emitter.
24
Junction transistors are of two types which can be obtained while
manufacturing.
P N P
2) NPN
TYPE: This is formed by joining a
layer of germanium to a P- N
Junction.
N P N
Both types
are shown in figure, with their symbols for
representation. The centre section is called the
base, one of the outside sections-the emitter and
the other outside section-the collector. The direction of the arrowhead gives the
direction of the conventional current with the forward bias on the emitter. The
conventional flow is opposite in direction to the electron flow.
25
The majority carriers (holes) of P region (known as emitter) move to N
region as they are repelled by the positive terminal of battery while the electrons of
N region are attracted by the positive terminal. The holes overcome the barrier and
cross the emitter junction into N region. As the width of base region is extremely
thin, two to five percent of holes recombine with the free electrons of N-region
which result in a small base current while the remaining holes (95% to 98%) reach the
collector junction. The collector is biased negatively and the negative collector
voltage aids in sweeping the hole into collector region.
As the P region at the right is biased negatively, a very small current should
flow but the following facts are observed:-
2) The current flowing across the collector is slightly less than that of the
emitter, and
3) The collector current is a function of emitter current i.e. with the decrease
or increase in the emitter current a corresponding change in the collector
current is observed.
26
The facts can be explained as follows:-
2. The collector current increases as the holes reaching the collector junction
are attracted by negative potential applied to the collector.
3. When the emitter current increases, most holes are injected into the base
region, which is attracted by the negative potential of the collector and hence
results in increasing the collector current. In this way emitter is analogous to
the control of plate current by small grid voltage in a vacuum triode.
Hence we can say that when the emitter is forward biased and collector is
negatively biased, a substantial current flows in both the circuits. Since a small
emitter voltage of about 0.1 to 0.5 volts permits the flow of an appreciable emitter
current the input power is very small. The collector voltage can be as high as 45
volts.
CD4049UBC • CD4050BC
Hex Inverting Buffer •
Hex Non-Inverting Buffer
General Description
27
Features
Applications
28
CAPACITORS
RESISTANCE
29
Resistance is the opposition of a material to the current. It is measured in
Ohms ( ). All conductors represent a certain amount of resistance, since no
conductor is 100% efficient. To control the electron flow (current) in a predictable
manner, we use resistors. Electronic circuits use calibrated lumped resistance to
control the flow of current. Broadly speaking, resistor can be divided into two
groups viz. fixed & adjustable (variable) resistors. In fixed resistors, the value is
fixed & cannot be varied. In variable resistors, the resistance value can be varied
by an adjuster knob. It can be divided into (a) Carbon composition (b) Wire wound
(c) Special type. The most common type of resistors used in our projects is carbon
type. The resistance value is normally indicated by colour bands. Each resistance
has four colours, one of the band on either side will be gold or silver, this is called
fourth band and indicates the tolerance, others three band will give the value of
resistance (see table). For example if a resistor has the following marking on it say
red, violet, gold. Comparing these coloured rings with the colour code, its value is
27000 ohms or 27 kilo ohms and its tolerance is ±5%. Resistor comes in various
sizes (Power rating). The bigger, the size, the more power rating of 1/4 watts. The
four colour rings on its body tells us the value of resistor value as given below.
COLOURS CODE
Black--------------------------------------------0
Brown-------------------------------------------1
Red----------------------------------------------2
Orange------------------------------------------3
Yellow------------------------------------------4
Green--------------------------------------------5
Blue----------------------------------------------6
Violet--------------------------------------------7
Grey---------------------------------------------8
White--------------------------------------------9
30
The first rings give the first digit. The second ring gives the second digit.
The third ring indicates the number of zeroes to be placed after the digits. The
fourth ring gives tolerance (gold ±5%, silver ± 10%, No colour ± 20%).
Resistance coils of different values are connected b/w the gaps. When the
knob is rotated, the pointer also moves over the brass pieces. If a gap is skipped
over, its resistance is included in the circuit. If two gaps are skipped over, the
resistances of both together are included in the circuit and so on.
A dial type of resistance box contains many dials depending upon the range,
which it has to cover. If a resistance box has to read upto 10,000, it will have
three dials each having ten gaps i.e. ten resistance coils each of resistance 10.
The third dial will have ten resistances each of 100.
The dial type of resistance boxes is better because the contact resistance in
this case is small & constant.
31
CIRCUIT DESCRIPTION
Fig. 3 shows the circuit of the frequency counter including the power supply. The
microcontroller used is AT89C2051, which features 2 kB of Flash, 128 bytes of
RAM, 15 input/output (I/O) lines, two 16-bit timers/ counters, a five-vector two-
level interrupt architecture, a full-duplex serial port, a precision analogue
comparator, an on-chip oscillator and clock circuitry.
Port-1 is used to drive the LCD in 4-bit mode with 10-kilo-ohm pull-up resistors.
The 24MHz crystal used gives a processing speed of 2 million instructions per
second (MIPS).
32
The LCD module is used in the 4-bit data interface mode, wherein only data pins
DB4 through DB7 are used for data transfer. The configuration used is shown in
Table II.
TABLE II
LCD Connections Used for
4-Bit Data Mode
LCD Display Port Pin
DB7 P1.7 14
DB6 P1.6 13
DB5 P1.5 12
DB4 P1.4 11
E P1.3 6
RS P1.2 4
RW Ground 5
Vss Ground 1
Vdd +5 volt 2
Vo 0-5 volt 3
33
PRINTED CIRCUIT BOARD
Printed circuit boards are used for housing components to make a circuit, for
comactness, simplicity of servicing and ease of interconnection. Single sided,
double sided and double sided with plated-through-hold (PYH) types of p.c boards
are common today.
Boards are of two types of material (1) phenolic paper based material (2)
Glass epoxy material. Both materials are available as laminate sheets with copper
cladding.
Printed circuit boards have a copper cladding on one or both sides. In both
boards, pasting thin copper foil on the board during curing does this. Boards are
prepared in sizes of 1 to 5 metre wide and upto 2 metres long. The thickness of the
boards is 1.42 to 1.8mm. The copper on the boards is about 0.2 thick and weighs
and ounce per square foot.
An actual-size, single-side PCB for the LCD frequency meter (Fig. 3) is shown in
Fig. 5 and its component layout in Fig. 6.
34
Fig. 5: Actual-size, single-side PCB layout for frequency meter
COMPONENTS REQUIRED
35
SEMICONDUCTORS
IC1.......................................................7805 5V regulator
IC2.......................................................AT89C2051 microcontroller
IC3.......................................................CD4050 hex buffer
T1.........................................................BC547 npn transistor
D1-D4..................................................IN4007 rectifier diode
D5........................................................IN4148 switching diode
LED1...................................................5mm LED
RESISTORS
R1.........................................................1-kilo-ohm
R2, R4, R6-R9.....................................10-kilo-ohm
R3.........................................................4.7-kilo-ohm
R5.........................................................150-ohm
CAPACITORS
C1.........................................................1000 F, 25V electrolytic
C2, C3, C7...........................................0.1F ceramic disk
C4, C5..................................................22pF ceramic disk
C6.........................................................10F, 16V electrolytic
MISCELLANEOUS
36
X1........................................................230V AC primary to 9V,
250mA secondary transformer
S1.........................................................ON/OFF switch
S2.........................................................Push-to-on switch
XTAL......................................................24 MHz
...........................................................16x2 LCD
CIRCUIT DIAGRAM
37
THE SOFTWARE
38
The software is compiled using the demo version of BASCOM-8051, which can be
downloaded from website ‘www.mcselec.com’.
The BASCOM compiler provides special instructions for use and display of data
on the LCD module.
START
DEFINE VARIABLES
INITIALISE PORTS
CONFIGURE LCD
CONNECTIONS
CONFIGURE TIMER0
AS A COUNTER
ENABLE
INTERRUPTS
RESET VARIABLES
Fig. 4 : Flow chart of the frequency counting program
MICROCONTROLLER CODE
40
'Connect the timer0 input P3.4 to a frequency generator
' freq meter
' 24 mhz xtal ok upto 300khz
41
' initialize ports
P1 = 0
P3 = 255
On Timer0 Timer_0_overflow_int
' interrupt will be generated on every 65536 count
Priority Set Timer0
Enable Interrupts
Enable Timer0
42
Counter0 = 0
'clear counter
Start Counter0
'enable the counter to count
Do
'set up a 1 sec accurate DO NOTHING loop
Enable Interrupts
'wait 1 as per BASCOM-51 is not accurate
Disable Interrupts
C = Counter0
'get counter value
D = T0ic * 65536
Lowerline
C = C + D
T0ic = 0
Lcd " "
Lowerline
' show the frequency
43
Lcd "f=" ; C ; " Hz"
Waitms 255
Waitms 255
C = 0
Counter0 = 0
Start Counter0
're-start it because it was stopped by accessing the
COUNTER
Loop
RESULTS
44
45
CONCLUSION
46
BIBLIOGRAPHY
a) www.mcselec.com
b) www.wikipedia.com
c) www.esnips.com
47
48