Professional Documents
Culture Documents
MICROCONTROLLER
The microcontroller being used in this system is Atmel 89C51. The 8051
• 4 ports having in total of 32 input/output lines are in most cases sufficient to make all
is that nothing is missing and nothing is too much. In other words, it is created exactly in
accordance to the average user‘s taste and needs. Another advantage is RAM
organization, the operation of Central Processor Unit (CPU) and ports which completely
use all recourses and enable further upgrade. All 8051 microcontrollers have 4 I/O ports
to be connected to peripheral devices are available for use. Pin configuration, i.e.
whether it is to be configured as an input (1) or an output (0), depends on its logic state.
(0) to appropriate I/O port bit. In this case, voltage level on appropriate pin will be
apply a logic one (1) to appropriate port. In this case, voltage level on appropriate pin will
be 5V (as is the case with any TTL input). There are five interrupt sources for the 8051,
which means that they can recognize 5 different events that can interrupt regular program
execution. Each interrupt can be enabled or disabled by setting bits of the IE register.
Likewise, the whole interrupt system can be disabled by clearing the EA bit
ARCHITECTURE
All 8051 microcontrollers have a 16-bit addressing bus and are capable of
addressing 64 kb memory. The 8051 has two types of memory and these are Program
Memory and Data Memory. Program Memory (ROM) is used to permanently save the
program being executed, while Data Memory (RAM) is used for temporarily storing data
and intermediate results created and used during the operation of the microcontroller.
Depending on the model in use, a few Kb of ROM and 128 or 256 bytes of RAM is used.
Figure 2. Architecture of microcontroller 8051
MEMORY ORGANISATION
The 8051 has two types of memory and these are Program Memory and
Data Memory. Program Memory (ROM) is used to permanently save the program being
executed, while Data Memory (RAM) is used for temporarily storing data and
intermediate results created and used during the operation of the microcontroller.
Depending on the model in use (we are still talking about the 8051 microcontroller family
in general) at most a few Kb of ROM and 128 or 256 bytes of RAM is used.
All 8051 microcontrollers have a 16-bit addressing bus and are capable of
PROGRAM MEMORY
The first models of the 8051 microcontroller family did not have internal
program memory. It was added as an external separate chip. These models are
recognizable by their label beginning with 803 (for example 8031 or 8032). All later
models have a few Kbytes ROM embedded. Even though such an amount of memory is
sufficient for writing most of the programs, there are situations when it is necessary to
DATA MEMORY
and intermediate results created and used during the operation of the microcontroller.
Besides, RAM memory built in the 8051 family includes many registers such as hardware
counters and timers, input/output ports, serial data buffers etc. The previous models had
256 RAM locations, while for the later models this number was incremented by
additional 128 registers. However, the first 256 memory locations (addresses 0-FFh) are
the heart of memory common to all the models belonging to the 8051 family. Locations
available to the user occupy memory space with addresses 0-7Fh, i.e. first 128 registers.
MEMORY EXPANSION
sufficient, it is possible to add two external memory chips with capacity of 64Kb each. P2
and P3 I/O ports are used for their addressing and data transmission.
ADDRESSING
Each instruction consists of two parts. One part describes WHAT should be done, while
the other explains HOW to do it. The latter part can be a data (binary number) or the
address at which the data is stored. Two ways of addressing are used for all 8051
DIRECT ADDRESSING
read is specified in instruction. The address may contain a number being changed during
operation (variable).
INDIRECT ADDRESSING
On indirect addressing, a register containing the address of another
register is specified in instruction. Data to be used in the program is stored in the letter
register.
MOV A,@R0; Means: Store the value from the register whose address is in the R0
register into accumulator. On indirect addressing, registers R0, R1 or Stack Pointer are
Special Function Registers (SFRs) are a sort of control table used for
running and monitoring the operation of the microcontroller. Each of these registers as
well as each bit they include, has its name, address in the scope of RAM and precisely
defined purpose such as timer control, interrupt control, serial communication control etc.
Even though there are 128 memory locations intended to be occupied by them, the basic
core, shared by all types of 8051 microcontrollers, has only 21 such registers. Rest of
develop microcontrollers keeping them compatible with the previous versions. It also
enables programs written a long time ago for microcontrollers which are out of
PSW register is one of the most important SFRs. It contains several status bits that reflect
the current state of the CPU. Besides, this register contains Carry bit, Auxiliary Carry,
two register bank select bits, Overflow flag, parity bit and user-definable status flag.
P - Parity bit. If a number stored in the accumulator is even then this bit will be
automatically set (1), otherwise it will be cleared (0). It is mainly used during data
OV Overflow occurs when the result of an arithmetical operation is larger than 255 and
cannot be stored in one register. Overflow condition causes the OV bit to be set (1).
RS0, RS1 - Register bank select bits. These two bits are used to select one of four register
banks of RAM. By setting and clearing these bits, registers R0-R7 are stored in one of
CY - Carry Flag is the (ninth) auxiliary bit used for all arithmetical operations and shift
instructions.
consists of two separate registers: DPH (Data Pointer High) and (Data Pointer Low). For
this reason it may be treated as a 16-bit register or as two independent 8-bit registers.
Their 16 bits are primarily used for external memory addressing. Besides, the DPTR
The microcontroller oscillator uses quartz crystal for its operation. As the
frequency of this oscillator is precisely defined and very stable, pulses it generates are
always of the same width, which makes them ideal for time measurement. Such crystals
are also used in quartz watches. In order to measure time between two events it is
sufficient to count up pulses coming from this oscillator. If the timer is properly
programmed, the value stored in its register will be incremented (or decremented) with
each coming pulse, i.e. once per each machine cycle. A single machine-cycle instruction
lasts for 12 quartz oscillator periods, which means that by embedding quartz with
oscillator frequency of 12MHz, a number stored in the timer register will be changed
their names suggest, their main purpose is to measure time and count external events.
Besides, they can be used for generating clock pulses to be used in serial communication,
BAUD RATE
Baud Rate is a number of sent/received bits per second. In case the UART
is used, baud rate depends on: selected mode, oscillator frequency and in some cases on
RESET
Reset occurs when the RS pin is supplied with a positive pulse in duration of
at least 2 machine cycles (24 clock cycles of crystal oscillator). After that, the
microcontroller generates an internal reset signal which clears all SFRs, except SBUF
registers, Stack Pointer and ports (the state of the first two ports is not defined, while FF
value is written to the ports configuring all their pins as inputs). Depending on
surrounding and purpose of device, the RS pin is usually connected to a power-on reset
push button or circuit or to both of them. Figure below illustrates one of the simplest
By setting the PD bit of the PCON register from within the program, the
microcontroller is set to Power down mode, thus turning off its internal oscillator and
reduces power consumption enormously. The microcontroller can operate using only 2V
power supply in power- down mode, while total power consumption is less than 40uA.
The only way to get the microcontroller back to normal mode is by reset. While the
microcontroller is in Power Down mode, the state of all SFR registers and I/O ports
remains unchanged. By setting it back into the normal mode, the contents of the SFR
register is lost, but the content of internal RAM is saved. Reset signal must be long
POWER SUPPLY
An effective functioning of any device or instrument relies on the
availability of uninterrupted and specific range of supply voltage. Hence, this necessitates
the design of a suitable power supply unit which acts as the basic driving force for the
components used.
it can either be stepped down or up depending on the value of the D.C. needed. In our
circuit the transformer performs he step-down operation where the 230V A.C. appears as
12V A.C. Across the secondary winding. (Practically as 15V A.C.) One alternation of the
input voltage will cause the top of the transformer to be positive and the bottom negative.
BRIDGE RECTIFIER
bridge rectifier. In this rectifier configuration, we have used four diodes, two diodes will
conduct during the negative alternation and two will conduct during positive alternation.
VOLTAGE REGULATOR
constant voltage of 5V. The IC regulator 7805 produces a constant voltage of 5V and IC
Regulator 7812 produces a constant voltage of 12V for a given input ranging from 17.5V
to 7.5V. The DC output produced will be as unidirectional pulsating current with a ripple
frequency of 120Hz.
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
It consists of a coil of wire surrounding a soft iron core, an iron yoke, which provides a
low reluctance path for magnetic flux, a moveable iron armature, and a set, or sets, of
contacts; two in the relay pictured. The armature is hinged to the yoke and mechanically
linked to a moving contact or contacts. It is held in place by a spring so that when the
relay is de-energized there is an air gap in the magnetic circuit. In this condition, one of
the two sets of contacts in the relay pictured is closed, and the other set is open. Other
relays may have more or fewer sets of contacts depending on their function. The relay in
the picture also has a wire connecting the armature to the yoke. This ensures continuity of
the circuit between the moving contacts on the armature, and the circuit track on the
Printed Circuit Board (PCB) via the yoke, which is soldered to the PCB
C - refers to common
- NO
magnetic field attracts the armature, and the consequent movement of the movable
contact or contacts either makes or breaks a connection with a fixed contact. If the set of
contacts was closed when the relay was de-energised, then the movement opens the
contacts and breaks the connection, and vice versa if the contacts were open. When the
current to the coil is switched off, the armature is returned by a force, approximately half
as strong as the magnetic force, to its relaxed position. Usually this force is provided by a
spring, but gravity is also used commonly in industrial motor starters. Most relays are
coil, to dissipate the energy from the collapsing magnetic field at deactivation, which
automotive relays already include that diode inside the relay case. Alternatively a contact
protection network, consisting of a capacitor and resistor in series, may absorb the surge.
If the coil is designed to be energized with AC, a small copper ring can be crimped to the
end of the solenoid. This "shading ring" creates a small out-of-phase current, which
By analogy with the functions of the original electromagnetic device, a solid-state relay is
made with a thyristor or other solid-state switching device. To achieve electrical isolation
an optocoupler can be used which is a light-emitting diode (LED) coupled with a photo
transistor.
TYPES OF RELAY
LATCHING RELAY
A latching relay has two relaxed states (bistable). These are also called
'keep' or 'stay' relays. When the current is switched off, the relay remains in its last state.
This is achieved with a solenoid operating a ratchet and cam mechanism, or by having
two opposing coils with an over-center spring or permanent magnet to hold the armature
and contacts in position while the coil is relaxed, or with a remnant core.
REED RELAY
A reed relay has a set of contacts inside a vacuum or inert gas filled glass
tube, which protects the contacts against atmospheric corrosion. The contacts are closed
by a magnetic field generated when current passes through a coil around the glass tube.
MERCURY-WETTED RELAY
are wetted with mercury. Such relays are used to switch low-voltage signals (one volt or
less) because of their low contact resistance, or for high-speed counting and timing
POLARIZED RELAY
magnet to increase sensitivity. Polarized relays were used in middle 20th Century
telephone exchanges to detect faint pulses and correct telegraphic distortion. The poles
were on screws, so a technician could first adjust them for maximum sensitivity and then
apply a bias spring to set the critical current that would operate the relay
ULN
This is one of the major component to be used in this set up. This is of 18
pin configuration. Ninth pin is supplied with ground and tenth pin is with vcc. Pin 1-8 is
of input pin, which get their input from controller. The pin 11-18 is of output pin, which
is given to the relay configuration of negative pin voltage. These Darlington arrays are
packages. All devices are pinned with outputs opposite inputs to facilitate ease of circuit
board layout.
Figure 6. ULN pin diagram
FEATURES
• Output Voltage to 95 V
• Transient-Protected Outputs
the controller circuit for visualizing some data’s digitally. The data’s include project
D 1
2 40
I
3 39
S
4 38
P
5 37
L
6 36
A Port 0
7 35
Y
8 34
33
9 32
+vcc 31
10 +Vcc
Gnd
11 30
12 8 29
13 0 28
14 5 27
15 1 26
33 PF
16 25
24 Port 2
17
18 23
X-Tel
19 22
33 PF 20 21
GND
All the operations within the microcontroller are performed at high speed
and quite simply, but the microcontroller itself would not be so useful if there are not
features:
• central processing unit - ranging from small and simple 8-bit processors to
circuit
This integration drastically reduces the number of chips and the amount of
wiring and PCB space that would be needed to produce equivalent systems using separate
chips.
blocks consisting of multiple locations (in early flash the entire chip had to be erased at
once). Flash memory costs far less than EEPROM and therefore has become the
needed. Examples of applications include digital audio players, digital cameras and
mobile phones. Flash memory is also used in USB flash drives, which are used for
general storage and transfer of data between computers. It has also gained some
popularity in the gaming market, where it is often used instead of EPROM’s for game
save data.
communicate with each other, or the signals (information) sent through those interfaces.
Inputs are the signals received by the unit, and outputs are the signals sent from it.
1 40 VCC
2 39
3 38
4 37
P1.0 to P1.7
5 36
6 35
7
8 34
8 0 33
Reset 9 5 32
RX 10 31 VCC
1 ALE
TX 11 30
29 PSEN
12
13 28
P3.0 to P3.7 14 27
15 26
16 25
17 24
11M HZ 18 23
19 22
20 21
PIN DESCRIPTION:
VCC:
Supply voltage.
GND:
Ground.
PORT 0:
Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each
pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as
high impedance Inputs. Port 0 can also be configured to be the multiplexed low order
address/data bus during accesses to external program and data memory. In this mode, P0
Port 0 also receives the code bytes during Flash programming and outputs
the code bytes during program verification. External pull ups are required during program
verification.
PORT 1:
Port 1 is an 8-bit bidirectional 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 (IIL) because of the internal pull
ups.
external count input (P1.0/T2) and the timer/counter 2 trigger input (P1.1/T2EX),
respectively, as shown in the following table. Port 1 also receives the low-order address
PORT 2:
Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 2
output buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins, they
are pulled high by the internal pull ups and can be used as inputs.
As inputs, Port 2 pins that are externally being pulled low will source
current (IIL) because of the internal pull ups. Port 2 emits the high-order address byte
during fetches from external program memory and during accesses to external data
memory that uses 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses
strong internal pull-ups when emitting 1s. During accesses to external data memory that
Port 2 emits the contents of the P2 Special Function Register. 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 bidirectional I/O port with internal pull ups. The Port 3
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 (IIL) because of the pull-ups. Port 3 also serves the functions of
RST:
Reset input. A high on this pin for two machine cycles while the oscillator is
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
frequency and may be used for external timing or clocking purposes. Note, however, that
one ALE pulse is skipped during each access to external data memory.
PSEN:
When the AT89C52 is executing code from external program memory, PSEN is activated
twice each machine cycle, except that two PSEN activations are skipped during each
EA/VPP:
the device to fetch code from external program memory locations starting at 0000H up to
reset. EA should be strapped to VCC for internal program executions. This pin also
receives the 12-volt programming enable voltage (VPP) during Flash programming when
XTAL1:
Input to the inverting oscillator amplifier and input to the internal clock
operating circuit.
Figure 11. Oscillator connection with controller
XTAL2:
TIMER 2:
event counter. The type of operation is selected by bit C/T2 in the SFR T2CON.
Timer 2 has three operating modes cycle. Since a machine cycle consists
transition at its corresponding external input pin, T2. In this function, the external input is
sampled during S5P2 of every machine cycle. When the samples show a high in one
cycle and a low in the next cycle, the count is incremented. The new count value appears
in the register during S3P1 of the cycle following the one in which the transition was
detected. Since two machine cycles (24 oscillator periods) are required to recognize a 1-
to-0 transition, the maximum count rate is 1/24 of the oscillator frequency.
To ensure that a given level is sampled at least once before it changes, the
INTERRUPTS:
Two external interrupts (INT0 and INT1), three timer interrupts (Timers 0,
SOURCE CODING
This chapter deals with the software coding that is requires to be done to
make the system work as per the requirements. The microcontroller 89C51 is
programmer. The code is stored in the microcontroller memory and is executed whenever
the system is switched on. The coding is done in embedded assembly language.