FREQUENCY METER USING 8051A Project Report submitted in partial
fulfillment of the requirements for the award of the Degree of
Bachelor of Technology In Electrical And Electronic Engineering
Submitted By A.PRATHIMA SARVANI N.SRAVANI S.UJWALA Under the
guidance Mr.K.SATISH KUMAR, M.Tech Assistant Professor 07241A0210
07241A0218 07241A0222
Department of Electrical and Electronic Engineering Gokaraju
Rangaraju Institute of Engineering & Technology (Affiliated to
J.N.T.U Hyderabad) Bachupally, Kukatpally, Hyderabad-500072
1
ABSTRACT
The object of this project is to determine and display the
frequency of the input power. This is done by using 8051
microcontroller. The circuit of our designed frequency meter
includes 8051 microcontroller, Liquid Crystal Display(LCD),Cathode
Ray Oscilloscope(CRO) and variable power supply unit. The CRO is
used to display the frequency waveform of the given input power.
Based on the source code given to the 8051 microcontroller it
detects the frequency value and displays that value with the help
of the LCD employed. Depending on the power supply the value of the
frequency on the LCD changes. Most frequency counters work by using
a [counter] which accumulates the number of events occurring within
a specific period of time. After a preset period (1 second, for
example), the value in the counter is transferred to a display and
the counter is reset to zero. If the event being measured repeats
itself with sufficient stability and the frequency is considerably
lower than that of the clock oscillator being used, the resolution
of the measurement can be greatly improved by measuring the time
required for an entire number of cycles, rather than counting the
number of entire cycles observed for a pre-set duration. Frequency
counters are commonly used in laboratories, factories, and field
environments to provide direct frequency measurements of various
devices. The most common applications for frequency counters are
measurement and characterization of oscillator and transmitter
frequencies.
2
S.NO
INDEX
PG.NO
Chapter 1: INTRODUCTION Microcontroller1.1 Introduction to
AT89c51 Microcontroller 1.2 Features 1.2.1 Pin diagram 1.3 Memory
Organization 1.3.1 Program memory 1.3.2 Data memory 1.4 Power-on
RESET 1.5 Interrupts 1.5.1 External interrupts 1.6 Timer set up
1.6.1 timer/counter0 1.6.2 timer/counter1 1.7 Serial Port Set 1.8
Generating baud rates 1.9 Power supply 1.9.1 Dual supplies 1.9.2
Transformer 1.9.3 Rectifier 17 19 20 22 2 5 6 7 8 10 11 13 14 15 16
1
3
1.9.4 Regulator 1.10 Relay 1.11 RS-232
23 24 26
Chapter 2: liquid crystal display (LCD)2.1 Introduction 2.2 Pin
diagram 2.3 Pin description 2.4 Basic commands of LCD 29 29 31
32
Chapter 3: circuit description3.1 Frequency meter 3.2 Block
diagram 3.3 Source code 34 35 36
Chapter 4: Software4.1 Overview of KEIL C cross Compiler 4.2
Proteus 4.3Simulator / Debugger 41 42 42
Result and Conclusio Bibliography
43 44
4
Chapter 1MICROCONTROLLER1.1 MICRO CONTROLLER INTRODUCTIONThe
AT89C51 is a low-power, high-performance CMOS 8-bit microcomputer
with 4K bytes of Flash programmable and erasable read only memory
(PEROM). The device is manufactured using Atmels high-density
nonvolatile memory technology and is compatible with
industry-standard MCS-51 instruction set and pin out. The on-chip
Flash allows the program memory to be reprogrammed in-system or by
a conventional nonvolatile memory programmer. By combining a
versatile 8-bit CPU with Flash on a monolithic chip, the AT89C51 is
a powerful microcomputer which provides a highly-flexible and
cost-effective solution to many embedded control applications. 1.2
Features Compatible with MCS-51 Products 4K Bytes of In-System
Reprogrammable Flash Memory Endurance: 1000 Write/Erase Cycles.
Fully Static Operation: 0Hz to 24MHz Three-level Program Memory
Lock 128 x 8- bit Internal RAM 32 Programmable I/O Lines Two 16-bit
Timer/Counters Six Interrupt Sources Programmable Serial Channel
Low-power Idle and Power-down Modes
5
1.2.1 Pin diagram:
Pin diagram of 8051
6
TIMER1 ONCHIP
COUNTER INPUTS
TIMER0
ONCHIP
INTERRUPT CONTROL
CPU
OSC
BUS CONTROL
4I/OPORTS
SERIL PORT
POP2P1P3
TXD
RXD
Figure 1.1: Block Diagram of the AT89C core
7
For more information on the individual devices and features,
refer to the Hardware Descriptions and Data Sheets of the specific
device.
Figure 1.2: Oscillator Connection The AT89C51 provides the
following standard features: 4K bytes of Flash, 128 bytes of RAM,
32 I/O lines, two 16-bit timer/counters, five vector two-level
interrupt architecture, a full duplex serial port, on-chip
oscillator and clock circuitry. In addition, the P89C51 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.XTAL2
NC
EXTERIOR OSCILLATOR SIGNAL
XTAL1
GND
8
Figure 1.3: External Clock Drive Configuration
1.3 MEMORY ORGANIZATION1.1.1 Program Memory Figure 4 shows a map
of the lower part of the program memory. After reset, the CPU
begins execution from location 0000H. As shown in fig.4, each
interrupt is assigned a fixed location in program memory. The
interrupt causes the CPU to jump to that location, where it
executes the service routine. External Interrupt 0, for example, is
assigned to location 0003H. If External Interrupt 0 is used, its
service routine must begin at location 0003H. If the interrupt is
not used, its service location is available as general purpose.
(0033)H 002BH INTERRUPT LOCATIONS 0023H RESET 001BH 8bytes
Figure 1.4: Program Memory.
Program memory addresses are always 16 bits wide, even though
the actual amount o program memory used may be less than 64Kbytes.
External program execution sacrifices two of the 8-bit ports, P0
and P2, to the function of addressing the program memory.9
1.1.2 Data MemoryThe right half of Figure 3 shows the internal
and external data memory spaces available on Philips Flash
microcontrollers. Fig.6 shows a hardware configuration for
accessing up to 2K bytes of external RAM. In this case, the CPU
executes from internal flash. Port0 serves as a multiplexed
address/data bus to the RAM, and 3 lines of Port 2 are used to page
the RAM. The CPU generates RD and WR signals as needed during
external RAM accesses. You can assign up to 64K bytes of external
data memory. External data memory addresses can be either 1 or
2bytes wide. One-byte addresses are often used in conjunction with
one or more other I/O lines to page the RAM, as shown in Fig.6.
Two-byte addresses can also be used, in which case the high address
byte is emitted at Port2.
FFH Upper 128 80H 7FH Lower 128 00
ACCESSIBLE BY INDIRECT ADDRESSING ONLY ACCESSIBLE BY INDIRECT
ADDRESSING AND DIRECT ADDRESSING
ACCESSIBLE BY DIRECT ADDRESSING ONLY
FFH
Special register function
Ports Status and control bits Timers Registers Stack pointer
Accumulator (etc)
Figure 1.5: Internal Data Memory
Internal data memory addresses are always 1 byte wide, which
implies an address space of only 256bytes. However, the addressing
modes for internal RAM can in fact accommodate 384 bytes. Direct
addresses higher than 7FH access one memory space and indirect
addresses higher than 7FH access a different memory space. Thus,
Figure.7 shows the Upper 128 and SFR space occupying the same block
of addresses, 80H through FFH, although they are physically
separate entities. Figure.8 shows how the lower 128 bytes of RAM
are10
mapped. The lowest 32 bytes are grouped into 4 banks of 8
registers. Program instructions call out these registers as R0
through R7. Two bits in the Program Status Word (PSW) select which
register bank is in use..
Figure 1.6: The lower 128 bytes of Internal RAM The next 16
bytes above the register banks form a block of bit-addressable
memory space. The microcontroller instruction set includes a wide
selection of single-bit instructions, and these instructions can
directly address the 128 bits in this area. These bit addresses are
00H through 7FH. All of the bytes in the Lower 128 can be accessed
by either direct or indirect addressing.
11
Special Function Register Map 8 Bytes F8 F0 E8 E0 D8 D0 C8 C0 B8
B0 A8 A0 98 90 88 80 FF F7 EF E7 DF D7 CF C7 BF B7 AF A7 9F 97 BF
87
B ACC PSW(1) T2C0N(1)( T2MOD(2) RCAP2L(2) IP(1) P3 IE(1) P2
SCON(1) PI TCON(1) PO RCAP2H(2) TL2(2) TH2(2)
SBUF TMOD(1) SP TLO DPL TLI DPH Bit Addressable THO TH1
PCON(1)
Notes: 1. SFRs converting mode or control bits 2.
AT89C52only
1.4 Power-on ResetThe reset input is the RST pin, which is the
input to a Schmitt Trigger. A reset is accomplished by holding the
RST pin high for at least two machine cycles (24 oscillator
periods), while the oscillator is running. The CPU responds by
generating an internal reset. The external reset signal is
asynchronous to the internal clock. The RST pin is sampled during
State 5 Phase 2 of every machine cycle. The port pins will maintain
their current activities for 19 oscillator periods after a logic 1
has been sampled at the RST pin; that is, for 19 to 31 oscillator
periods after the external reset signal has been applied to the RST
pin.
12
The internal reset algorithm writes 0s to all the SFRs except
the port latches, the Stack Pointer and SBUF. The port latches are
initialized to FFH, the Stack Pointer to 07H, and SBUF is
indeterminate. The internal RAM is not affected by reset. On power
up the RAM content is indeterminate. REGISTER REST VALUE
------------------------------------------------------------------------PC
ACC B PSW SP DPTR P0-P3 IP IE TMOD TCON TH0 TL0 TH1 0000H 00H 00H
00H 07H 0000H FFH XXX0000B 0XX0000B 00H 00H 00H 00H 00H13
SCON SBUF PCON (NMOS) PCON (CMOS)
00H Indeterminate 0XXXXXXXB 0XXX0000B
1.5 InterruptsThe AT89C51 provides 5 interrupt sources. The
External Interrupts INT0 and INT1 can each be either
level-activated or transition-activated, depending on bits IT0 and
IT1 in Register TCON. The flags that actually generate these
interrupts are bits IE0 and IE1 in TCON. When an external interrupt
is generated, the flag that generated it is cleared by the hardware
when the service routine is vectored to only if the interrupt was
transition-activated. If the interrupt was level-activated, then
the external requesting source is what controls the request flag,
rather than the on-chip hardware. The Timer0 and Timer 1 Interrupts
are generated by TF0 and TF1, which are set by a rollover in their
respective Timer/Counter registers (except see Timer0 in Mode3).
When a timer interrupt is generated, the flag that generated it is
cleared by the on-chip hardware when the service routine is
vectored to. The Serial Port Interrupt is generated by the logical
OR of RI and TI. Neither of these flags is cleared by hardware when
the service routine is vectored to. In fact, the service routine
will normally have to determine whether it was RI or TI that
generated the interrupt, and the bit will have to be cleared in
software. All of the bits that generate interrupts can be set or
cleared by software, with the same result as thought it had been
set or cleared by hardware. This is, interrupts can be generated or
pending interrupts can be canceled in software. The interrupt flags
are sampled a S5P2 of every machine cycle. The samples are polled
during the following machine cycle. If one of the flags was in a
set condition at S5P2 of the14
preceding cycle, the polling cycle will find it and the
interrupt system will generate an LCALL to the appropriate service
routine, provided this hardware-generated LCALL is not blocked by
any of the following conditions: 1. 2. 3. An interrupt of equal or
higher priority level is already in progress. The current (polling)
cycle is not the final cycle in the execution of the instruction in
progress. The instruction in progress is RET1 or any write to the
IE or IP registers. Note that a simple RET instruction would also
have returned execution to the interrupted program, but it would
have left the interrupt control system thinking an interrupt was
still in progress, making future interrupts impossible. 1.5.1
External Interrupts The external sources can be programmed to be
level-activated or transitionactivated by setting or clearing bit
IT1 or IT0 in Register TCON. If ITx=0, external interrupt x is
triggered by a detected low at the INTX pin. If ITx=1, external pin
x is edge triggered. In this mode if successive samples of the INTX
pin show a high in one cycle and a low in the next cycle, interrupt
request flag IEx in TCON is set. Flag bit IEx then request the
interrupt. Since the external interrupt pins are sampled once each
machine cycle, an input high or low should hold for at least 12
oscillator periods to ensure sampling. If the external interrupt is
transition-activated, the external source has to hold the request
pin high for at least once cycle, and then hold it low for at least
one cycle. This is done to ensure that transition is seen so that
interrupt request flag IEx will be set. The CPU will automatically
clear IEx when the service routine is called. To use any of the
interrupts in the 89C51 Family, the following three steps must be
taken. Set the EA (enable all) bit in the IE register to 1. 1. Set
the corresponding individual interrupt enable bit in the IE
register to 1. 2. Begin the interrupt service routine at the
corresponding vector.15
Address of that interrupt. See Table below. Interrupt Source
Vector Address
---------------------------------------------------------------IE0
TF0 IE1 TF1 RI & TI 0003H 000BH 0013H 001BH 0023H
In addition, for external interrupts, pins INT0 and INT1(P3.2
and P3.3) must be set to 1, and depending on whether the interrupt
is to be level or transition activated, bits IT0 or IT1 in the TCON
register may need to be set to 1. ITx=0 ITx=1 below: IE0 TF0 IE1
TF1R1 or T1 lowest priority highest priority level activated
transition activated Priority within level is only to resolve
simultaneous requests of the same priority level. Form high to
low, interrupt sources are listed
16
1.6 Timer Set-Up The tables below give some values for TMOD
which can be used to set up Timer 0 and Timer 1 in different modes.
It is assumed that only one timer is being used at a time. If it is
desired to run Timers 0 and 1 simultaneously, in any mode the value
in the TMOD for timer 0 must be ORed with value shown for Timer 1.
For example, if it is desired to run Timer 0 in mode 1 GATE
(external control), and Timer 1 in mode 2 COUNTER, then value that
must be loaded into TMOD is 69H (09H from the table for Timer0,
ORed with 60H from the table for Timer 1). Moreover, it is assumed
that the user, at this point, is not ready to turn the timers on
and will do that at a different point in the program by setting bit
TRx (in TCON) to 1. 1.6.1 TIMER/COUNTER 0 As a Timer: Mode Function
TMOD (internal control) TMOD (external control)
0 1 2 3
13-bit Timer 16-bit Timer 8-bit Auto-Reload Two 8-bit Timers
00H 01H 02H 03H
08H 09H 0AH 0BH
17
As a Counter: Mode Function TMOD (internal control) TMOD
(external control)
0 1 2 3
13-bit Counter 16-bit Counter 8-bit Auto-Reload One 8-bit
Counter
04H 05H 06H 07H
0CH 0DH 0EH 0FH
1.6.2TIMER/COUNTER 1 As a Timer: Mode Function TMOD (internal
control) TMOD (external control)
0 1 2 3
13-bit Timer 16-bit Timer 8-bit Auto-Reload Does not run
00H 10H 20H 30H
80H 90H A0H B0H
18
As a Counter Mode Function TMOD (internal control) TMOD
(external control)
0 1 2 3
13-bit Counter 16-bit Counter 8-bit Auto-Reload Not
available
40H 50H 60H ---
C0H D0H A0H ---
1.7 Serial Port Set-Up The serial port is full duplex, meaning
it can transmit and receive simultaneously. It is also
receive-buffered, meaning it can commence reception of a second
byte before a previously received byte has been read form the
register. (However, if the first byte still hasnt been read by the
time reception of the second byte is complete, one of the bytes
will be lost.) The serial port receive and transmit registers are
both accessed at Special Function Register SBUF. Writing to SBUF
loads the transmit register, and reading SBUF accesses a physically
separate receive register. The serial port can operate in 4 modes:
Mode 0: Serial data enters and exits through RxD. TxD outputs the
shift clock. 8 bits are transmitted/received (LSB first). The baud
rate is fixed at 1/12th oscillator frequency. Mode 1: 10 bits are
transmitted (through TxD) or received (through RxD): a start bit
(0), 8 data bits (LSB first), and a stop bit (1). On receive; the
stop bit goes into RB8 in Special Function Register SCON. The baud
rate is variable. Mode 2: 11 bits are transmitted (trough TxD) or
received (through RxD): start bit (0), 8 data bits (LSB first), a
programmable 9th data bit, and a stop bit (1). On transmit, the 9th
data bit (TB is19
SCON) can be assigned the value of 0 or 1. Or, for example, the
parity bit (P, in the PSW) could be moved into TB8. On receive; the
9th data bit goes into RB8 in Special Function Register SCON, while
the stop bit is ignored. The baud rate is programmable to either
1/32 or 1/64th oscillator frequency. Mode 3: 11 bits are
transmitted (through TxD) or received (through RxD): a start bit
(0), 8 data bits (LSB first), a programmable 9th data bit, and a
stop bit (1). In fact, Mode 3 is the same as Mode2 in all aspects
except baud rate. The baud rate in Mode 3 is variable. Timer 1
Generated Commonly Used Baud Rages The values for the different
modes of operation of the serial port are shown in the table below:
MODE SCON SM2 Variation
0 1 2 3
10H 50H 90H D0H
Single Processor Environment (SM2 = 0)
0 1 2 3
Not Available Multiprocessor 70H B0H F0H Environment (SM2 =1)
------------20
1.8 GENERATING BAUD RATES Serial Port in Mode 0: Mode 0 has a
fixed baud rate, which is 1/12th oscillator frequency. To run the
serial port in this mode none of the Timer/Counters need to be set
up. Only the SCON register needs to be defined. Baud Rate =
Oscillator Frequency /12 Serial Port in Mode 1: Mode1 has a
variable baud rate. The baud rate is generated by Timer 1. For this
purpose, Timer 1 is used in mode2 (Auto-Reload). Baud Rate = (K x
Osc.Freq) / (32 x 12 x [256 (TH1)]) If SMOD =0, then K=1. If SMOD
=1, then K =2 (SMOD is in the PCON register). Most of the time the
user knows the baud rate and needs to know the reload value for
TH1. TH1 = 256 (K x Osc.Freq) / (384 x baud rate) TH1 must be an
integer value. Rounding off TH1 to the nearest integer may not
produce the desired baud rate. In this case, the user may have to
choose another crystal frequency. Since the PCON register is not
bit addressable, one way to set the bit is logical ORing the PCON
register (i.e. ORL PCON, #80H). The address of PCON is 87H. Serial
Port in Mode2: The baud rate is fixed in this mode and is 1/32 or
1/64 of the oscillator frequency, depending on the value of the
SMOD bit in the PCON register.
21
In this mode none of the Timers are used and the clock comes
form the internal phase 2 clock. SMOD = 1, Baud Rate = 1/32
Osc.Freq. SMOD =0, Baud Rate = 1/64 Osc.Freq.
Circuit of 89C5RD2
1.9 Power supplyA power supply (sometimes called a power supply
unit or PSU) is a device or system that supplies electrical or
other types of energy to an output load or group of loads. The term
is most commonly applied to electrical energy supplies, less often
to mechanical ones, and rarely to others.
Types of Power Supply There are many types of power supply. Most
are designed to convert high voltage AC mains electricity to a
suitable low voltage supply for electronics circuits and other
devices. A power supply can by broken down into a series of blocks,
each of which performs a particular function. For example a 5V
regulated supply:22
```````````````` Each of the blocks is described in more detail
below:
Transformer - steps down high voltage AC mains to low voltage
AC. Rectifier - converts AC to DC, but the DC output is varying.
Smoothing - smoothes the DC from varying greatly to a small ripple.
Regulator - eliminates ripple by setting DC output to a fixed
voltage.
Power supplies made from these blocks are described below with a
circuit diagram and a graph of their output:
Transformer only Transformer + Rectifier Transformer + Rectifier
+ Smoothing Transformer + Rectifier + Smoothing + Regulator
1.9.1 Dual SuppliesSome electronic circuits require a power
supply with positive and negative outputs as well as zero volts
(0V). This is called a 'dual supply' because it is like two
ordinary supplies connected together as shown in the diagram. Dual
supplies have three outputs, for example a 9V supply has +9V, 0V
and -9V outputs.
23
Transformer only
The low voltage AC output is suitable for lamps, heaters and
special AC motors. It is not suitable for electronic circuits
unless they include a rectifier and a smoothing capacitor.
Transformer + Rectifier
The varying DC output is suitable for lamps, heaters and
standard motors. It is not suitable for electronic circuits unless
they include a smoothing capacitor.
24
Transformer + Rectifier + Smoothing
The smooth DC output has a small ripple. It is suitable for most
electronic circuits.
Transformer + Rectifier + Smoothing + Regulator
The regulated DC output is very smooth with no ripple. It is
suitable for all electronic circuits.
1.9.2 Transformer
Transformer circuit symbol
25
Vs = secondary (output) voltage Ns = number of turns on
secondary coil Is = secondary (output) current
Vp = primary (input) voltage Np = number of turns on primary
coil Ip = primary (input) current
Transformers convert AC electricity from one voltage to another
with little loss of power. Transformers work only with AC and this
is one of the reasons why mains electricity is AC. Step-up
transformers increase voltage, step-down transformers reduce
voltage. Most power supplies use a step-down transformer to reduce
the dangerously high mains voltage (230V in UK) to a safer low
voltage. The input coil is called the primary and the output coil
is called the secondary. There is no electrical connection between
the two coils, instead they are linked by an alternating magnetic
field created in the soft-iron core of the transformer. The two
lines in the middle of the circuit symbol represent the core.
Transformers waste very little power so the power out is (almost)
equal to the power in. Note that as voltage is stepped down current
is stepped up. Vp turns ratio = Vs = Ns Npand
Figure 1.8:Transformer
power out = power in Vs Is = Vp Ip
1.9.3 Rectifier There are several ways of connecting diodes to
make a rectifier to convert AC to DC. The bridge rectifier is the
most important and it produces full-wave varying DC. A full-wave
rectifier26
can also be made from just two diodes if a centre-tap
transformer is used, but this method is rarely used now that diodes
are cheaper. A single diode can be used as a rectifier but it only
uses the positive (+) parts of the AC wave to produce half-wave
varying DC. Bridge rectifier A bridge rectifier can be made using
four individual diodes, but it is also available in special
packages containing the four diodes required. It is called a
full-wave rectifier because it uses the entire AC wave (both
positive and negative sections). 1.4V is used up in the bridge
rectifier because each diode uses 0.7V when conducting and there
are always two diodes conducting, as shown in the diagram below.
Bridge rectifiers are rated by the maximum current they can pass
and the maximum reverse voltage they can withstand (this must be at
least three times the supply RMS voltage so the rectifier can
withstand the peak voltages). Please see the Diodes page for more
details, including pictures of bridge rectifiers.
Bridge rectifierAlternate pairs of diodes conduct, changing over
the connections so the alternating directions of AC are converted
to the one direction of DC.
Output: full-wave varying DC(using all the AC wave)
27
1.9.4 RegulatorVoltage regulator ICs are available with fixed
(typically 5, 12 and 15V) or variable output voltages. They are
also rated by the maximum current they can pass. Negative voltage
regulators are available, mainly for use in dual supplies. Most
regulators include some automatic protection from excessive current
('overload protection') and overheating ('thermal protection').
Many of the fixed voltage regulators ICs have 3 leads and look like
power transistors, such as the 7805 +5V 1A regulator shown on the
right. They include a hole for attaching a heatsink if necessary.
Choosing a zener diode and resistor: 1. The zener voltage Vz is the
output voltage required 2. The input voltage Vs must be a few volts
greater than Vz(this is to allow for small fluctuations in Vs due
to ripple)
3. The maximum current Imax is the output current required plus
10% 4. The zener power Pz is determined by the maximum current: Pz
> Vz Imax 5. The resistor resistance: R = (Vs - Vz) / Imax 6.
The resistor power rating: P > (Vs - Vz) Imax
1.10 Relay:A relay is an electrical switch that opens and closes
under the control of another electrical circuit. In the original
form, the switch is operated by an electromagnet to open or close
one or many sets of contacts. It was invented by Joseph Henry in
1835. Because a relay is able to control an output circuit of
higher power than the input circuit, it can be considered to be, in
a broad sense, a form of an electrical amplifier.
28
In this this project we can use electromagnetic relay. THE
ELECTROMAGNETIC RELAY
Figure 1.9: ELECTROMAGNETIC RELAY The electromagnetic relay
consists of a multi-turn coil, wound on an iron core, to form an
electromagnet. When the coil is energized, by passing current
through it, the core becomes temporarily magnetized. The magnetized
core attracts the iron armature. The armature is pivoted which
causes it to operate one or more sets of contacts. When the coil is
de-energized the armature and contacts are released. The coil can
be energized from a low power source such as a transistor while the
contacts can switch high powers such as the mains supply. The relay
can also be situated remotely from the control source. Relays can
generate a very high voltage across the coil when switched off.
This can damage other components in the circuit. To prevent this, a
diode is connected across the coil.29
The cathode of the diode is connected to the most positive end
of the coil.
The spring sets (contacts) can be a mixture of n.o n.c and c.o.
Look at the page on switches to see how they can be used in
circuits. Various coil operating voltages (ac and dc) are
available. The actual contact points on the spring sets are
available for high current and low current operation. The REED
RELAY has a much faster operation than the relays described above.
1.11: RS-232RS232 DB9 pinout
In telecommunications, RS-232 (Recommended Standard 232) is a
standard for serial binary single-ended data and control signals
connecting between a DTE (Data Terminal30
Equipment) and a DCE (Data Circuit-terminating Equipment). It is
commonly used in computer serial ports. The standard defines the
electrical characteristics and timing of signals, the meaning of
signals, and the physical size and pinout of connectors. The RS232
standard describes a communication method where information is sent
bit by bit on a physical channel. The information must be broken up
in data words. The length of a data word is variable. On PC's a
length between 5 and 8 bits can be selected. This length is the
netto information length of each word. For proper transfer
additional bits are added for synchronisation and error checking
purposes. It is important, that the transmitter and receiver use
the same number of bits. Otherwise, the data word may be
misinterpreted, or not recognized at all. With synchronous
communication, a clock or trigger signal must be present which
indicates the beginning of each transfer. The absence of a clock
signal makes an asynchronous communication channel cheaper to
operate. Less lines are necessary in the cable. A disadvantage is,
that the receiver can start at the wrong moment receiving the
information. Resynchronization is then needed which costs time. All
data received in the resynchronization period is lost. Another
disadvantage is that extra bits are needed in the data stream to
indicate the start and end of useful information. These extra bits
take up bandwidth. Data bits are sent with a predefined frequency,
the baud rate. Both the transmitter and receiver must be programmed
to use the same bit frequency. After the first bit is received, the
receiver calculates at which moments the other data bits will be
received. It will check the line voltage levels at those moments.
With RS232, the line voltage level can have two states. The on
state is also known as mark, the off state as space. No other line
states are possible. When the line is idle, it is kept in the mark
state.
31
Chapter-2 LIQUID CRYSTAL DISPLAY2.1 INTRODUCTIONLCD is a type of
display used in digital watches and many portable computers. LCD
displays utilize to sheets of polarizing material with a liquid
crystal solution between them. An electric current passed through
the liquid causes the crystals to align so that light cannot pass
through them. LCD technology has advanced very rapidly since its
initial inception over a decade ago for use in laptop computers.
Technical achievement has resulted in brighter displace, higher
resolutions, reduce response times and cheaper manufacturing
process.The liquid crystals can be manipulated through an applied
electric voltage so that light is allowed to pass or is blocked. By
carefully controlling where and what wavelength (color) of light is
allowed to pass, the LCD monitor is able to display images. A back
light provides LCD monitors brightness. Just as there are many
varieties of solids and liquids, there is also a variety of liquid
crystal substances. Depending on the temperature and particular
nature of a substance, liquid crystals can be in one of several
distinct phases.
Over the years many improvements have been made to LCD to help
enhance resolution, image, sharpness and response times. One of the
latest such advancements is TFT or Thin Film Transistor. TFT-LCDs
make use of a very thin transistor that is applied to glass during
acts as switch allowing control of light at the pixel level,
greatly enhancing image sharpness and resolution. This has been
particularly important for improving LCDs ability to display
small-sized fonts and image clearly. LCD interfacing with 8051 is a
real-world application. In recent years the LCD is finding
widespread use replacing LEDs (seven segment LEDs or other multi
segment LEDs). This is due to following reasons: 1. The declining
prices of LCDs. 2. Incorporation of a refreshing controller into
the LCD, thereby relieving the CPU to keep displaying the data. 3.
Ease of programming for characters and graphics.
32
2.2 PIN DIAGRAMMost of the LCD modules conform to a standard
interface specification. A 14pin access is provided having eight
data lines, three control lines and three power lines. The
connections are laid out in one of the two common configurations,
either two rows of seven pins, or a single row of 14 pins. One of
the, pins are numbered on the LCDs print circuit board (PCB), but
if not, it is quite easy to locate pin1. Since this pin is
connected to ground, it often has a thicker PCB track, connected to
it, and it is generally connected to metalwork at same point. G +5V
-5V
123
D0 D1
D2 D3 D4 D5
D6
D7
RS
R/W EN
Figure 2.1:PIN DIAGRAM OF LCD DISPLAY
2.3 PIN DESCRIPTIONSVcc, Vss and Vee While Vcc and Vss provide
+5V and ground respectively, Vee is used for controlling LCD
contrast.33
RS, register select There are two very important registers
inside the LCD. The RS pin is used for their selection as follows.
a) If RS=0, the instruction command code register is selected,
allowing the user to send a command such as clear display, cursor
at home, etc., b) If RS=1 the data register is selected, allowing
the user to send data to be displayed on the LCD. R/W, read/write
R/W input allows the user to write information to the LCD or read
information from it. R/W=1 when reading; R/W=0 when writing. EN,
Enable The enable pin is used by the LCD to latch information
presented to its data pins. When data is supplied to data pins, a
high-to-low pulse must be applied to this pin in order for the LCD
to latch in the data present at the data pins. This pulse must be a
minimum of 450ns wide. D0-D7 The 8-bit data pins, D0-D7, are used
to send information to the LCD or read the contents of the LCDs
internal registers. To display letters and numbers, we send ASCII
codes for the letters A-Z, a-z, and numbers 0-9 to these pins while
making RS=1. We also use RS=0 to check the busy flag bit to see if
the LCD is ready to receive information. The busy flag is D7 and
can be read when R/W=1 and RS=0, as follows: if R/W=1, RS=0. When
D7=1 (busy flag=1), the LCD is busy taking care of internal
operations and will not accept any information.
34
The pin descriptions are given in table below: PIN 1 2 3 SYMBOL
Vss Vcc Vee I/O ---DESCRIPTION Ground +5V power supply Power supply
to control contrast 4 RS I RS=0 to select command register RS=1 to
select data register 5 R/W I R/W=0 for write R/W=1 for read 6 7 8 9
10 11 12 13 14 EN DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7 I/O I/O I/O I/O
I/O I/O I/O I/O I/O Enable The 8-bit data bus The 8-bit data bus
The 8-bit data bus The 8-bit data bus The 8-bit data bus The 8-bit
data bus The 8-bit data bus The 8-bit data bus
TABLE 8 : PIN DESCRIPTIONS OF LCD
35
TABLE 9: INSTRUCTION SET OF LCD 2.4 BASIC COMMANDS OF LCD:Set
Cursor Move Direction: 04h Shift cursor to the left 06h Shift
cursor to the right 80h force cursor to the beginning of the first
line C0h force cursor to the beginning of second line 02h return
home
36
Enable Display/Cursor: 0Ch - Turn Display On, cursor off 0ah -
Turn Cursor On, Display off 08h - Cursor off, Display off 0eh/0fh-
display on, cursor blinking Shift Display: 18h 1Ch - Display Shift
to left, right respectively Set Interface Length: 38h Initialize
LCD as 2 lines, 5*7 matrix Reading Data back is used in this
application, which requires data to be moved back and forth on the
LCD. The "Busy Flag" is polled to determine whether the last
instruction that has been sent has completed processing. Before we
send commands or data to the LCD module, the Module must be
initialized. For eight bit mode, this is done using the following
series of operations: Wait more than 15 msecs after power is
applied. Write 0x030 to LCD and wait 5 msecs for the instruction to
complete Write 0x030 to LCD and wait 160 usecs for instruction to
complete Write 0x030 AGAIN to LCD and wait 160 usecs or Poll the
Busy Flag Set the Operating Characteristics of the LCD Write "Set
Interface Length" Write 0x010 to turn off the Display Write 0x001
to Clear the Display Write "Set Cursor Move Direction" Setting
Cursor Behaviour Bits Write "Enable Display/Cursor" & enable
Display and Optional Cursor.
37
CHAPTER 3 FREQUENCY METER3.1INTRODUCTIONFrequency meter, device
for measuring the repetitions per unit of time (customarily, a
second) of a complete electromagnetic waveform. Various types of
frequency meters are used. Many are instruments of the deflection
type, ordinarily used for measuring low frequencies but capable of
being used for frequencies as high as 900 Hz. These operate by
balancing two opposing forces. Changes in the frequency to be
measured cause a change in this balance that can be measured by the
deflection of a pointer on a scale. Deflection-type meters are of
two types, electrically resonant circuits and ratio meters. An
example of a simple electrically resonant circuit is a moving-coil
meter. In one version, this device possesses two coils tuned to
different frequencies and connected at right angles to one another
in such a way that the whole element, with attached pointer, can
move. Frequencies in the middle of the meters range cause the
currents in the two coils to be approximately equal and the pointer
to indicate the midpoint of a scale. Changes in frequency cause an
imbalance in the currents in the two coils, causing them and, in
turn, the pointer to move. Another type of frequency meter, not of
the deflection type, is the resonant-reed type, ordinarily used in
ranges from 10 to 1,000 Hz, although special designs can operate at
lower or higher frequencies. These work by means of specially tuned
steel reeds that vibrate under the effect of electric current; only
those reeds that are in resonance vibrate visibly, however.
38
3.2 BLOCK DIAGRAM
Power Supply
PULSES OFCRO Micro Controller LCD
FREQUENCYMETER
The block diagram consists of Micro controller, LCD display,
CRO, Power supply. In the hardware the micro controller is
connected with help of the serial port. With the help of the
microcontroller the number of pulses will be counted and displayed
on the LCD display. The baud rate is set per the micro
controller.
39
3.3 SOURCE CODE#include sbit intr=P3^4; sfr ldata=0x90; sbit
rs=P2^0; sbit rw=P2^1; sbit en=P2^2; void lcdcmd(char ); void
delay(int); void lcddata(int); void lcddata1(char *value); void
main() { int i,l,H,k; //char n; while(1) { TMOD=0x15; intr=1;
TL0=0x00; TH0=0x00; TR0=1; for(i=0;i