You are on page 1of 27

HARDWARE IMPLEMENTATION

MICROCONTROLLER

The microcontroller being used in this system is Atmel 89C51. The 8051

microcontroller has nothing impressive in appearance:

• 4 Kb of ROM is not much at all.

• 128Kb of RAM (including SFRs) satisfies the user's basic needs.

• 4 ports having in total of 32 input/output lines are in most cases sufficient to make all

necessary connections to peripheral environment.

The whole configuration is obviously thought of as to satisfy the needs of

most programmers working on development of automation devices. One of its advantages

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

each comprising 8 bits which can be configured as inputs or outputs.

Accordingly, in total of 32 input/output pins enabling the microcontroller

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.

In order to configure a microcontroller pin as an input, it is necessary to apply logic zero

(0) to appropriate I/O port bit. In this case, voltage level on appropriate pin will be

0.Similarly, in order to configure a microcontroller pin as an input, it is necessary to

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

of the same register.

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

addressing 64 kb memory. It is neither a mistake nor a big ambition of engineers who

were working on basic core development. It is a matter of smart memory organization

which makes these microcontrollers a real “programmers’ goody“.

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

use additional memory as well.

DATA MEMORY

As already mentioned, Data Memory is used for temporarily storing data

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

In case memory (RAM or ROM) built in the microcontroller is not

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

While operating, the processor processes data as per program instructions.

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

microcontrollers depending on which part of memory should be accessed

DIRECT ADDRESSING

On direct addressing, the address of memory location containing data to be

read is specified in instruction. The address may contain a number being changed during

operation (variable).

MOV A,33h; Means: move a number from address 33 hex to accumulator.

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

used for specifying 8-bit addresses.

SPECIAL FUNCTION REGISTERS

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

locations is intentionally left unoccupied in order to enable the manufacturers to further

develop microcontrollers keeping them compatible with the previous versions. It also

enables programs written a long time ago for microcontrollers which are out of

production now to be used today.

PROGRAM STATUS WORD REGISTER

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

transmit and receive via serial communication.

Bit 1. This bit is intended to be used in the future versions of microcontrollers.

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).

Otherwise, it will be cleared (0).

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

four banks of RAM.

RS1 RS2 Space in RAM


0 0 Bank0 00h-07h
0 1 Bank1 08h-0Fh
1 0 Bank2 10h-17h
1 1 Bank3 18h-1Fh

Table 2. List of bank registers

F0 - Flag 0. This is a general-purpose bit available for use.

AC - Auxiliary Carry Flag is used for BCD operations only.

CY - Carry Flag is the (ninth) auxiliary bit used for all arithmetical operations and shift
instructions.

DATA POINT REGISTER


DPTR register is not a true one because it doesn't physically exist. It

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

Register is usually used for storing data and intermediate results.

COUNTERS AND TIMERS

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

million times per second, i.e. each microsecond.

The 8051 microcontroller has 2 timers/counters called T0 and T1. As

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,

so called Baud Rate.

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

the state of the SMOD bit of the SCON register.

Baud Rate BitSMOD


Mode 0 Fosc. / 12
1 Fosc.
Mode 1 16 12 (256- BitSMOD
TH1)
Fosc. / 32 1
Mode 2
Fosc. / 64 0
1 Fosc.
Mode 3 16 12 (256-
TH1)

Table 3. Baud rate calculation

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

circuits providing safe power-on reset.


Figure 3. Reset connection in microcontroller 8051

POWER DOWN MODE

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

enough, approximately 10mS, to enable stable operation of the quartz oscillator.

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.

Figure 4. Power supply connection

STEP DOWN TRANSFORMER

When A.C. is applied to the primary winding of the power transformer

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.

The next alternation will cause the polarity reverse.

BRIDGE RECTIFIER

A commonly used circuit for supplying large amounts of dc power is the

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

Due to the fluctuation in the supply we need a regulator to provide a

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

to open or close one or many sets of contacts.

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

NO- refers to normally


open
C RELAY NC-refers to normally
closed
- negative voltage
+ NC
+ positive supply

Figure 5. Relay pin diagram

When an electric current is passed through the coil, the resulting

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

manufactured to operate quickly. In a low voltage application, this is to reduce noise. In a

high voltage or high current application, this is to reduce arcing.


If the coil is energized with DC, a diode is frequently installed across the

