Professional Documents
Culture Documents
systems.
MICROCONTROLLERS:
8051 is an 8-bit processor, meaning that the CPU can work on only 8 bits of
data at a time. Data larger than 8 bits has to be broken into 8-bit pieces to be
processed by the CPU. 8051 is available in different memory types such as UV-
EPROM, Flash and NV-RAM.
The features, pin description of the microcontroller and the software tools
used are discussed in the following sections.
FEATURES OF AT89C51:
Description:
Vcc
Pin 40 provides supply voltage to the chip. The voltage source is +5V.
GND
XTAL1 and XTAL2 are the input and output, respectively, of an inverting
amplifier that can be configured for use as an on-chip oscillator, as shown in
Figure 11. 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 the below figure. 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.
Fig: Oscillator Connections
RESET
Pin9 is the reset pin. It is an input and is active high. Upon applying a high pulse
to this pin, the microcontroller will reset and terminate all the activities. This is
often referred to as a power-on reset.
EA (External access)
Pin 31 is EA. It is an active low signal. It is an input pin and must be connected to
either Vcc or GND but it cannot be left unconnected.
The 8051 family members all come with on-chip ROM to store programs.
In such cases, the EA pin is connected to Vcc. If the code is stored on an external
ROM, the EA pin must be connected to GND to indicate that the code is stored
externally.
PSEN (Program store enable)
Ports 0, 1, 2 and 3
The four ports P0, P1, P2 and P3 each use 8 pins, making them 8-bit ports. All
the ports upon RESET are configured as input, since P0-P3 have value FFH on
them.
Port 0(P0)
Port 0 is also designated as AD0-AD7, allowing it to be used for both address and
data. ALE indicates if P0 has address or data. When ALE=0, it provides data D0-
D7, but when ALE=1, it has address A0-A7. Therefore, ALE is used for
demultiplexing address and data with the help of an internal latch.
With no external memory connection, both P1 and P2 are used as simple I/O.
With external memory connections, port 2 must be used along with P0 to provide
the 16-bit address for the external memory. Port 2 is designated as A8-A15
indicating its dual function. While P0 provides the lower 8 bits via A0-A7, it is the
job of P2 to provide bits A8-A15 of the address.
Port 3
Port 3 occupies a total of 8 pins, pins 10 through 17. It can be used as input or
output. P3 does not need any pull-up resistors, the same as port 1 and port 2. Port
3 has an additional function of providing some extremely important signals such
as interrupts.
The CPU takes a certain number of clock cycles to execute an instruction. In the
8051 family, these clock cycles are referred to as machine cycles. The length of
the machine cycle depends on the frequency of the crystal oscillator. The crystal
oscillator, along with on-chip circuitry, provides the clock source for the 8051
CPU.
The frequency can vary from 4 MHz to 30 MHz, depending upon the chip rating
and manufacturer. But the exact frequency of 11.0592 MHz crystal oscillator is
used to make the 8051 based system compatible with the serial port of the IBM
PC.
In the original version of 8051, one machine cycle lasts 12 oscillator periods.
Therefore, to calculate the machine cycle for the 8051, the calculation is made as
1/12 of the crystal frequency and its inverse is taken.
The assembly language program is written and this program has to be dumped
into the microcontroller for the hardware kit to function according to the software.
The program dumped in the microcontroller is stored in the Flash memory in the
microcontroller. Before that, this Flash memory has to be programmed and is
discussed in the next section.
ALE/PROG
Address Latch Enable is an output pulse for latching the low byte of the
address during accesses to external memory. This pin is also the program pulse
input (PROG) during Flash programming. In normal operation, ALE is emitted at
a constant rate of 1/6 the oscillator frequency and may be used for external timing
or clocking purposes. If desired, ALE operation can be disabled by setting bit 0 of
SFR location 8EH. With the bit set, ALE is active only during a MOVX or
MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-
disable bit has no effect if the microcontroller is in external execution mode.
PSEN (Program Store Enable)
It is the read strobe to external program memory. When the AT89S8252 is
executing code from external program memory, PSEN is acti-vated twice each
machine cycle, except that two PSEN activations are skipped during each access
to external data memory.
Ports 0, 1, 2 and 3
The four ports P0, P1, P2 and P3 each use 8 pins, making them 8-bit ports. All
the ports upon RESET are configured as input, since P0-P3 have value FFH on
them.
Port 0(P0)
Port 0 is also designated as AD0-AD7, allowing it to be used for both address and
data. ALE indicates if P0 has address or data. When ALE=0, it provides data D0-
D7, but when ALE=1, it has address A0-A7. Therefore, ALE is used for
demultiplexing address and data with the help of an internal latch.
When there is no external memory connection, the pins of P0 must be
connected to a 10K-ohm pull-up resistor. This is due to the fact that P0 is an open
drain. With external pull-up resistors connected to P0, it can be used as a simple
I/O, just like P1 and P2. But the ports P1, P2 and P3 do not need any pull-up
resistors since they already have pull-up resistors internally. Upon reset, ports P1,
P2 and P3 are configured as input ports.
Port 1
Port 1 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 1
output buffers can sink/source four TTL inputs. When 1s are written to Port 1
pins, they are pulled high by the internal pull-ups and can be used as inputs. As
inputs, Port 1 pins that are externally being pulled low will source current because
of the internal pull-ups.
Some Port 1 pins provide additional functions. P1.0 and P1.1 can be
configured to be the timer/counter 2 external count input (P1.0/T2) and the
timer/counter 2 trigger input (P1.1/T2EX), respectively. Furthermore, P1.4, P1.5,
P1.6, and P1.7 can be configured as the SPI slave port select, data input/output
and shift clock input/output pins. Port 1 also receives the low-order address bytes
during Flash programming and verification.
Table: Port1 Alternate functions
Port 2
With no external memory connection, P2 are used as simple I/O. With
external memory connections, port 2 must be used along with P0 to provide the 16-
bit address for the external memory. Port 2 is designated as A8-A15 indicating its
dual function. While P0 provides the lower 8 bits via A0-A7, it is the job of P2 to
provide bits A8-A15 of the address.
Port 2 also receives the high-order address bits and some control signals
during Flash programming and verification.
Port 3
Port 3 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 3
output buffers can sink/source four TTL inputs. When 1s are written to Port 3
pins, they are pulled high by the internal pull-ups and can be used as inputs. As
inputs, Port 3 pins that are externally being pulled low will source current because
of the pull-ups. Port 3 receives some control signals for Flash programming and
verification.
Port 3 also serves the functions of various special features of the
AT89S8252, as shown in the following table.
Instructions that use direct addressing access SFR space. For example, the
following direct addressing instruction accesses the SFR at location 0A0H (which
is P2).
Instructions that use indirect addressing access the upper 128 bytes of
RAM. For example, the following indirect addressing instruction, where R0
contains 0A0H, accesses the data byte at address 0A0H, rather than P2 (whose
address is 0A0H).
The on-chip EEPROM data memory is selected by setting the EEMEN bit
in the WMCON register at SFR address location 96H. The EEPROM address
range is from 000H to 7FFH. The MOVX instructions are used to access the
EEPROM. To access off-chip data memory with the MOVX instructions, the
EEMEN bit needs to be set to “0”.
Machine cycle for the 8051
The CPU takes a certain number of clock cycles to execute an instruction. In the
8051 family, these clock cycles are referred to as machine cycles. The length of
the machine cycle depends on the frequency of the crystal oscillator. The crystal
oscillator, along with on-chip circuitry, provides the clock source for the 8051
CPU.
The frequency can vary from 4 MHz to 30 MHz, depending upon the chip rating
and manufacturer. But the exact frequency of 11.0592 MHz crystal oscillator is
used to make the 8051 based system compatible with the serial port of the IBM
PC.
In the original version of 8051, one machine cycle lasts 12 oscillator periods.
Therefore, to calculate the machine cycle for the 8051, the calculation is made as
1/12 of the crystal frequency and its inverse is taken.
POWER SUPPLY:
The input to the circuit is applied from the regulated power supply. The a.c.
input i.e., 230V from the mains supply is step down by the transformer to 12V and
is fed to a rectifier. The output obtained from the rectifier is a pulsating d.c
voltage. So in order to get a pure d.c voltage, the output voltage from the rectifier
is fed to a filter to remove any a.c components present even after rectification.
Now, this voltage is given to a voltage regulator to obtain a pure constant dc
voltage.
230V AC
50Hz D.C
Output
Rectifier:
The output from the transformer is fed to the rectifier. It converts A.C. into
pulsating D.C. The rectifier may be a half wave or a full wave rectifier. In this
project, a bridge rectifier is used because of its merits like good stability and full
wave rectification.
For the positive half cycle of the input ac voltage, diodes D1 and D3 conduct,
whereas diodes D2 and D4 remain in the OFF state. The conducting diodes will be
in series with the load resistance RL and hence the load current flows through RL.
For the negative half cycle of the input ac voltage, diodes D2 and D4 conduct
whereas, D1 and D3 remain OFF. The conducting diodes D2 and D4 will be in
series with the load resistance RL and hence the current flows through RL in the
same direction as in the previous half cycle. Thus a bi-directional wave is
converted into a unidirectional wave.
Filter:
Capacitive filter is used in this project. It removes the ripples from the
output of rectifier and smoothens the D.C. Output received from this filter is
constant until the mains voltage and load is maintained constant. However, if
either of the two is varied, D.C. voltage received at this point changes. Therefore a
regulator is applied at the output stage.
Voltage regulator:
As the name itself implies, it regulates the input applied to it. A voltage
regulator is an electrical regulator designed to automatically maintain a constant
voltage level. In this project, power supply of 5V and 12V are required. In order to
obtain these voltage levels, 7805 and 7812 voltage regulators are to be used. The
first number 78 represents positive supply and the numbers 05, 12 represent the
required output voltage levels. The L78xx series of three-terminal positive
regulators is available in TO-220, TO-220FP, TO-3, D2PAK and DPAK packages
and several fixed output voltages, making it useful in a wide range of applications.
These regulators can provide local on-card regulation, eliminating the distribution
problems associated with single point regulation.
Each type employs internal current limiting, thermal shut-down and safe
area protection, making it essentially indestructible. If adequate heat sinking is
provided, they can deliver over 1 A output current. Although designed primarily
as fixed voltage regulators, these devices can be used with external components to
obtain adjustable voltage and currents.
Function
LED’s emit light when an electric current passes through them.
Connecting and soldering
LED’s must be connected the correct way round, the diagram may be
labeled a or + for anode and k or - for cathode (yes, it really is k, not c, for
cathode!). The cathode is the short lead and there may be a slight flat on the
body of round LED’s. If you can see inside the LED the cathode is the larger electrode (but this
is not an official identification method).
LED’s can be damaged by heat when soldering, but the risk is small unless you are very
slow. No special precautions are needed for soldering most LED’s.
Testing an LED:
LED’s must have a resistor in series to limit the current to a safe value, for quick testing
purposes a 1k resistor is suitable for most LED’s if your supply voltage is 12V or less.
Remember to connect the LED the correct way round!
Colors of LED’s
LED’s are available in red, orange,
amber, yellow, green, blue and white. Blue and
white LED’s are much more expensive than the
other colors.
Light-emitting diode
Electronic symbol
When a light-emitting diode is forward biased (switched on), electrons are able to
recombine with electron holes within the device, releasing energy in the form of photons. This
effect is called electroluminescence and the color of the light (corresponding to the energy of
the photon) is determined by the energy gap of the semiconductor. An LED is often small in
area (less than 1 mm2), and integrated optical components may be used to shape its radiation
pattern. LED’s present many advantages over incandescent light sources including lower energy
consumption, longer lifetime, improved robustness, smaller size, faster switching, and greater
durability and reliability. LED’s powerful enough for room lighting are relatively expensive and
require more precise current and heat management than compact fluorescent lamp sources of
comparable output.
The first commercial LED’s were commonly used as replacements for incandescent and
neon indicator lamps, and in seven-segment displays, first in expensive equipment such as
laboratory and electronics test equipment, then later in such appliances as TVs, radios,
telephones, calculators, and even watches (see list of signal uses). These red LED’s were bright
enough only for use as indicators, as the light output was not enough to illuminate an area.
Readouts in calculators were so small that plastic lenses were built over each digit to make them
legible. Later, other colors grew widely available and also appeared in appliances and
equipment. As LED materials technology grew more advanced, light output rose, while
maintaining efficiency and reliability at acceptable levels. The invention and development of the
high power white light LED to use for illumination (see list of illumination applications). Most
LED’s were made in the very common 5 mm T1¾ and 3 mm T1 packages, but with rising
power output, it has grown increasingly necessary to shed excess heat to maintain reliability, so
more complex packages have been adapted for efficient heat dissipation. Packages for state-of-
the-art high power LED’s bear little resemblance to early LED’s.
Illustration of Haitz's Law. Light output per LED as a function of production year, note
the logarithmic scale on the vertical axis.
Technology:
Like a normal diode, the LED consists of a chip of semi conducting material doped with
impurities to create a p-n junction. As in other diodes, current flows easily from the p-side, or
anode, to the n-side, or cathode, but not in the reverse direction. Charge-carriers—electrons and
holes—flow into the junction from electrodes with different voltages. When an electron meets a
hole, it falls into a lower energy level, and releases energy in the form of a photon.
The wavelength of the light emitted, and thus its color, depends on the band gap energy
of the materials forming the p-n junction. In silicon or germanium diodes, the electrons and
holes recombine by a non-radiative transition which produces no optical emission, because
these are indirect band gap materials. The materials used for the LED have a direct band gap
with energies corresponding to near-infrared, visible or near-ultraviolet light.
LED development began with infrared and red devices made with gallium arsenide.
Advances in materials science have enabled making devices with ever-shorter wavelengths,
emitting light in a variety of colors.
LED’s are usually built on an n-type substrate, with an electrode attached to the p-type
layer deposited on its surface. P-type substrates, while less common, occur as well. Many
commercial LED’s, especially GaN/InGaN, also use sapphire substrate.
Most materials used for LED production have very high refractive indices. This means
that much light will be reflected back into the material at the material/air surface interface.
Thus, light extraction in LED’s is an important aspect of LED production, subject to much
research and development.
Generally a flat-surfaced uncoated LED semiconductor chip will only emit light
perpendicular to the semiconductor's surface, and a few degrees to the side, in a cone shape
referred to as the light cone, cone of light, or the escape cone. The maximum angle of incidence
is referred to as the critical angle. When this angle is exceeded photons no longer penetrate the
semiconductor, but are instead reflected both internally inside the semiconductor crystal, and
externally off the surface of the crystal as if it were a mirror. Internal reflections can escape
through other crystalline faces, if the incidence angle is low enough and the crystal is
sufficiently transparent to not re-absorb the photon emission. But for a simple square LED with
90-degree angled surfaces on all sides, the faces all act as equal angle mirrors. In this case the
light can not escape and is lost as waste heat in the crystal. A convoluted chip surface with
angled facets similar to a jewel or Fresnel lens can increase light output by allowing light to be
emitted perpendicular to the chip surface while far to the sides of the photon emission point.
The ideal shape of a semiconductor with maximum light output would be a micro sphere
with the photon emission occurring at the exact center, with electrodes penetrating to the center
to contact at the emission point. All light rays emanating from the center would be
perpendicular to the entire surface of the sphere, resulting in no internal reflections. A
hemispherical semiconductor would also work, with the flat back-surface serving as a mirror to
back-scattered photons.
Transition coatings:
Many LED semiconductor chips are potted in clear or colored molded plastic shells. The
plastic shell has three purposes:
Typical indicator LED’s are designed to operate with no more than 30–60 milli-watts
[mW] of electrical power. Around 1999, Philips Lumi LED’s introduced power LED’s capable
of continuous use at one watt [W]. These LED’s used much larger semiconductor die sizes to
handle the large power inputs. Also, the semiconductor dies were mounted onto metal slugs to
allow for heat removal from the LED die.
One of the key advantages of LED-based lighting is its high efficiency, as measured by
its light output per unit power input. White LED’s quickly matched and overtook the efficiency
of standard incandescent lighting systems. In 2002, Lumi LED’s made five-watt LED’s
available with a luminous efficacy of 18–22 lumens per watt [lm/W]. For comparison, a
conventional 60–100 W incandescent light bulb emits around 15 lm/W, and standard
fluorescent lights emit up to 100 lm/W. A recurring problem is that efficiency falls sharply with
rising current. This effect is known as droop and effectively limits the light output of a given
LED, rising heating more than light output for higher current.
In September 2003, a new type of blue LED was demonstrated by the company Cree
Inc. to provide 24 mW at 20 milli amperes [mA]. This produced a commercially packaged
white light giving 65 lm/W at 20 mA, becoming the brightest white LED commercially
available at the time, and more than four times as efficient as standard incandescent. In 2006,
they demonstrated a prototype with a record white LED luminous efficacy of 131 lm/W at 20
mA. Also, Seoul Semiconductor plans for 135 lm/W by 2007 and 145 lm/W by 2008, which
would be nearing an order of magnitude improvement over standard incandescent and better
than even standard fluorescents. Nichia Corporation has developed a white LED with luminous
efficacy of 150 lm/W at a forward current of 20 mA.
Practical general lighting needs high-power LED’s, of one watt or more. Typical
operating currents for such devices begin at 350 mA.
Note that these efficiencies are for the LED chip only, held at low temperature in a lab.
Lighting works at higher temperature and with drive circuit losses, so efficiencies are much
lower. United States Department of Energy (DOE) testing of commercial LED lamps designed
to replace incandescent lamps or CFLs showed that average efficacy was still about 46 lm/W in
2009 (tested performance ranged from 17 lm/W to 79 lm/W).
Solid state devices such as LED’s are subject to very limited wear and tear if operated at
low currents and at low temperatures. Many of the LED’s made in the 1970s and 1980s are still
in service today. Typical lifetimes quoted are 25,000 to 100,000 hours but heat and current
settings can extend or shorten this time significantly.
The most common symptom of LED (and diode laser) failure is the gradual lowering of
light output and loss of efficiency. Sudden failures, although rare, can occur as well. Early red
LED’s were notable for their short lifetime. With the development of high-power LED’s the
devices are subjected to higher junction temperatures and higher current densities than
traditional devices. This causes stress on the material and may cause early light output
degradation. To quantitatively classify lifetime in a standardized manner it has been suggested
to use the terms L75 and L50 which is the time it will take a given LED to reach 75% and 50%
light output respectively.
SERIAL COMMUNICATION:
1. Microcontroller
2. PC
3. RS 232 cable
4. MAX 232 IC
5. HyperTerminal
When the pins P3.0 and P3.1 of microcontroller are set, UART, which is inbuilt in the
microcontroller, will be enabled to start the serial communication.
The 8051 has two timers: Timer 0 and Timer 1. They can be used either as timers to
generate a time delay or as counters to count events happening outside the microcontroller.
Both Timer 0 and Timer 1 are 16-bit wide. Since the 8051 has an 8-bit architecture, each
16-bit timer is accessed as two separate registers of low byte and high byte. Lower byte register
of Timer 0 is TL0 and higher byte is TH0. Similarly lower byte register of Timer1 is TL1 and
higher byte register is TH1.
Both timers 0 and 1 use the same register TMOD to set the various operation modes.TMOD is
an 8-bit register in which the lower 4 bits are set aside for Timer 0 and the upper 4 bits for
Timer 1. In each case, the lower 2 bits are used to set the timer mode and the upper 2 bits to
specify the operation.
(MSB) (LSB)
TIMER 1 TIMER 0
GATE:
Every timer has a means of starting and stopping. Some timers do this by software,
some by hardware and some have both software and hardware controls. The timers in the 8051
have both. The start and stop of the timer are controlled by the way of software by the TR (timer
start) bits TR0 and TR1. These instructions start and stop the timers as long as GATE=0 in the
TMOD register. The hardware way of starting and stopping the timer by an external source is
achieved by making GATE=1 in the TMOD register.
C/T:
Timer or counter selected. Cleared for timer operation and set for counter operation.
M1 :
Mode bit 1
M0 :
Mode bit 0
it overflows
This mode 2 is an 8-bit timer and therefore it allows only values of 00H to FFH to be
loaded into the timer’s register TH. After TH is loaded with the 8-bit value, the 8051 give a
copy of it to TL. When the timer starts, it starts to count up by incrementing the TL register. It
counts up until it reaches its limit of FFH. When it rolls over from FFH to 00H, it sets high the
TF (timer flag). If Timer 0 is used, TF0 goes high and if Timer 1 is used, TF1 goes high. When
the TL register rolls from FFH to 0 and TF is set to 1, TL is reloaded automatically with the
original value kept by the TH register.
Computers transfer data in two ways: parallel and serial. In parallel data transfers, often
8 or more lines are used to transfer data to a device that is only a few feet away. Although a lot
of data can be transferred in a short amount of time by using many wires
Fig:
communication
using cables between pc to microcontroller
in parallel, the distance cannot be great. To transfer to a device located many meters
away, the serial method is best suitable. In serial communication, the data is sent one bit at a
time. The 8051 has serial communication capability built into it, thereby making possible fast
data transfer using only a few wires.
The fact that serial communication uses a single data line instead of the 8-bit data
line instead of the 8-bit data line of parallel communication not only makes it cheaper but also
enables two computers located in two different cities to communicate over the telephone.
Serial data communication uses two methods, asynchronous and synchronous. The
synchronous method transfers a block of data at a time, while the asynchronous method
transfers a single byte at a time. With synchronous communications, the two devices initially
synchronize themselves to each other, and then continually send characters to stay in sync. Even
when data is not really being sent, a constant flow of bits allows each device to know where the
other is at any given time. That is, each character that is sent is either actual data or an idle
character. Synchronous communications allows faster data transfer rates than asynchronous
methods, because additional bits to mark the beginning and end of each data byte are not
required. The serial ports on IBM-style PCs are asynchronous devices and therefore only
support asynchronous serial communications.
Asynchronous means "no synchronization", and thus does not require sending and
receiving idle characters. However, the beginning and end of each byte of data must be
identified by start and stop bits. The start bit indicates when the data byte is about to begin and
the stop bit signals when it ends. The requirement to send these additional two bits causes
asynchronous communication to be slightly slower than synchronous however it has the
advantage that the processor does not have to deal with the additional idle characters.
There are special IC chips made by many manufacturers for serial data communications.
These chips are commonly referred to as UART(universal asynchronous receiver-transmitter)
and USART(universal synchronous-asynchronous receiver-transmitter). The 8051 has a built-in
UART.
In the asynchronous method, the data such as ASCII characters are packed between a
start and a stop bit. The start bit is always one bit, but the stop bit can be one or two bits. The
start bit is always a 0 (low) and stop bit (s) is 1 (high). This is called framing.
The rate of data transfer in serial data communication is stated as bps (bits per second).
Another widely used terminology for bps is baud rate. The data transfer rate of a given
computer system depends on communication ports incorporated into that system. And in
asynchronous serial data communication, this baud rate is generally limited to 100,000bps. The
baud rate is fixed to 9600bps in order to interface with the microcontroller using a crystal of
11.0592 MHz.
RS232 CABLE:
To allow compatibility among data communication equipment, an interfacing
standard called RS232 is used. Since the standard was set long before the advent of the TTL
logic family, its input and output voltage levels are not TTL compatible. For this reason, to
connect any RS232 to a microcontroller system, voltage converters such as MAX232 are used
to convert the TTL logic levels to the RS232 voltage levels and vice versa.
MAX232:
The drivers provide RS-232 voltage level outputs (approx. ± 7.5 V) from a
single + 5 V supply via on-chip charge pumps and external capacitors. This makes
it useful for implementing RS-232 in devices that otherwise do not need any
voltages outside the 0 V to + 5 V range, as power supply design does not need to
be made more complicated just for driving the RS-232 in this case.
The receivers reduce RS-232 inputs (which may be as high as ± 25 V), to
standard 5 V TTL levels. These receivers have a typical threshold of 1.3 V, and a
typical hysteresis of 0.5 V.
RS232 Line Type & Logic Level RS232 Voltage TTL Voltage
to/from MAX232
Data Transmission (Rx/Tx) Logic 0 +3 V to +25 V 0V
Data Transmission (Rx/Tx) Logic 1 -3 V to -25 V 5V
Control Signals (RTS/CTS/DTR/DSR) -3 V to -25 V 5V
Logic 0
Control Signals (RTS/CTS/DTR/DSR) +3 V to +25 V 0V
Logic 1
The MAX232 from Maxim was the first IC which in one package contains
the necessary drivers and receivers to adapt the RS-232 signal voltage levels to
TTL logic. It became popular, because it just needs one voltage (+5V or +3.3V)
and generates the necessary RS-232 voltage levels.
General Description
MAX232 Features
Operates From a Single 5-V Power Supply With 1.0-uF Charge-Pump Capacitors
and Computers
RS-232
RS-232 is simple, universal, well understood and supported but it has some
serious shortcomings as a data interface. The standards to 256kbps or less and line
lengths of 15M (50 ft) or less but today we see high speed ports on our home PC
running very high speeds and with high quality cable maxim distance has
increased greatly. The rule of thumb for the length a data cable depends on speed
of the data, quality of the cable.
The RS-232 interface presupposes a common ground between the DTE and
DCE. This is a reasonable assumption when a short cable connects the DTE to the
DCE, but with longer lines and connections between devices that may be on
different electrical busses with different grounds, this may not be true.
The output signal level usually swings between +12V and -12V. The "dead
area" between +3v and -3v is designed to absorb line noise. In the various RS- 232-
like definitions this dead area may vary. For instance, the definition for V.10 has a
dead area from +0.3v to -0.3v. Many receivers designed for RS-232 are sensitive to
differentials of 1v or less.
This can cause problems when using pin powered widgets - line drivers,
converters, modems etc. These type of units need enough voltage & current to
power them self's up. Typical URART (the RS-232 I/O chip) allows up to 50ma
per output pin - so if the device needs 70ma to run we would need to use at least 2
pins for power. Some devices are very efficient and only require one pin (some
times the Transmit or DTR pin) to be high - in the "SPACE" state while idle.
An RS-232 port can supply only limited power to another device. The
number of output lines, the type of interface driver IC, and the state of the output
lines are important considerations.
The types of driver ICs used in serial ports can be divided into three general
categories:
Drivers which require plus (+) and minus (-) voltage power supplies such as
the 1488 series of interface integrated circuits. (Most desktop and tower PCs use
this type of driver.)
Low power drivers which require one +5 volt power supply. This type of
driver has an internal charge pump for voltage conversion. (Many industrial
microprocessor controls use this type of driver.)
Low voltage (3.3 v) and low power drivers which meet the EIA-562
Standard. (Used on notebooks and laptops.)
Pins 4 RTS (Request To Send - from the transmitting computer) and 5 CTS
(Clear To Send - from the Data set) are used to control. In most Asynchronous
situations, RTS and CTS are constantly on throughout the communication session.
However where the DTE is connected to a multipoint line, RTS is used to turn
carrier on the modem on and off. On a multipoint line, it's imperative that only
one station is transmitting at a time (because they share the return phone pair).
When a station wants to transmit, it raises RTS. The modem turns on carrier,
typically waits a few milliseconds for carrier to stabilize, and then raises CTS. The
DTE transmits when it sees CTS up. When the station has finished its
transmission, it drops RTS and the modem drops CTS and carrier together.
Clock signals (pins 15, 17, & 24) are only used for synchronous
communications. The modem or DSU extracts the clock from the data stream and
provides a steady clock signal to the DTE. Note that the transmit and receive
clock signals do not have to be the same, or even at the same baud rate.
Note: Transmit and receive leads (2 or 3) can be reversed depending on the use of
the equipment - DCE Data Communications Equipment or a DTE Data Terminal
Equipment.
Find out by following these steps: The point of reference for all signals is the
terminal (or PC).
1) Measure the DC voltages between (DB25) pins 2 & 7 and between pins 3 & 7.
Be sure the black lead is connected to pin 7 (Signal Ground) and the red lead to
whichever pin you are measuring.
4) If both pins 2 & 3 have a voltage of at least 3 volts, then either you are
measuring incorrectly, or your device is not a standard EIA-232 device. Call
technical support.
5) In general, a DTE provides a voltage on TD, RTS, & DTR, whereas a DCE
provides voltage on RD, CTS, DSR, & CD.
X.21 interface on a DB 15 connector
General
Functional Description
As can be seen from the pinning specifications, the Signal Element Timing (clock) is
provided by the DCE. This means that your provider (local telco office) is responsible for the
correct clocking and that X.21 is a synchronous interface. Hardware handshaking is done by the
Control and Indication lines. The Control is used by the DTE and the Indication is the DCE one.
Cross-cable pinning
9-pin 25-pin
Description Signal Source DTE or DCE
DTE DCE
Carrier Detect CD 1 8 from Modem
Receive Data RD 2 3 from Modem
Transmit Data TD 3 2 from Terminal/Computer
Data Terminal
DTR 4 20 from Terminal/Computer
Ready
Signal Ground SG 5 7 from Modem
Data Set Ready DSR 6 6 from Modem
Request to Send RTS 7 4 from Terminal/Computer
Clear to Send CTS 8 5 from Modem
Ring Indicator RI 9 22 from Modem
Cabling considerations - you should use cabling made for RS-232 data but I
have seen low speed data go over 250' on 2 pair phone cable. Level 5 cable can
also be used but for best distance uses a low capacitance data grade cable.
The standard maxim length is 50' but if data is async you can increase that
distance to as much as 500' with a good grade of cable.
Using a high grade cable (individually shield low capacitance pairs) the distance
can be extended to 4000'At higher frequencies a new problem comes to light. The
high frequency component of the data signal is lost as the cable gets longer
resulting in a rounded, rather than square wave signal. The maxim distance will
depend on the speed and noise level around the cable run. On longer runs a line
drive is needed. This is a simple modem used to increase the maxim distance you
can run RS-232 data.
Selecting data cable isn't difficult, but often gets lost in the shuffle of
larger system issues. Care should be taken. However, because intermittent
problems caused by marginal cable can be very difficult to troubleshoot.
Beyond the obvious traits such as number of conductors and wire gauge, cable
specifications include a handful of less intuitive terms.
Proteus is a software which accepts only hex files. Once the machine code
is converted into hex code, that hex code has to be dumped into the
microcontroller placed in the programmer kit and this is done by the Proteus.
Programmer kit contains a microcontroller on it other than the one which is to be
programmed. This microcontroller has a program in it written in such a way that it
accepts the hex file from the keil compiler and dumps this hex file into the
microcontroller which is to be programmed. As this programmer kit requires
power supply to be operated, this power supply is given from the power supply
circuit designed above. It should be noted that this programmer kit contains a
power supply section in the board itself but in order to switch on that power
supply, a source is required. Thus this is accomplished from the power supply
board with an output of 12volts or from an adapter connected to 230 V AC.
Applications
Leds Funtain shape:
Source code:
mov p2,#00h
rep:mov r0,#08
mov a,#01h
loop:mov p2,a
acall delay
setb c
rlc a
djnz r0,loop
mov r0,#08h
loop1: clr c
rrc a
mov p2,a
acall delay
djnz r0,loop1
ajmp rep
delay: mov r1,#01
loop3: mov r2,#255
loop2: mov r3,#255
djnz r3,$
djnz r2, loop2
djnz r1,loop3
ret
end
Traffic signal:
Source code:
mov p2,#00h
mov p3,#0f0h
main:mov p2,#4ch
mov p3,#0f2h
acall delay
mov p2,#52h
acall delay1
mov p2,#61h
acall delay
mov p2,#91h
acall delay1
mov p2,#09h
mov p3,#0f3h
acall delay
mov p2,#89h
mov p3,#0f4h
acall delay1
mov p2,#49h
mov p3,#0f8h
acall delay
mov p2,#4ah
mov p3,#0f4h
acall delay1
ajmp main
delay:mov r0,#40
loop1: mov r1,#255
loop: mov r2,#255
djnz r2,$
djnz r1,loop
djnz r0,loop1
ret
delay1:mov r0,#20
loop2: mov r1,#200
loop3: mov r2,#200
djnz r2,$
djnz r1,loop3
djnz r0,loop2
ret
end
Date display:
Source code:
mov p1,#00h
mov p2,#00h
back:setb p2.0 // com1 activate
mov p1,#0a4h //to display 2'
acall delay
clr p2.0
setb p2.1 // com2
mov p1,#12h //5.
acall delay
clr p2.1
setb p2.2 //com3
mov p1,#0f9h //1
acall delay
clr p2.2
setb p2.3 //com4
mov p1,#79h //1.
acall delay
clr p2.3
setb p2.4 //com5
mov p1,#0a4h
acall delay
clr p2.4
setb p2.5 //com6
mov p1,#0c0h
acall delay
clr p2.5
setb p2.6 //com7
mov p1,#0f9h //1
acall delay
clr p2.6
setb p2.7 // com8
mov p1,#80h
acall delay
clr p2.7
ajmp back
delay: mov r1,#200
djnz r1,$
ret end
DC Motor
Source code:
back:setb p2.0
acall delay
clr p2.0
acall delay
sjmp back
delay:mov r0,#71
mov tmod,#10h
loop:mov th1,#02h
mov tl1,#81h
setb tr1
jnb tf1,$
clr tf1
djnz r0,loop
clr tr1
ret
end
Source code:
back:clr p2.0
clr p2.1
acall delay
setb p2.0
setb p2.1
acall delay
sjmp back
delay:mov r0,#04
loop1:mov r1,#240
mov tmod,#10h
loop:mov th1,#1fh
mov tl1,#06h
setb tr1
jnb tf1,$
clr tf1
djnz r1,loop
djnz r0,loop1
clr tr1
ret
end
Source Code:
#include<reg51.h>
sbit rs=P1^0;
sbit rw=P1^1;
sbit en=P1^2;
void main()
{
unsigned char name[8]={"SAIMEDHA"};
unsigned char roll[6]={"ECE999"} ;
unsigned char comm[4]={0x38,0x10,0x0c,0x80};
unsigned char v1;
unsigned int v3;
P2=0x00;
for(v1=0;v1<4;v1++)
{
P2=comm[v1];
rs=0;
rw=0;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
}
for(v1=0;v1<8;v1++)
{
P2=name[v1];
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
}
P2=0xc0;
rs=0;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
for(v1=0;v1<6;v1++)
{
P2=roll[v1];
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
}
}
Password protected system
Source code:
#include<reg51.h>
// Keypad connections//
sbit row1=P1^0;
sbit row2=P1^1;
sbit row3=P1^2;
sbit row4=P1^3;
sbit col1=P1^4;
sbit col2=P1^5;
sbit col3=P1^6;
//lcd connections//
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
//motor inputs//
sbit motp=P2^3;
sbit motn=P2^4;
void delay();
void check();
unsigned char comm[4]={0x38,0x0c,0x10,0x80};
unsigned char msg[15]={"ENTER PASSWORD"};
unsigned char password[4]={"9676"};
unsigned char read[4]; //used to store keys given from keypad
unsigned char v1,v2=0x00;
unsigned int v3;
void main()
{
motp=motn=0;
P3=0x00;
for(v1=0;v1<4;v1++)
{
P3=comm[v1];
rs=0;
rw=0;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
} for(v1=0;v1<15;v1+
+)
{
P3=msg[v1];
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
}
P3=0xc0;
rs=0;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
while(1)
{
row1=0;
if(col1==0)
{
read[v2]='1';
P3='*';
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
delay();
v2=v2+1;
}
if(col2==0)
{
read[v2]='2';
P3='*';
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
delay();
v2=v2+1;
}
if(col3==0)
{
read[v2]='3';
P3='*';
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
delay();
v2=v2+1;
}
row1=1;row2=0;
if(col1==0)
{
read[v2]='4';
P3='*';
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
delay();
v2=v2+1;
}
if(col2==0)
{
read[v2]='5';
P3='*';
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
delay();
v2=v2+1;
}
if(col3==0)
{
read[v2]='6';
P3='*';
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
delay();
v2=v2+1;
}
row2=1;row3=0;
if(col1==0)
{
read[v2]='7';
P3='*';
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
delay();
v2=v2+1;
}
if(col2==0)
{
read[v2]='8';
P3='*';
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
delay();
v2=v2+1;
}
if(col3==0)
{
read[v2]='9';
P3='*';
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
delay();
v2=v2+1;
}
row3=1;row4=0;
if(col1==0)
{
read[v2]='*';
P3='*';
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
delay();
v2=v2+1;
}
if(col2==0)
{
read[v2]='0';
P3='*';
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
delay();
v2=v2+1;
}
if(col3==0)
{
check();
delay();
}
row4=1;
}
}
void check()
{
unsigned char msg2[16]={"PASSWORD MATCHED"};
unsigned char msg3[14]={"WRONG PASSWORD"};
unsigned char v4;
if(password[0]==read[0]&&password[1]==read[1]&&password[2]==read[2]
&&password[3]==read[3])
{
motp=1;
motn=0;
P3=0x01;
rs=0;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
for(v4=0;v4<16;v4++)
{
P3=msg2[v4];
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
}
delay();
motp=motn=0;
}
else
{
motp=0;
motn=0;
P3=0x01;
rs=0;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
for(v4=0;v4<14;v4++)
{
P3=msg3[v4];
rs=1;
en=1;
for(v3=0;v3<2000;v3++);
en=0;
}
delay();
}
}
void delay()
{
unsigned int v5;
for(v5=0;v5<60000;v5++);
}