Académique Documents
Professionnel Documents
Culture Documents
1. INTRODUCTION
Some of the main devices used in embedded products are Microprocessors and
Microcontrollers. Microprocessors are commonly referred to as general purpose
processors as they simply accept the inputs, process it and give the output.
In contrast, a microcontroller not only accepts the data as inputs but also
manipulates it, interfaces the data with various devices, controls the data and thus
finally gives the result.
As everyone in this competitive world prefer to make the things easy and
simple to handle, this project sets an example to some extent.
In order to develop any project, the main requirements are hardware, software,
memory devices, protocols, interface media and display devices. The brief description
of these is explained in detail in later topics. This project provides three modes for the
user in which the control of the electrical appliances can be accessed.
1. Manual Mode
2. Auto load Mode
3. Auto fan Mode
The above three modes are discussed later in detail.
ECE Department 10
RVR Institute of Engineering &Technology
LDR
LM35 ADC
\\\
ECE Department 11
RVR Institute of Engineering &Technology
3.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.
ECE Department 12
RVR Institute of Engineering &Technology
In addition, the AT89C51 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.
ECE Department 13
RVR Institute of Engineering &Technology
VCC: - Pin 40 provides supply voltage to the chip. The voltage source is +5V.
The 8051 has an on-chip oscillator but requires an external clock to run it.
Usually, a quartz crystal oscillator is connected to inputs XTAL1 (pin19) and XTAL2
(pin18). There are various speeds of 8051 family. Speed refers to the maximum
ECE Department 14
RVR Institute of Engineering &Technology
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):-
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.
ALE (Address Latch Enable):- This is an output pin and is active high.
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):-
ECE Department 15
RVR Institute of Engineering &Technology
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.
ECE Department 16
RVR Institute of Engineering &Technology
P3.4 T0 (timer 0) 14
P3.5 T1 (timer 1) 15
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.
ECE Department 17
RVR Institute of Engineering &Technology
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.
3.5 Timers:-
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
ECE Department 18
RVR Institute of Engineering &Technology
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
startingand 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
prescaler
ECE Department 19
RVR Institute of Engineering &Technology
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.
SCON (Serial Control) Register:- The SCON register is an 8-bit register used
to program the start bit, stop bit and data bits of data framing.
ECE Department 20
RVR Institute of Engineering &Technology
Reception
ECE Department 21
RVR Institute of Engineering &Technology
0 0 Serial Mode 0
1 0 Serial Mode 2
1 1 Serial Mode 3
Of the four serial modes, only mode 1 is widely used. In the SCON register,
when serial mode 1 is chosen, the data framing is 8 bits, 1 stop bit and 1 start bit,
which makes it compatible with the COM port of IBM/ compatible PC’s. And the
most important is serial mode 1 allows the baud rate to be variable and is set by Timer
1 of the 8051. In serial mode 1, for each character a total of 10 bits are transferred,
where the first bit is the start bit, followed by 8 bits of data and finally 1 stop bit.
ECE Department 22
RVR Institute of Engineering &Technology
4. 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.
asynchronous methods, because additional bits to mark the beginning and end of each
data byte are not required. The 8051 has a built-in UART.
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
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
standard called RS232 is used. Since the standard was set long before the advent of
ECE Department 23
RVR Institute of Engineering &Technology
the TTL logic family, its input and output voltage levels are not TTL compatible. For
such as MAX232 are used to convert the TTL logic levels to the RS232 voltage levels
by RS232 standards. This IC provides best noise rejection and very reliable against
drivers.
To ensure data transfer between PC and microcontroller, the baud rate and
voltage levels of Microcontroller and PC should be the same. The voltage levels of
microcontroller are logic1 and logic 0 i.e., logic 1 is +5V and logic 0 is 0V. But for
PC, RS232 voltage levels are considered and they are: logic 1 is taken as -3V to -25V
ECE Department 24
RVR Institute of Engineering &Technology
and logic 0 as +3V to +25V. So, in order to equal these voltage levels,
ECE Department 25
RVR Institute of Engineering &Technology
Analog-to-digital converters are among the most widely used devices for data
acquisition. Digital systems use binary values, but in the physical world everything is
continuous i.e., analog values. Temperature, pressure (wind or liquid), humidity and
velocity are the physical analog quantities.
These physical quantities are to be converted into digital values for further
processing. One such device to convert these physical quantities into electrical signals
is sensor. Sensors for temperature, pressure, humidity, light and many other natural
quantities produce an output that is voltage or current.
5.1 ADC0804:-
The ADC chip that is used in this project is ADC0804. The ADC0804 IC is an
8-bit parallel ADC in the family of the ADC0800 series from National
Semiconductor. It works with +5 volts and has a resolution of 8 bits. In the ADC0804,
the conversion time varies depending on the clocking signals applied to the CLK IN
pin, but it cannot be faster than 110µs.
ECE Department 26
RVR Institute of Engineering &Technology
CS (Chip Select):-
Chip select is an active low input used to activate the ADC0804 chip. To
access the ADC0804, this pin must be low.
RD (Read):-
This is an input signal and is active low. ADC converts the analog input to its
binary equivalent and holds it in an internal register. RD is used to get the data out of
ADC0804 chip. When CS=0, if a high-to-low pulse is applied to the RD pin, the 8-bit
digital output shows up at the D0-D7 data pins.
WR (Write):- This is an active low input used to inform the ADC0804 to start the
conversion process.
ECE Department 27
RVR Institute of Engineering &Technology
INTR:-
This is an output pin and is active low. It is a normally high pin and when the
conversion is finished, it goes low to signal the CPU that the converted data is ready
to be picked up. After INTR goes low, the CS pin is made low i.e., CS=0 and send a
high-to-low pulse to the RD pin to get the data out of the ADC0804 chip.
These are the differential analog inputs where Vin=Vin(+) – Vin(-). The
Vin(-) pin is connected to ground and the Vin(+) pin is used as the analog input to be
converted to digital.
VCC:-
This is the +5 volt power supply. It is also used as a reference voltage when
the Vref/2 input (pin 9) is open.
ECE Department 28
RVR Institute of Engineering &Technology
VREF/2:-
Pin 9 is an input voltage used for the reference voltage. If this pin is open, the
analog input voltage for the ADC0804 is in the range of 0 to 5 volts.Vref/2 is used to
implement analog input voltages other than 0.5V. i.e., if the analog input range needs
to be 0 to 4 volts, Vref/2 is connected to 2 volts.
D0-D7:-
D0-D7 (D7 is the MSB) are the digital data output pins since ADC0804 is a
parallel ADC chip. To calculate the output voltage, the below equation is used:
Dout = Vin/ (step size)
where Dout = digital data output pins (in decimal) and Vin = analog input value
Step size is the smallest change and is given by (2 x Vref/2)/256 for ADC0804.
The speed at which an analog input is converted to the digital output depends
on the speed of the CLK input. According to the ADC0804 datasheets, the typical
operating frequency is approximately 640 kHz at 5 volts.
ECE Department 29
RVR Institute of Engineering &Technology
20
8 P2.5
P2.6
9 P2.7
P1.7
C P1.6
P1.5
5 P1.4
P1.3
1 P1.2
P1.1
ECE Department 30
RVR Institute of Engineering &Technology
In this project, in order to obtain the fan speed based on temperature, initially
this temperature value has to be read and fed to the microcontroller. This temperature
value has to be sensed. Thus a sensor has to be used and the sensor used in this project
is LM35. It converts temperature value into electrical signals.
The LM35’s low output impedance, linear output, and precise inherent
calibration make interfacing to readout or control circuitry especially easy. It can be
used with single power supplies, or with plus and minus supplies. As it draws only 60
μA from its supply, it has very low self-heating, less than 0.1°C in still air.
6.2 Features:-
ECE Department 31
RVR Institute of Engineering &Technology
ADC accepts the output from LM35 and converts that data into digital form
which is sent to microcontroller for further processing.
ECE Department 32
RVR Institute of Engineering &Technology
7. RELAYS
The relay allows the isolation of two separate sections of a system with two
different voltage sources i.e., a small amount of voltage/current on one side can
handle a large amount of voltage/current on the other side but there is no chance that
these two voltages mix up.
7.1 Operation:-
When current flows through the coil, a magnetic field is created around the
coil i.e., the coil is energized. This causes the armature to be attracted to the coil. The
armature’s contact acts like a switch and closes or opens the circuit. When the coil is
not energized, aspring pulls the armature to its normal state of open or closed. There
are all types of relays for all kinds of applications.
ECE Department 33
RVR Institute of Engineering &Technology
Transistors and ICs must be protected from the brief high voltage 'spike'
produced when the relay coil is switched off. The above diagram shows how a signal
diode (eg 1N4148) is connected across the relay coil to provide this protection. The
diode is connected 'backwards' so that it will normally not conduct. Conduction
occurs only when the relay coil is switched off, at this moment the current tries to
flow continuously through the coil and it is safely diverted through the diode. Without
the diode no current could flow and the coil would produce a damaging high voltage
'spike' in its attempt to keep the current flowing.
ECE Department 34
RVR Institute of Engineering &Technology
1. The contacts can be normally open (NO) or normally closed (NC). In the NC type,
the contacts are closed when the coil is not energized. In the NO type, the contacts are
closed when the coil is energized.
2. There can be one or more contacts. i.e., different types like SPST (single pole
single throw), SPDT (single pole double throw) and DPDT (double pole double
throw) relays.
3. The voltage and current required to energize the coil. The voltage can vary from a
few volts to 50 volts, while the current can be from a few milliamps to 20milliamps.
The relay has a minimum voltage, below which the coil will not be energized. This
minimum voltage is called the “pull-in” voltage.
4. The minimum DC/AC voltage and current that can be handled by the contacts. This
is in the range of a few volts to hundreds of volts, while the current can be from a few
amps to 40A or more, depending on the relay.
An SPDT relay consists of five pins, two for the magnetic coil, one as the
common terminal and the last pins as normally connected pin and normally closed
pin.
When the current flows through this coil, the coil gets energized. Initially
when the coil is not energized, there will be a connection between the common
terminal and normally closed pin. But when the coil is energized, this connection
breaks and a new connection between the common terminal and normally open pin
will be established. Thus when there is an input from the microcontroller to the relay,
the relay will be switched on.
Thus when the relay is on, it can drive the loads connected between the
common terminal and normally open pin. Therefore, the relay takes 5V from the
ECE Department 35
RVR Institute of Engineering &Technology
microcontroller and drives the loads which consume high currents. Thus the relay acts
as an isolation device.
Digital systems and microcontroller pins lack sufficient current to drive the
relay. While the relay’s coil needs around 10milli amps to be energized, the
microcontroller’s pin can provide a maximum of 1-2milli amps current. For this
reason, a driver such as ULN2003 or a power transistor is placed in between the
microcontroller and the relay. In order to operate more than one relay, ULN2003 can
be connected between relay and microcontroller.
The ULN2003 driver is a high voltage, high current Darlington arrays each
containing seven open collector Darlington pairs with common emitters. Each channel
is rated at 500mA and can withstand peak currents of 600mA. Suppression diodes are
included for inductive load driving and the inputs are pinned opposite the outputs to
simplify board layout.
These versatile devices are useful for driving a wide range of loads including
solenoids, relays DC motors, LED displays filament lamps, thermal print heads and
high power buffers. This chip is supplied in 16 pin plastic DIP packages with a copper
lead frame to reduce thermal resistance.
ECE Department 36
RVR Institute of Engineering &Technology
ECE Department 37
RVR Institute of Engineering &Technology
This ULN2003 driver can drive seven relays at a time. The pins 8 and 9
provide ground and Vcc respectively. The working of ULN driver is as follows:
It can accept seven inputs at a time and produces seven corresponding outputs.
If the input to any one of the seven input pins is high, then the value at its
corresponding output pin will be low, for example if the input at pin 6 is high, then
the value at the corresponding output i.e., output at pin 11 will be low. Similarly if the
input at a particular pin is low, then the corresponding output will be high.
One of the coil terminals of the relay will be connected to the output pin of the
ULN driver. Thus in order to switch on the relay to operate any load, the output from
the ULN driver (any one of the 7 outputs) should be low. Thus for the output to be
low, the input applied at that corresponding input pin should be high. The input to the
ULN driver is provided by the microcontroller. Thus the instruction required to
operate the relay through the microcontroller is
SETB PX.Y
Where X is the port number (P0, P1, P2 and P3)
And Y is the pin number of Port X.
ECE Department 38
RVR Institute of Engineering &Technology
ECE Department 39
RVR Institute of Engineering &Technology
LEDs are the most widely used input/output devices of the 8051.
Microcontroller port pins cannot drive these LEDs as these require high currents to
switch on. This current limiting resistor is connected to protect the port pins from
sudden flow of high currents from the power supply.
Thus in order to glow the LED, first there should be a current flow through the
LED. In order to have a current flow, a voltage difference should exist between the
LED terminals. To ensure the voltage difference between the terminals and as the
positive terminal of LED is connected to power supply Vcc, the negative terminal has
to be connected to ground. Thus this ground value is provided by the microcontroller
port pin. This can be achieved by writing an instruction “CLR P2.0”. With this, the
port pin P2.0 is initialized to zero and thus now a voltage difference is established
between the LED terminals and accordingly, current flows and therefore the LED
glows. LED and switches can be connected to any one of the four port pins.
ECE Department 40
RVR Institute of Engineering &Technology
ECE Department 41
RVR Institute of Engineering &Technology
ECE Department 42
RVR Institute of Engineering &Technology
In this project, the user will be provided with three modes the user has the
choice to select the required mode.
Thus after entering the key ‘0’ in the hyper terminal window, user will get the
message “manual mode selected” in the hyper terminal window. After this message, a
list of options will be provided in the next line of the hyper terminal window.
ECE Department 43
RVR Institute of Engineering &Technology
User will get the message “operating fan…” in the hyper terminal window. the
present speed of the fan will be displayed in the next line. For example, if the speed of
the fan is 1, the message “fan speed at level 1” will be displayed in the hyper terminal
window. an other two options will be displayed in the next line and the options are:
So, if the user wishes to increment the fan speed, he has to enter the key ‘I’
and enter key and he has to enter the key ‘D’ if he wishes to decrement the fan speed.
The user can increment the speed up to level4 and can decrement the speed to zero
level i.e., off condition.
ECE Department 44
RVR Institute of Engineering &Technology
The message “load 1 is operating ….” will be displayed in the hyper terminal
window. The present status of the load1 will be displayed in the next line of the hyper
terminal window. That is, if the load is on, the message “load1 is on” will be
displayed in the hyper terminal window and if the load is off, the message “load1 is
off” will be displayed.
If the user wishes to change the status of the load, he has to press the same key
once again. the user has to press the key ’Q’ if he wishes to come out of the manual
mode at any moment or he can proceed with the next key if he wishes to stay in the
same mode.
The message “load 2 is operating ….” will be displayed in the hyper terminal
window. The present status of the load2 will be displayed in the next line of the hyper
terminal window. That is, if the load is on, the message “load2 is on” will be
displayed in the hyper terminal window. If the user wishes to change the status of the
load, he has to press the same key once again.
The message “load 3 is operating ….” will be displayed in the hyper terminal
window. The present status of the load3 will be displayed in the next line of the hyper
terminal window. That is, if the load is on, the message “load3 is on” will be
displayed in the hyper terminal window. If the user wishes to change the status of the
load, he has to press the same key once again. And so on until the key 8 the operation
will be the same.
If the user tries to give any key other than these, the message “Invalid
operation” will be displayed in the hyper terminal window.
ECE Department 45
RVR Institute of Engineering &Technology
The user has to press the key ’Q’ if he wishes to terminate from the manual
mode at any moment. Whenever the user presses the key ‘Q’, the main menu will be
displayed in the hyper terminal window.
He has to enter AL from the PC keyboard. Then the message “Auto light
mode selected” will be displayed in the hyper terminal window. In this, the control of
the electrical appliances is controlled by light dependent resistor (LDR).
He has to enter AF from the keyboard then the message “Auto fan mode
selected” will be displayed in the hyper terminal window. The message “temperature
is:” will be displayed in the next line. The fan speed is controlled by monitoring the
temperature continuously. The temperature value is read from the temperature sensor
and this analog value is converted into digital value by analog to digital converter
(ADC) and fed to microcontroller. The room temperature value is displayed in the
hyper terminal window. The user has no choice to select the fan speed in this mode.
ECE Department 46
RVR Institute of Engineering &Technology
Keil compiler is a software used where the machine language code is written
and compiled. After compilation, the machine source code is converted into hex code
which is to be dumped into the microcontroller for further processing. Keil compiler
also supports C language code.
11.2 Proload:-
Proload 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 and
this is done by the proload. Proload is a programmer which itself contains a
microcontroller in 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.
ECE Department 47
RVR Institute of Engineering &Technology
ECE Department 48
RVR Institute of Engineering &Technology
ECE Department 49
RVR Institute of Engineering &Technology
12. CONCLUSION
In terms of complexity embedded systems can range from very simple with a
single microcontroller chip, to very complex with multiple units, peripherals and
networks mounted inside a large chassis or enclosure, but the project falls under the
former category making it very simple to analyze.
This project provides three modes for the user in which the control of the
electrical appliances can be accessed. As this project is suitable for hotels and
showrooms the number of loads can be increased and can be used to control the
electrical appliances of large scale showrooms and hotels without any problem. But as
the number of loads increases the complexity also increases which may create a
problem in the system.
Therefore, the project is very much useful in hotels and large scale industries
were at a time many electrical appliances are to be controlled.
ECE Department 50
RVR Institute of Engineering &Technology
13. BIBLIOGRAPHY
www.atmel.com
www.datasheetcatalog.com
www.discovercircuits.com
www.kpsec.freeuk.com
www.datasheets.com
www.beyondlogic.com
www.natoinal.com
ECE Department 51