coil, to dissipate the energy from the collapsing magnetic field at deactivation, which

would otherwise generate a voltage spike dangerous to circuit components. Some

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

increases the minimum pull on the armature during the AC cycle.

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

A mercury-wetted reed relay is a form of reed relay in which the contacts

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

applications where the mercury eliminates contact bounce

POLARIZED RELAY

A Polarized Relay placed the armature between the poles of a permanent

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

furnished in 18-pin dual in-line plastic packages or 18-lead small-outline plastic

packages. All devices are pinned with outputs opposite inputs to facilitate ease of circuit

board layout.
Figure 6. ULN pin diagram

FEATURES

• Output Current to 500 MA

• Output Voltage to 95 V

• Transient-Protected Outputs

LCD WITH CONTROLLER

Since lcd is of 16 pin configuration, they were ultimately connected wit

the controller circuit for visualizing some data’s digitally. The data’s include project

name, temperature in Celsius.


LCD

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

Figure 7. Connection of LCD display with controller


MICROCONTROLLER SPECIFICATION

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

special circuits which make it complete.

A microcontroller is a single integrated circuit with the following key

features:

• central processing unit - ranging from small and simple 8-bit processors to

sophisticated 32- or 64-bit processors

• input/output interfaces such as serial ports

• peripherals such as timers and watchdog circuits

• RAM for data storage

• ROM, EEPROM or Flash memory for program storage

• clock generator - often an oscillator for a quartz timing crystal, resonator or RC

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.

Flash memory is a form of non-volatile computer memory that can be

electrically erased and reprogrammed. Unlike EEPROM, it is erased and programmed in

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

dominant technology wherever a significant amount of non-volatile, solid-state storage is

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.

In computing, Input/output, or I/O, is the collection of interfaces that

different functional units (sub-systems) of an information processing system use to

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

FIGURE 10. MICROCONTROLLER PIN DIAGRAM

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

has internal pull ups.

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.

In addition, 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, as shown in the following table. Port 1 also receives the low-order address

bytes during Flash programming and verification.

Port Pin Alternate Functions

P1.0 T2 (external count input to Timer/Counter 2),time out


T2EX (Timer/Counter 2 capture/reload trigger and direction
P1.1
control)
P1.5 MOSI(Used for In-System Programming)

P1.6 MISO(Used for In-System Programming)

P1.7 SCK(Used for In-System Programming)

TABEL 4. LIST OF PORT 1

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

use 8-bit addresses (MOVX @ RI),

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

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 (IIL) because of the pull-ups. Port 3 also serves the functions of

various special features of the AT89C51, as shown in the following table.

Port Pin Alternate Functions

P3.0 RXD (serial input port)

P3.1 TXD (serial output port)

P3.2 INT0 (external interrupt 0)

P3.3 INT1 (external interrupt 1)

P3.4 T0 (timer 0 external input)

P3.5 T1 (timer 1 external input)

P3.6 WR (external data memory write strobe)

P3.7 RD (external data memory read strobe)

Table 5. List of port 3

RST:

Reset input. A high on this pin for two machine cycles while the oscillator is

running resets the device.

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. Note, however, that

one ALE pulse is skipped during each access to external data memory.

PSEN:

Program Store Enable is the read strobe to external program memory.

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

access to external data memory.

EA/VPP:

External Access Enable. EA must be strapped to GND in order to enable

the device to fetch code from external program memory locations starting at 0000H up to

FFFFH.Note, however, that if lock bit 1 is programmed, EA will be internally latched on

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

12-volt programming is selected.

XTAL1:

Input to the inverting oscillator amplifier and input to the internal clock

operating circuit.
Figure 11. Oscillator connection with controller

XTAL2:

Output from the inverting oscillator amplifier.

TIMER 2:

Timer 2 is a 16-bit Timer/Counter that can operate as either a timer or an

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

of 12 oscillator periods, the count rate is 1/12 of the oscillator frequency

In the Counter function, the register is incremented in response to a 1-to-0

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

level should be held for at least one full machine cycle.

INTERRUPTS:

The AT89C52 has a total of six interrupt vectors:

Two external interrupts (INT0 and INT1), three timer interrupts (Timers 0,

1, and 2), and the serial port interrupt.

Each of these interrupt sources can be individually enabled or disabled by

setting or clearing a bit in Special Function Register IE.

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

programmed by transferring the program created in a system to it with the help of

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.

You might also like